mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-11 07:19:16 +00:00
monitor for bad option
This commit is contained in:
@@ -67,7 +67,21 @@ Options:
|
|||||||
""".format(BANNER, PROFILE)
|
""".format(BANNER, PROFILE)
|
||||||
|
|
||||||
|
|
||||||
class Options:
|
class AttrMonitor:
|
||||||
|
_set_attr_err = False
|
||||||
|
|
||||||
|
def __setattr__(self, key, value):
|
||||||
|
"""monitor attribute setting"""
|
||||||
|
if not hasattr(self, key) and self._set_attr_err:
|
||||||
|
self._attr_change(key)
|
||||||
|
super(AttrMonitor, self).__setattr__(key, value)
|
||||||
|
|
||||||
|
def _attr_set(self, attr):
|
||||||
|
"""do something when unexistent attr is set"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Options(AttrMonitor):
|
||||||
|
|
||||||
def __init__(self, args=None):
|
def __init__(self, args=None):
|
||||||
"""constructor
|
"""constructor
|
||||||
@@ -89,6 +103,8 @@ class Options:
|
|||||||
and not self.args['--no-banner']:
|
and not self.args['--no-banner']:
|
||||||
self._header()
|
self._header()
|
||||||
self._print_attr()
|
self._print_attr()
|
||||||
|
# start monitoring for bad attribute
|
||||||
|
self._set_attr_err = True
|
||||||
|
|
||||||
def _header(self):
|
def _header(self):
|
||||||
"""print the header"""
|
"""print the header"""
|
||||||
@@ -172,3 +188,7 @@ class Options:
|
|||||||
if callable(val):
|
if callable(val):
|
||||||
continue
|
continue
|
||||||
self.log.dbg('- {}: \"{}\"'.format(att, val))
|
self.log.dbg('- {}: \"{}\"'.format(att, val))
|
||||||
|
|
||||||
|
def _attr_set(self, attr):
|
||||||
|
"""error when some inexistent attr is set"""
|
||||||
|
raise Exception('bad option: {}'.format(attr))
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ def load_options(confpath, profile):
|
|||||||
o.link = LinkTypes.NOLINK.value
|
o.link = LinkTypes.NOLINK.value
|
||||||
o.install_showdiff = True
|
o.install_showdiff = True
|
||||||
o.debug = True
|
o.debug = True
|
||||||
o.dopts = ''
|
o.compare_dopts = ''
|
||||||
o.variables = {}
|
o.variables = {}
|
||||||
return o
|
return o
|
||||||
|
|
||||||
|
|||||||
@@ -162,9 +162,9 @@ class TestCompare(unittest.TestCase):
|
|||||||
# test compare from dotdrop
|
# test compare from dotdrop
|
||||||
self.assertFalse(cmd_compare(o, tmp))
|
self.assertFalse(cmd_compare(o, tmp))
|
||||||
# test focus
|
# test focus
|
||||||
o.focus = d4
|
o.compare_focus = d4
|
||||||
self.assertFalse(cmd_compare(o, tmp))
|
self.assertFalse(cmd_compare(o, tmp))
|
||||||
o.focus = '/tmp/fake'
|
o.compare_focus = '/tmp/fake'
|
||||||
self.assertFalse(cmd_compare(o, tmp))
|
self.assertFalse(cmd_compare(o, tmp))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,10 @@ class TestUpdate(unittest.TestCase):
|
|||||||
self.assertTrue(os.path.exists(d2))
|
self.assertTrue(os.path.exists(d2))
|
||||||
self.addCleanup(clean, d2)
|
self.addCleanup(clean, d2)
|
||||||
|
|
||||||
|
d3t, c3t = create_random_file(fold_config)
|
||||||
|
self.assertTrue(os.path.exists(d3t))
|
||||||
|
self.addCleanup(clean, d3t)
|
||||||
|
|
||||||
# create the directory to test
|
# create the directory to test
|
||||||
dpath = os.path.join(fold_config, get_string(5))
|
dpath = os.path.join(fold_config, get_string(5))
|
||||||
dir1 = create_dir(dpath)
|
dir1 = create_dir(dpath)
|
||||||
@@ -69,11 +73,14 @@ class TestUpdate(unittest.TestCase):
|
|||||||
self.assertTrue(os.path.exists(confpath))
|
self.assertTrue(os.path.exists(confpath))
|
||||||
o = load_options(confpath, profile)
|
o = load_options(confpath, profile)
|
||||||
o.debug = True
|
o.debug = True
|
||||||
dfiles = [d1, dir1, d2]
|
o.update_showpatch = True
|
||||||
|
dfiles = [d1, dir1, d2, d3t]
|
||||||
|
|
||||||
# import the files
|
# import the files
|
||||||
o.import_path = dfiles
|
o.import_path = dfiles
|
||||||
cmd_importer(o)
|
cmd_importer(o)
|
||||||
|
|
||||||
|
# get new config
|
||||||
o = load_options(confpath, profile)
|
o = load_options(confpath, profile)
|
||||||
|
|
||||||
# edit the files
|
# edit the files
|
||||||
@@ -92,6 +99,7 @@ class TestUpdate(unittest.TestCase):
|
|||||||
o.safe = False
|
o.safe = False
|
||||||
o.debug = True
|
o.debug = True
|
||||||
o.update_path = [d1, dir1]
|
o.update_path = [d1, dir1]
|
||||||
|
o.update_showpatch = True
|
||||||
cmd_update(o)
|
cmd_update(o)
|
||||||
|
|
||||||
# test content
|
# test content
|
||||||
@@ -114,7 +122,7 @@ class TestUpdate(unittest.TestCase):
|
|||||||
o.safe = False
|
o.safe = False
|
||||||
o.debug = True
|
o.debug = True
|
||||||
o.update_path = [d2key]
|
o.update_path = [d2key]
|
||||||
o.iskey = True
|
o.update_iskey = True
|
||||||
cmd_update(o)
|
cmd_update(o)
|
||||||
|
|
||||||
# test content
|
# test content
|
||||||
|
|||||||
Reference in New Issue
Block a user