mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-04 16:49:42 +00:00
linting
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
# pylint: disable-msg=C0103
|
||||||
"""
|
"""
|
||||||
author: deadc0de6 (https://github.com/deadc0de6)
|
author: deadc0de6 (https://github.com/deadc0de6)
|
||||||
Copyright (c) 2020, deadc0de6
|
Copyright (c) 2020, deadc0de6
|
||||||
@@ -32,6 +33,7 @@ def run_test(logfd, path):
|
|||||||
if logfd:
|
if logfd:
|
||||||
logfd.write(f'starting test \"{path}\"\n')
|
logfd.write(f'starting test \"{path}\"\n')
|
||||||
logfd.flush()
|
logfd.flush()
|
||||||
|
# pylint: disable=R1732
|
||||||
proc = subprocess.Popen(path, shell=False,
|
proc = subprocess.Popen(path, shell=False,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
@@ -73,6 +75,7 @@ def main():
|
|||||||
|
|
||||||
logfd = sys.stdout
|
logfd = sys.stdout
|
||||||
if not is_cicd():
|
if not is_cicd():
|
||||||
|
# pylint: disable=R1732
|
||||||
logfd = open(LOG_FILE, 'w', encoding='utf-8')
|
logfd = open(LOG_FILE, 'w', encoding='utf-8')
|
||||||
if max_jobs:
|
if max_jobs:
|
||||||
logfd.write(f'run tests with {max_jobs} parallel job(s)\n')
|
logfd.write(f'run tests with {max_jobs} parallel job(s)\n')
|
||||||
@@ -95,6 +98,7 @@ def main():
|
|||||||
for test in futures.as_completed(wait_for.keys()):
|
for test in futures.as_completed(wait_for.keys()):
|
||||||
try:
|
try:
|
||||||
ret, reason, name, log = test.result()
|
ret, reason, name, log = test.result()
|
||||||
|
# pylint: disable=W0703
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
print()
|
print()
|
||||||
print(f'test \"{wait_for[test]}\" failed: {exc}')
|
print(f'test \"{wait_for[test]}\" failed: {exc}')
|
||||||
|
|||||||
@@ -10,11 +10,13 @@ import dotdrop
|
|||||||
|
|
||||||
|
|
||||||
class TestDummy(unittest.TestCase):
|
class TestDummy(unittest.TestCase):
|
||||||
|
"""test case"""
|
||||||
|
|
||||||
dotdrop.main()
|
dotdrop.main()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
"""entry point"""
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
124
tests/helpers.py
124
tests/helpers.py
@@ -21,27 +21,30 @@ TMPSUFFIX = '-dotdrop-tests'
|
|||||||
|
|
||||||
|
|
||||||
class SubsetTestCase(TestCase):
|
class SubsetTestCase(TestCase):
|
||||||
def assertIsSubset(self, sub, sup):
|
"""test case"""
|
||||||
for subKey, subValue in sub.items():
|
|
||||||
self.assertIn(subKey, sup)
|
|
||||||
supValue = sup[subKey]
|
|
||||||
|
|
||||||
if isinstance(subValue, str):
|
def assert_is_subset(self, sub, sup):
|
||||||
self.assertEqual(subValue, supValue)
|
"""ensure it's a subset"""
|
||||||
|
for sub_key, sub_val in sub.items():
|
||||||
|
self.assertIn(sub_key, sup)
|
||||||
|
subvalue = sup[sub_key]
|
||||||
|
|
||||||
|
if isinstance(sub_val, str):
|
||||||
|
self.assertEqual(sub_val, subvalue)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if isinstance(subValue, dict):
|
if isinstance(sub_val, dict):
|
||||||
self.assertIsSubset(subValue, supValue)
|
self.assert_is_subset(sub_val, subvalue)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
iter(subValue)
|
iter(sub_val)
|
||||||
self.assertTrue(all(
|
self.assertTrue(all(
|
||||||
subItem in supValue
|
subItem in subvalue
|
||||||
for subItem in subValue
|
for subItem in sub_val
|
||||||
))
|
))
|
||||||
except TypeError:
|
except TypeError:
|
||||||
self.assertEqual(subValue, supValue)
|
self.assertEqual(sub_val, subvalue)
|
||||||
|
|
||||||
|
|
||||||
def clean(path):
|
def clean(path):
|
||||||
@@ -60,7 +63,7 @@ def get_string(length):
|
|||||||
"""Get a random string of length 'length'"""
|
"""Get a random string of length 'length'"""
|
||||||
alpha = string.ascii_uppercase + string.digits
|
alpha = string.ascii_uppercase + string.digits
|
||||||
temp = ''.join(random.choice(alpha) for _ in range(length))
|
temp = ''.join(random.choice(alpha) for _ in range(length))
|
||||||
return 'tmp.{}{}'.format(temp, TMPSUFFIX)
|
return f'tmp.{temp}{TMPSUFFIX}'
|
||||||
|
|
||||||
|
|
||||||
def get_tempdir():
|
def get_tempdir():
|
||||||
@@ -82,15 +85,16 @@ def create_random_file(directory, content=None,
|
|||||||
pre = bytes()
|
pre = bytes()
|
||||||
if template:
|
if template:
|
||||||
pre = bytes('{{@@ header() @@}}\n', 'ascii')
|
pre = bytes('{{@@ header() @@}}\n', 'ascii')
|
||||||
content = bytes('{}{}\n'.format(pre, get_string(100)), 'ascii')
|
content = bytes(f'{pre}{get_string(100)}\n', 'ascii')
|
||||||
else:
|
else:
|
||||||
pre = ''
|
pre = ''
|
||||||
if template:
|
if template:
|
||||||
pre = '{{@@ header() @@}}\n'
|
pre = '{{@@ header() @@}}\n'
|
||||||
content = '{}{}\n'.format(pre, get_string(100))
|
content = f'{pre}{get_string(100)}\n'
|
||||||
path = os.path.join(directory, fname)
|
path = os.path.join(directory, fname)
|
||||||
with open(path, mode) as f:
|
# pylint: disable=W1514
|
||||||
f.write(content)
|
with open(path, mode) as file:
|
||||||
|
file.write(content)
|
||||||
return path, content
|
return path, content
|
||||||
|
|
||||||
|
|
||||||
@@ -99,8 +103,9 @@ def edit_content(path, newcontent, binary=False):
|
|||||||
mode = 'w'
|
mode = 'w'
|
||||||
if binary:
|
if binary:
|
||||||
mode = 'wb'
|
mode = 'wb'
|
||||||
with open(path, mode) as f:
|
# pylint: disable=W1514
|
||||||
f.write(newcontent)
|
with open(path, mode) as file:
|
||||||
|
file.write(newcontent)
|
||||||
|
|
||||||
|
|
||||||
def create_dir(path):
|
def create_dir(path):
|
||||||
@@ -159,15 +164,16 @@ def load_options(confpath, profile):
|
|||||||
args['--profile'] = profile
|
args['--profile'] = profile
|
||||||
args['--verbose'] = True
|
args['--verbose'] = True
|
||||||
# and get the options
|
# and get the options
|
||||||
o = Options(args=args)
|
opt = Options(args=args)
|
||||||
o.profile = profile
|
opt.profile = profile
|
||||||
o.dry = False
|
opt.dry = False
|
||||||
o.safe = False
|
opt.safe = False
|
||||||
o.install_diff = True
|
opt.install_diff = True
|
||||||
o.import_link = LinkTypes.NOLINK
|
opt.import_link = LinkTypes.NOLINK
|
||||||
o.install_showdiff = True
|
opt.install_showdiff = True
|
||||||
o.debug = True
|
opt.debug = True
|
||||||
return o
|
opt.dotpath = os.path.join(os.path.dirname(confpath), 'dotfiles')
|
||||||
|
return opt
|
||||||
|
|
||||||
|
|
||||||
def get_path_strip_version(path):
|
def get_path_strip_version(path):
|
||||||
@@ -192,7 +198,9 @@ def get_dotfile_from_yaml(dic, path):
|
|||||||
|
|
||||||
|
|
||||||
def yaml_dashed_list(items, indent=0):
|
def yaml_dashed_list(items, indent=0):
|
||||||
return ('\n'.join('{}- {}'.format(' ' * indent, item) for item in items)
|
"""yaml dashed list"""
|
||||||
|
ind = ' ' * indent
|
||||||
|
return ('\n'.join(f'{ind}- {item}' for item in items)
|
||||||
+ '\n')
|
+ '\n')
|
||||||
|
|
||||||
|
|
||||||
@@ -203,28 +211,29 @@ def create_fake_config(directory, configname='config.yaml',
|
|||||||
"""Create a fake config file"""
|
"""Create a fake config file"""
|
||||||
path = os.path.join(directory, configname)
|
path = os.path.join(directory, configname)
|
||||||
workdir = os.path.join(directory, 'workdir')
|
workdir = os.path.join(directory, 'workdir')
|
||||||
with open(path, 'w') as f:
|
with open(path, 'w', encoding='utf-8') as file:
|
||||||
f.write('config:\n')
|
file.write('config:\n')
|
||||||
f.write(' backup: {}\n'.format(str(backup)))
|
file.write(f' backup: {backup}\n')
|
||||||
f.write(' create: {}\n'.format(str(create)))
|
file.write(f' create: {create}\n')
|
||||||
f.write(' dotpath: {}\n'.format(dotpath))
|
file.write(f' dotpath: {dotpath}\n')
|
||||||
f.write(' workdir: {}\n'.format(workdir))
|
file.write(f' workdir: {workdir}\n')
|
||||||
if import_actions:
|
if import_actions:
|
||||||
f.write(' import_actions:\n')
|
file.write(' import_actions:\n')
|
||||||
f.write(yaml_dashed_list(import_actions, 4))
|
file.write(yaml_dashed_list(import_actions, 4))
|
||||||
if import_configs:
|
if import_configs:
|
||||||
f.write(' import_configs:\n')
|
file.write(' import_configs:\n')
|
||||||
f.write(yaml_dashed_list(import_configs, 4))
|
file.write(yaml_dashed_list(import_configs, 4))
|
||||||
if import_variables:
|
if import_variables:
|
||||||
f.write(' import_variables:\n')
|
file.write(' import_variables:\n')
|
||||||
f.write(yaml_dashed_list(import_variables, 4))
|
file.write(yaml_dashed_list(import_variables, 4))
|
||||||
f.write('dotfiles:\n')
|
file.write('dotfiles:\n')
|
||||||
f.write('profiles:\n')
|
file.write('profiles:\n')
|
||||||
f.write('actions:\n')
|
file.write('actions:\n')
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
def create_yaml_keyval(pairs, parent_dir=None, top_key=None):
|
def create_yaml_keyval(pairs, parent_dir=None, top_key=None):
|
||||||
|
"""create key val for yaml"""
|
||||||
if top_key:
|
if top_key:
|
||||||
pairs = {top_key: pairs}
|
pairs = {top_key: pairs}
|
||||||
if not parent_dir:
|
if not parent_dir:
|
||||||
@@ -235,6 +244,7 @@ def create_yaml_keyval(pairs, parent_dir=None, top_key=None):
|
|||||||
return file_name
|
return file_name
|
||||||
|
|
||||||
|
|
||||||
|
# pylint: disable=W0102
|
||||||
def populate_fake_config(config, dotfiles={}, profiles={}, actions={},
|
def populate_fake_config(config, dotfiles={}, profiles={}, actions={},
|
||||||
trans={}, trans_write={}, variables={},
|
trans={}, trans_write={}, variables={},
|
||||||
dynvariables={}):
|
dynvariables={}):
|
||||||
@@ -267,14 +277,14 @@ def file_in_yaml(yaml_file, path, link=False):
|
|||||||
|
|
||||||
dotfiles = yaml_conf['dotfiles'].values()
|
dotfiles = yaml_conf['dotfiles'].values()
|
||||||
|
|
||||||
in_src = any([x['src'].endswith(strip) for x in dotfiles])
|
in_src = any(x['src'].endswith(strip) for x in dotfiles)
|
||||||
in_dst = path in (os.path.expanduser(x['dst']) for x in dotfiles)
|
in_dst = path in (os.path.expanduser(x['dst']) for x in dotfiles)
|
||||||
|
|
||||||
if link:
|
if link:
|
||||||
df = get_dotfile_from_yaml(yaml_conf, path)
|
dotfile = get_dotfile_from_yaml(yaml_conf, path)
|
||||||
has_link = False
|
has_link = False
|
||||||
if df:
|
if dotfile:
|
||||||
has_link = 'link' in df
|
has_link = 'link' in dotfile
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return in_src and in_dst and has_link
|
return in_src and in_dst and has_link
|
||||||
@@ -282,15 +292,17 @@ def file_in_yaml(yaml_file, path, link=False):
|
|||||||
|
|
||||||
|
|
||||||
def yaml_load(path):
|
def yaml_load(path):
|
||||||
with open(path, 'r') as f:
|
"""load yaml"""
|
||||||
content = yaml(typ='safe').load(f)
|
with open(path, 'r', encoding='utf-8') as file:
|
||||||
|
content = yaml(typ='safe').load(file)
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
|
||||||
def yaml_dump(content, path):
|
def yaml_dump(content, path):
|
||||||
with open(path, 'w') as f:
|
"""dump yaml"""
|
||||||
y = yaml()
|
with open(path, 'w', encoding='utf-8') as file:
|
||||||
y.default_flow_style = False
|
cont = yaml()
|
||||||
y.indent = 2
|
cont.default_flow_style = False
|
||||||
y.typ = 'safe'
|
cont.indent = 2
|
||||||
y.dump(content, f)
|
cont.typ = 'safe'
|
||||||
|
cont.dump(content, file)
|
||||||
|
|||||||
@@ -20,24 +20,26 @@ from tests.helpers import create_dir, get_string, get_tempdir, clean, \
|
|||||||
|
|
||||||
|
|
||||||
class TestCompare(unittest.TestCase):
|
class TestCompare(unittest.TestCase):
|
||||||
|
"""test case"""
|
||||||
|
|
||||||
CONFIG_BACKUP = False
|
CONFIG_BACKUP = False
|
||||||
CONFIG_CREATE = True
|
CONFIG_CREATE = True
|
||||||
CONFIG_DOTPATH = 'dotfiles'
|
CONFIG_DOTPATH = 'dotfiles'
|
||||||
CONFIG_NAME = 'config.yaml'
|
CONFIG_NAME = 'config.yaml'
|
||||||
|
|
||||||
def compare(self, o, tmp, nbdotfiles):
|
def compare(self, opt, tmp, nbdotfiles):
|
||||||
dotfiles = o.dotfiles
|
"""compare"""
|
||||||
|
dotfiles = opt.dotfiles
|
||||||
self.assertTrue(len(dotfiles) == nbdotfiles)
|
self.assertTrue(len(dotfiles) == nbdotfiles)
|
||||||
t = Templategen(base=o.dotpath, debug=True)
|
templ = Templategen(base=opt.dotpath, debug=True)
|
||||||
inst = Installer(create=o.create, backup=o.backup,
|
inst = Installer(create=opt.create, backup=opt.backup,
|
||||||
dry=o.dry, base=o.dotpath, debug=o.debug)
|
dry=opt.dry, base=opt.dotpath, debug=opt.debug)
|
||||||
comp = Comparator()
|
comp = Comparator()
|
||||||
results = {}
|
results = {}
|
||||||
for dotfile in dotfiles:
|
for dotfile in dotfiles:
|
||||||
path = os.path.expanduser(dotfile.dst)
|
path = os.path.expanduser(dotfile.dst)
|
||||||
ret, err, insttmp = inst.install_to_temp(t, tmp, dotfile.src,
|
ret, _, insttmp = inst.install_to_temp(templ, tmp, dotfile.src,
|
||||||
dotfile.dst)
|
dotfile.dst)
|
||||||
if not ret:
|
if not ret:
|
||||||
results[path] = False
|
results[path] = False
|
||||||
continue
|
continue
|
||||||
@@ -47,9 +49,10 @@ class TestCompare(unittest.TestCase):
|
|||||||
return results
|
return results
|
||||||
|
|
||||||
def test_none(self):
|
def test_none(self):
|
||||||
t = Templategen(base=self.CONFIG_DOTPATH,
|
"""test none"""
|
||||||
debug=True, variables=None)
|
templ = Templategen(base=self.CONFIG_DOTPATH,
|
||||||
self.assertTrue(t is not None)
|
debug=True, variables=None)
|
||||||
|
self.assertTrue(templ is not None)
|
||||||
|
|
||||||
def test_compare(self):
|
def test_compare(self):
|
||||||
"""Test the compare function"""
|
"""Test the compare function"""
|
||||||
@@ -74,33 +77,33 @@ class TestCompare(unittest.TestCase):
|
|||||||
self.addCleanup(clean, dotfilespath)
|
self.addCleanup(clean, dotfilespath)
|
||||||
|
|
||||||
# create the dotfiles to test
|
# create the dotfiles to test
|
||||||
d1, c1 = create_random_file(fold_config)
|
df1, _ = create_random_file(fold_config)
|
||||||
self.assertTrue(os.path.exists(d1))
|
self.assertTrue(os.path.exists(df1))
|
||||||
self.addCleanup(clean, d1)
|
self.addCleanup(clean, df1)
|
||||||
|
|
||||||
d2, c2 = create_random_file(fold_subcfg)
|
df2, _ = create_random_file(fold_subcfg)
|
||||||
self.assertTrue(os.path.exists(d2))
|
self.assertTrue(os.path.exists(df2))
|
||||||
self.addCleanup(clean, d2)
|
self.addCleanup(clean, df2)
|
||||||
|
|
||||||
d3, c3 = create_random_file(fold_tmp)
|
df3, _ = create_random_file(fold_tmp)
|
||||||
self.assertTrue(os.path.exists(d3))
|
self.assertTrue(os.path.exists(df3))
|
||||||
self.addCleanup(clean, d3)
|
self.addCleanup(clean, df3)
|
||||||
|
|
||||||
d4, c4 = create_random_file(fold_tmp, binary=True)
|
df4, _ = create_random_file(fold_tmp, binary=True)
|
||||||
self.assertTrue(os.path.exists(d4))
|
self.assertTrue(os.path.exists(df4))
|
||||||
self.addCleanup(clean, d4)
|
self.addCleanup(clean, df4)
|
||||||
|
|
||||||
d5 = get_tempdir()
|
df5 = get_tempdir()
|
||||||
self.assertTrue(os.path.exists(d5))
|
self.assertTrue(os.path.exists(df5))
|
||||||
self.addCleanup(clean, d5)
|
self.addCleanup(clean, df5)
|
||||||
|
|
||||||
d6, _ = create_random_file(d5)
|
df6, _ = create_random_file(df5)
|
||||||
self.assertTrue(os.path.exists(d6))
|
self.assertTrue(os.path.exists(df6))
|
||||||
|
|
||||||
d9 = get_tempdir()
|
df9 = get_tempdir()
|
||||||
self.assertTrue(os.path.exists(d9))
|
self.assertTrue(os.path.exists(df9))
|
||||||
self.addCleanup(clean, d9)
|
self.addCleanup(clean, df9)
|
||||||
d9sub = os.path.join(d9, get_string(5))
|
d9sub = os.path.join(df9, get_string(5))
|
||||||
create_dir(d9sub)
|
create_dir(d9sub)
|
||||||
d9f1, _ = create_random_file(d9sub)
|
d9f1, _ = create_random_file(d9sub)
|
||||||
|
|
||||||
@@ -112,69 +115,70 @@ class TestCompare(unittest.TestCase):
|
|||||||
backup=self.CONFIG_BACKUP,
|
backup=self.CONFIG_BACKUP,
|
||||||
create=self.CONFIG_CREATE)
|
create=self.CONFIG_CREATE)
|
||||||
self.assertTrue(os.path.exists(confpath))
|
self.assertTrue(os.path.exists(confpath))
|
||||||
o = load_options(confpath, profile)
|
opt = load_options(confpath, profile)
|
||||||
o.longkey = True
|
opt.longkey = True
|
||||||
o.debug = True
|
opt.debug = True
|
||||||
dfiles = [d1, d2, d3, d4, d5, d9]
|
dfiles = [df1, df2, df3, df4, df5, df9]
|
||||||
|
|
||||||
# import the files
|
# import the files
|
||||||
o.import_path = dfiles
|
opt.import_path = dfiles
|
||||||
cmd_importer(o)
|
cmd_importer(opt)
|
||||||
o = load_options(confpath, profile)
|
opt = load_options(confpath, profile)
|
||||||
|
|
||||||
# compare the files
|
# compare the files
|
||||||
expected = {d1: True, d2: True, d3: True, d4: True,
|
expected = {df1: True, df2: True, df3: True, df4: True,
|
||||||
d5: True, d9: True}
|
df5: True, df9: True}
|
||||||
results = self.compare(o, tmp, len(dfiles))
|
results = self.compare(opt, tmp, len(dfiles))
|
||||||
self.assertTrue(results == expected)
|
self.assertTrue(results == expected)
|
||||||
|
|
||||||
# modify file
|
# modify file
|
||||||
edit_content(d1, get_string(20))
|
edit_content(df1, get_string(20))
|
||||||
expected = {d1: False, d2: True, d3: True, d4: True,
|
expected = {df1: False, df2: True, df3: True, df4: True,
|
||||||
d5: True, d9: True}
|
df5: True, df9: True}
|
||||||
results = self.compare(o, tmp, len(dfiles))
|
results = self.compare(opt, tmp, len(dfiles))
|
||||||
self.assertTrue(results == expected)
|
self.assertTrue(results == expected)
|
||||||
|
|
||||||
# modify binary file
|
# modify binary file
|
||||||
edit_content(d4, bytes(get_string(20), 'ascii'), binary=True)
|
edit_content(df4, bytes(get_string(20), 'ascii'), binary=True)
|
||||||
expected = {d1: False, d2: True, d3: True, d4: False,
|
expected = {df1: False, df2: True, df3: True, df4: False,
|
||||||
d5: True, d9: True}
|
df5: True, df9: True}
|
||||||
results = self.compare(o, tmp, len(dfiles))
|
results = self.compare(opt, tmp, len(dfiles))
|
||||||
self.assertTrue(results == expected)
|
self.assertTrue(results == expected)
|
||||||
|
|
||||||
# add file in directory
|
# add file in directory
|
||||||
d7, _ = create_random_file(d5)
|
df7, _ = create_random_file(df5)
|
||||||
self.assertTrue(os.path.exists(d7))
|
self.assertTrue(os.path.exists(df7))
|
||||||
expected = {d1: False, d2: True, d3: True, d4: False,
|
expected = {df1: False, df2: True, df3: True, df4: False,
|
||||||
d5: False, d9: True}
|
df5: False, df9: True}
|
||||||
results = self.compare(o, tmp, len(dfiles))
|
results = self.compare(opt, tmp, len(dfiles))
|
||||||
self.assertTrue(results == expected)
|
self.assertTrue(results == expected)
|
||||||
|
|
||||||
# modify all files
|
# modify all files
|
||||||
edit_content(d2, get_string(20))
|
edit_content(df2, get_string(20))
|
||||||
edit_content(d3, get_string(21))
|
edit_content(df3, get_string(21))
|
||||||
expected = {d1: False, d2: False, d3: False, d4: False,
|
expected = {df1: False, df2: False, df3: False, df4: False,
|
||||||
d5: False, d9: True}
|
df5: False, df9: True}
|
||||||
results = self.compare(o, tmp, len(dfiles))
|
results = self.compare(opt, tmp, len(dfiles))
|
||||||
self.assertTrue(results == expected)
|
self.assertTrue(results == expected)
|
||||||
|
|
||||||
# edit sub file
|
# edit sub file
|
||||||
edit_content(d9f1, get_string(12))
|
edit_content(d9f1, get_string(12))
|
||||||
expected = {d1: False, d2: False, d3: False, d4: False,
|
expected = {df1: False, df2: False, df3: False, df4: False,
|
||||||
d5: False, d9: False}
|
df5: False, df9: False}
|
||||||
results = self.compare(o, tmp, len(dfiles))
|
results = self.compare(opt, tmp, len(dfiles))
|
||||||
self.assertTrue(results == expected)
|
self.assertTrue(results == expected)
|
||||||
|
|
||||||
# test compare from dotdrop
|
# test compare from dotdrop
|
||||||
self.assertFalse(cmd_compare(o, tmp))
|
self.assertFalse(cmd_compare(opt, tmp))
|
||||||
# test focus
|
# test focus
|
||||||
o.compare_focus = [d4]
|
opt.compare_focus = [df4]
|
||||||
self.assertFalse(cmd_compare(o, tmp))
|
self.assertFalse(cmd_compare(opt, tmp))
|
||||||
o.compare_focus = ['/tmp/fake']
|
opt.compare_focus = ['/tmp/fake']
|
||||||
self.assertFalse(cmd_compare(o, tmp))
|
self.assertFalse(cmd_compare(opt, tmp))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
"""entry point"""
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ from tests.helpers import (clean, create_dir, create_fake_config,
|
|||||||
|
|
||||||
|
|
||||||
class TestImport(unittest.TestCase):
|
class TestImport(unittest.TestCase):
|
||||||
|
"""test case"""
|
||||||
|
|
||||||
CONFIG_BACKUP = False
|
CONFIG_BACKUP = False
|
||||||
CONFIG_CREATE = True
|
CONFIG_CREATE = True
|
||||||
@@ -33,11 +34,11 @@ class TestImport(unittest.TestCase):
|
|||||||
self.assertTrue(os.path.exists(path))
|
self.assertTrue(os.path.exists(path))
|
||||||
return yaml_load(path)
|
return yaml_load(path)
|
||||||
|
|
||||||
def assert_file(self, path, o, profile):
|
def assert_file(self, path, opt, _profile):
|
||||||
"""Make sure path has been inserted in conf for profile"""
|
"""Make sure path has been inserted in conf for profile"""
|
||||||
strip = get_path_strip_version(path)
|
strip = get_path_strip_version(path)
|
||||||
self.assertTrue(any(x.src.endswith(strip) for x in o.dotfiles))
|
self.assertTrue(any(x.src.endswith(strip) for x in opt.dotfiles))
|
||||||
dsts = (os.path.expanduser(x.dst) for x in o.dotfiles)
|
dsts = (os.path.expanduser(x.dst) for x in opt.dotfiles)
|
||||||
self.assertTrue(path in dsts)
|
self.assertTrue(path in dsts)
|
||||||
|
|
||||||
def assert_in_yaml(self, path, dic, link=False):
|
def assert_in_yaml(self, path, dic, link=False):
|
||||||
@@ -63,12 +64,12 @@ class TestImport(unittest.TestCase):
|
|||||||
backup=self.CONFIG_BACKUP,
|
backup=self.CONFIG_BACKUP,
|
||||||
create=self.CONFIG_CREATE)
|
create=self.CONFIG_CREATE)
|
||||||
self.assertTrue(os.path.exists(confpath))
|
self.assertTrue(os.path.exists(confpath))
|
||||||
o = load_options(confpath, profile)
|
opt = load_options(confpath, profile)
|
||||||
|
|
||||||
# create some random dotfiles
|
# create some random dotfiles
|
||||||
dotfile1, content1 = create_random_file(src)
|
dotfile1, _ = create_random_file(src)
|
||||||
self.addCleanup(clean, dotfile1)
|
self.addCleanup(clean, dotfile1)
|
||||||
dotfile2, content2 = create_random_file(os.path.expanduser('~'))
|
dotfile2, _ = create_random_file(os.path.expanduser('~'))
|
||||||
self.addCleanup(clean, dotfile2)
|
self.addCleanup(clean, dotfile2)
|
||||||
homeconf = os.path.join(os.path.expanduser('~'), '.config')
|
homeconf = os.path.join(os.path.expanduser('~'), '.config')
|
||||||
if not os.path.exists(homeconf):
|
if not os.path.exists(homeconf):
|
||||||
@@ -77,8 +78,8 @@ class TestImport(unittest.TestCase):
|
|||||||
dotconfig = os.path.join(homeconf, get_string(5))
|
dotconfig = os.path.join(homeconf, get_string(5))
|
||||||
create_dir(dotconfig)
|
create_dir(dotconfig)
|
||||||
self.addCleanup(clean, dotconfig)
|
self.addCleanup(clean, dotconfig)
|
||||||
dotfile3, content3 = create_random_file(dotconfig)
|
dotfile3, _ = create_random_file(dotconfig)
|
||||||
dotfile4, content3 = create_random_file(homeconf)
|
dotfile4, _ = create_random_file(homeconf)
|
||||||
self.addCleanup(clean, dotfile4)
|
self.addCleanup(clean, dotfile4)
|
||||||
|
|
||||||
# fake a directory containing dotfiles
|
# fake a directory containing dotfiles
|
||||||
@@ -89,7 +90,7 @@ class TestImport(unittest.TestCase):
|
|||||||
sub2, _ = create_random_file(dotfile5)
|
sub2, _ = create_random_file(dotfile5)
|
||||||
|
|
||||||
# fake a file for symlink
|
# fake a file for symlink
|
||||||
dotfile6, content6 = create_random_file(dotconfig)
|
dotfile6, _ = create_random_file(dotconfig)
|
||||||
self.addCleanup(clean, dotfile6)
|
self.addCleanup(clean, dotfile6)
|
||||||
|
|
||||||
# fake a directory for symlink
|
# fake a directory for symlink
|
||||||
@@ -101,37 +102,37 @@ class TestImport(unittest.TestCase):
|
|||||||
|
|
||||||
# import the dotfiles
|
# import the dotfiles
|
||||||
dfiles = [dotfile1, dotfile2, dotfile3, dotfile4, dotfile5]
|
dfiles = [dotfile1, dotfile2, dotfile3, dotfile4, dotfile5]
|
||||||
o.import_path = dfiles
|
opt.import_path = dfiles
|
||||||
cmd_importer(o)
|
cmd_importer(opt)
|
||||||
# import symlink
|
# import symlink
|
||||||
o.import_link = LinkTypes.LINK
|
opt.import_link = LinkTypes.LINK
|
||||||
sfiles = [dotfile6, dotfile7]
|
sfiles = [dotfile6, dotfile7]
|
||||||
o.import_path = sfiles
|
opt.import_path = sfiles
|
||||||
cmd_importer(o)
|
cmd_importer(opt)
|
||||||
o.import_link = LinkTypes.NOLINK
|
opt.import_link = LinkTypes.NOLINK
|
||||||
|
|
||||||
# reload the config
|
# reload the config
|
||||||
o = load_options(confpath, profile)
|
opt = load_options(confpath, profile)
|
||||||
|
|
||||||
# test dotfiles in config class
|
# test dotfiles in config class
|
||||||
self.assertTrue(profile in [p.key for p in o.profiles])
|
self.assertTrue(profile in [p.key for p in opt.profiles])
|
||||||
self.assert_file(dotfile1, o, profile)
|
self.assert_file(dotfile1, opt, profile)
|
||||||
self.assert_file(dotfile2, o, profile)
|
self.assert_file(dotfile2, opt, profile)
|
||||||
self.assert_file(dotfile3, o, profile)
|
self.assert_file(dotfile3, opt, profile)
|
||||||
self.assert_file(dotfile4, o, profile)
|
self.assert_file(dotfile4, opt, profile)
|
||||||
self.assert_file(dotfile5, o, profile)
|
self.assert_file(dotfile5, opt, profile)
|
||||||
self.assert_file(dotfile6, o, profile)
|
self.assert_file(dotfile6, opt, profile)
|
||||||
self.assert_file(dotfile7, o, profile)
|
self.assert_file(dotfile7, opt, profile)
|
||||||
|
|
||||||
# test dotfiles in yaml file
|
# test dotfiles in yaml file
|
||||||
y = self.load_yaml(confpath)
|
cont2 = self.load_yaml(confpath)
|
||||||
self.assert_in_yaml(dotfile1, y)
|
self.assert_in_yaml(dotfile1, cont2)
|
||||||
self.assert_in_yaml(dotfile2, y)
|
self.assert_in_yaml(dotfile2, cont2)
|
||||||
self.assert_in_yaml(dotfile3, y)
|
self.assert_in_yaml(dotfile3, cont2)
|
||||||
self.assert_in_yaml(dotfile4, y)
|
self.assert_in_yaml(dotfile4, cont2)
|
||||||
self.assert_in_yaml(dotfile5, y)
|
self.assert_in_yaml(dotfile5, cont2)
|
||||||
self.assert_in_yaml(dotfile6, y, link=True)
|
self.assert_in_yaml(dotfile6, cont2, link=True)
|
||||||
self.assert_in_yaml(dotfile7, y, link=True)
|
self.assert_in_yaml(dotfile7, cont2, link=True)
|
||||||
|
|
||||||
# test have been imported in dotdrop dotpath directory
|
# test have been imported in dotdrop dotpath directory
|
||||||
indt1 = os.path.join(dotfilespath,
|
indt1 = os.path.join(dotfilespath,
|
||||||
@@ -154,16 +155,16 @@ class TestImport(unittest.TestCase):
|
|||||||
self.CONFIG_DOTPATH,
|
self.CONFIG_DOTPATH,
|
||||||
get_path_strip_version(dotfile5))
|
get_path_strip_version(dotfile5))
|
||||||
self.assertTrue(os.path.exists(indt5))
|
self.assertTrue(os.path.exists(indt5))
|
||||||
s1 = os.path.join(dotfilespath,
|
fsb1 = os.path.join(dotfilespath,
|
||||||
self.CONFIG_DOTPATH,
|
self.CONFIG_DOTPATH,
|
||||||
get_path_strip_version(dotfile6),
|
get_path_strip_version(dotfile6),
|
||||||
sub1)
|
sub1)
|
||||||
self.assertTrue(os.path.exists(s1))
|
self.assertTrue(os.path.exists(fsb1))
|
||||||
s2 = os.path.join(dotfilespath,
|
fsb2 = os.path.join(dotfilespath,
|
||||||
self.CONFIG_DOTPATH,
|
self.CONFIG_DOTPATH,
|
||||||
get_path_strip_version(dotfile6),
|
get_path_strip_version(dotfile6),
|
||||||
sub2)
|
sub2)
|
||||||
self.assertTrue(os.path.exists(s2))
|
self.assertTrue(os.path.exists(fsb2))
|
||||||
indt6 = os.path.join(dotfilespath,
|
indt6 = os.path.join(dotfilespath,
|
||||||
self.CONFIG_DOTPATH,
|
self.CONFIG_DOTPATH,
|
||||||
get_path_strip_version(dotfile6))
|
get_path_strip_version(dotfile6))
|
||||||
@@ -172,29 +173,31 @@ class TestImport(unittest.TestCase):
|
|||||||
self.CONFIG_DOTPATH,
|
self.CONFIG_DOTPATH,
|
||||||
get_path_strip_version(dotfile7))
|
get_path_strip_version(dotfile7))
|
||||||
self.assertTrue(os.path.exists(indt7))
|
self.assertTrue(os.path.exists(indt7))
|
||||||
s3 = os.path.join(dotfilespath,
|
fsb3 = os.path.join(dotfilespath,
|
||||||
self.CONFIG_DOTPATH,
|
self.CONFIG_DOTPATH,
|
||||||
get_path_strip_version(dotfile7),
|
get_path_strip_version(dotfile7),
|
||||||
sub3)
|
sub3)
|
||||||
self.assertTrue(os.path.exists(s3))
|
self.assertTrue(os.path.exists(fsb3))
|
||||||
s4 = os.path.join(dotfilespath,
|
fsb4 = os.path.join(dotfilespath,
|
||||||
self.CONFIG_DOTPATH,
|
self.CONFIG_DOTPATH,
|
||||||
get_path_strip_version(dotfile7),
|
get_path_strip_version(dotfile7),
|
||||||
sub4)
|
sub4)
|
||||||
self.assertTrue(os.path.exists(s4))
|
self.assertTrue(os.path.exists(fsb4))
|
||||||
|
|
||||||
cmd_list_profiles(o)
|
cmd_list_profiles(opt)
|
||||||
cmd_files(o)
|
cmd_files(opt)
|
||||||
|
|
||||||
# fake test update
|
# fake test update
|
||||||
editcontent = 'edited'
|
editcontent = 'edited'
|
||||||
edit_content(dotfile1, editcontent)
|
edit_content(dotfile1, editcontent)
|
||||||
o.safe = False
|
opt.safe = False
|
||||||
o.update_path = [dotfile1]
|
opt.update_path = [dotfile1]
|
||||||
o.debug = True
|
opt.debug = True
|
||||||
cmd_update(o)
|
cmd_update(opt)
|
||||||
c2 = open(indt1, 'r').read()
|
cont = ''
|
||||||
self.assertTrue(editcontent == c2)
|
with open(indt1, 'r', encoding='utf-8') as file:
|
||||||
|
cont = file.read()
|
||||||
|
self.assertTrue(editcontent == cont)
|
||||||
|
|
||||||
def test_ext_config_yaml_not_mix(self):
|
def test_ext_config_yaml_not_mix(self):
|
||||||
"""Test whether the import_configs mixes yaml files upon importing."""
|
"""Test whether the import_configs mixes yaml files upon importing."""
|
||||||
@@ -311,37 +314,37 @@ class TestImport(unittest.TestCase):
|
|||||||
})
|
})
|
||||||
|
|
||||||
# import the dotfiles
|
# import the dotfiles
|
||||||
o = load_options(imported_path, 'host1')
|
opt = load_options(imported_path, 'host1')
|
||||||
o.import_path = dotfiles_ed
|
opt.import_path = dotfiles_ed
|
||||||
cmd_importer(o)
|
cmd_importer(opt)
|
||||||
|
|
||||||
o = load_options(importing_path, 'host2')
|
opt = load_options(importing_path, 'host2')
|
||||||
o.import_path = dotfiles_ing
|
opt.import_path = dotfiles_ing
|
||||||
cmd_importer(o)
|
cmd_importer(opt)
|
||||||
|
|
||||||
# reload the config
|
# reload the config
|
||||||
o = load_options(importing_path, 'host2')
|
opt = load_options(importing_path, 'host2')
|
||||||
|
|
||||||
# test imported config
|
# test imported config
|
||||||
y = self.load_yaml(imported_path)
|
ycont = self.load_yaml(imported_path)
|
||||||
|
|
||||||
# testing dotfiles
|
# testing dotfiles
|
||||||
self.assertTrue(all(file_in_yaml(y, df)
|
self.assertTrue(all(file_in_yaml(ycont, df)
|
||||||
for df in dotfiles_ed))
|
for df in dotfiles_ed))
|
||||||
self.assertFalse(any(file_in_yaml(y, df)
|
self.assertFalse(any(file_in_yaml(ycont, df)
|
||||||
for df in dotfiles_ing))
|
for df in dotfiles_ing))
|
||||||
|
|
||||||
# testing profiles
|
# testing profiles
|
||||||
profiles = y['profiles'].keys()
|
profiles = ycont['profiles'].keys()
|
||||||
self.assertTrue('host1' in profiles)
|
self.assertTrue('host1' in profiles)
|
||||||
self.assertFalse('host2' in profiles)
|
self.assertFalse('host2' in profiles)
|
||||||
|
|
||||||
# testing actions
|
# testing actions
|
||||||
actions = y['actions']['pre']
|
actions = ycont['actions']['pre']
|
||||||
actions.update(y['actions']['post'])
|
actions.update(ycont['actions']['post'])
|
||||||
actions.update({
|
actions.update({
|
||||||
k: v
|
k: v
|
||||||
for k, v in y['actions'].items()
|
for k, v in ycont['actions'].items()
|
||||||
if k not in ('pre', 'post')
|
if k not in ('pre', 'post')
|
||||||
})
|
})
|
||||||
actions = actions.keys()
|
actions = actions.keys()
|
||||||
@@ -349,41 +352,41 @@ class TestImport(unittest.TestCase):
|
|||||||
self.assertFalse(any(a.endswith('ing') for a in actions))
|
self.assertFalse(any(a.endswith('ing') for a in actions))
|
||||||
|
|
||||||
# testing transformations
|
# testing transformations
|
||||||
transformations = y['trans_read'].keys()
|
transformations = ycont['trans_read'].keys()
|
||||||
self.assertTrue(all(t.endswith('ed') for t in transformations))
|
self.assertTrue(all(t.endswith('ed') for t in transformations))
|
||||||
self.assertFalse(any(t.endswith('ing') for t in transformations))
|
self.assertFalse(any(t.endswith('ing') for t in transformations))
|
||||||
transformations = y['trans_write'].keys()
|
transformations = ycont['trans_write'].keys()
|
||||||
self.assertTrue(all(t.endswith('ed') for t in transformations))
|
self.assertTrue(all(t.endswith('ed') for t in transformations))
|
||||||
self.assertFalse(any(t.endswith('ing') for t in transformations))
|
self.assertFalse(any(t.endswith('ing') for t in transformations))
|
||||||
|
|
||||||
# testing variables
|
# testing variables
|
||||||
variables = self._remove_priv_vars(y['variables'].keys())
|
variables = self._remove_priv_vars(ycont['variables'].keys())
|
||||||
self.assertTrue(all(v.endswith('ed') for v in variables))
|
self.assertTrue(all(v.endswith('ed') for v in variables))
|
||||||
self.assertFalse(any(v.endswith('ing') for v in variables))
|
self.assertFalse(any(v.endswith('ing') for v in variables))
|
||||||
dyn_variables = y['dynvariables'].keys()
|
dyn_variables = ycont['dynvariables'].keys()
|
||||||
self.assertTrue(all(dv.endswith('ed') for dv in dyn_variables))
|
self.assertTrue(all(dv.endswith('ed') for dv in dyn_variables))
|
||||||
self.assertFalse(any(dv.endswith('ing') for dv in dyn_variables))
|
self.assertFalse(any(dv.endswith('ing') for dv in dyn_variables))
|
||||||
|
|
||||||
# test importing config
|
# test importing config
|
||||||
y = self.load_yaml(importing_path)
|
ycont = self.load_yaml(importing_path)
|
||||||
|
|
||||||
# testing dotfiles
|
# testing dotfiles
|
||||||
self.assertTrue(all(file_in_yaml(y, df)
|
self.assertTrue(all(file_in_yaml(ycont, df)
|
||||||
for df in dotfiles_ing))
|
for df in dotfiles_ing))
|
||||||
self.assertFalse(any(file_in_yaml(y, df)
|
self.assertFalse(any(file_in_yaml(ycont, df)
|
||||||
for df in dotfiles_ed))
|
for df in dotfiles_ed))
|
||||||
|
|
||||||
# testing profiles
|
# testing profiles
|
||||||
profiles = y['profiles'].keys()
|
profiles = ycont['profiles'].keys()
|
||||||
self.assertTrue('host2' in profiles)
|
self.assertTrue('host2' in profiles)
|
||||||
self.assertFalse('host1' in profiles)
|
self.assertFalse('host1' in profiles)
|
||||||
|
|
||||||
# testing actions
|
# testing actions
|
||||||
actions = y['actions']['pre']
|
actions = ycont['actions']['pre']
|
||||||
actions.update(y['actions']['post'])
|
actions.update(ycont['actions']['post'])
|
||||||
actions.update({
|
actions.update({
|
||||||
k: v
|
k: v
|
||||||
for k, v in y['actions'].items()
|
for k, v in ycont['actions'].items()
|
||||||
if k not in ('pre', 'post')
|
if k not in ('pre', 'post')
|
||||||
})
|
})
|
||||||
actions = actions.keys()
|
actions = actions.keys()
|
||||||
@@ -391,18 +394,18 @@ class TestImport(unittest.TestCase):
|
|||||||
self.assertFalse(any(action.endswith('ed') for action in actions))
|
self.assertFalse(any(action.endswith('ed') for action in actions))
|
||||||
|
|
||||||
# testing transformations
|
# testing transformations
|
||||||
transformations = y['trans_read'].keys()
|
transformations = ycont['trans_read'].keys()
|
||||||
self.assertTrue(all(t.endswith('ing') for t in transformations))
|
self.assertTrue(all(t.endswith('ing') for t in transformations))
|
||||||
self.assertFalse(any(t.endswith('ed') for t in transformations))
|
self.assertFalse(any(t.endswith('ed') for t in transformations))
|
||||||
transformations = y['trans_write'].keys()
|
transformations = ycont['trans_write'].keys()
|
||||||
self.assertTrue(all(t.endswith('ing') for t in transformations))
|
self.assertTrue(all(t.endswith('ing') for t in transformations))
|
||||||
self.assertFalse(any(t.endswith('ed') for t in transformations))
|
self.assertFalse(any(t.endswith('ed') for t in transformations))
|
||||||
|
|
||||||
# testing variables
|
# testing variables
|
||||||
variables = self._remove_priv_vars(y['variables'].keys())
|
variables = self._remove_priv_vars(ycont['variables'].keys())
|
||||||
self.assertTrue(all(v.endswith('ing') for v in variables))
|
self.assertTrue(all(v.endswith('ing') for v in variables))
|
||||||
self.assertFalse(any(v.endswith('ed') for v in variables))
|
self.assertFalse(any(v.endswith('ed') for v in variables))
|
||||||
dyn_variables = y['dynvariables'].keys()
|
dyn_variables = ycont['dynvariables'].keys()
|
||||||
self.assertTrue(all(dv.endswith('ing') for dv in dyn_variables))
|
self.assertTrue(all(dv.endswith('ing') for dv in dyn_variables))
|
||||||
self.assertFalse(any(dv.endswith('ed') for dv in dyn_variables))
|
self.assertFalse(any(dv.endswith('ed') for dv in dyn_variables))
|
||||||
|
|
||||||
@@ -414,6 +417,7 @@ class TestImport(unittest.TestCase):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
"""entry point"""
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,11 +8,10 @@ import os
|
|||||||
import unittest
|
import unittest
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
import filecmp
|
import filecmp
|
||||||
|
|
||||||
from dotdrop.cfg_aggregator import CfgAggregator as Cfg
|
|
||||||
from tests.helpers import (clean, create_dir, create_fake_config,
|
from tests.helpers import (clean, create_dir, create_fake_config,
|
||||||
create_random_file, get_string, get_tempdir,
|
create_random_file, get_string, get_tempdir,
|
||||||
load_options, populate_fake_config)
|
load_options, populate_fake_config)
|
||||||
|
from dotdrop.cfg_aggregator import CfgAggregator as Cfg
|
||||||
from dotdrop.dotfile import Dotfile
|
from dotdrop.dotfile import Dotfile
|
||||||
from dotdrop.installer import Installer
|
from dotdrop.installer import Installer
|
||||||
from dotdrop.action import Action
|
from dotdrop.action import Action
|
||||||
@@ -23,6 +22,7 @@ from dotdrop.linktypes import LinkTypes
|
|||||||
|
|
||||||
|
|
||||||
class TestInstall(unittest.TestCase):
|
class TestInstall(unittest.TestCase):
|
||||||
|
"""test case"""
|
||||||
|
|
||||||
CONFIG_NAME = 'config.yaml'
|
CONFIG_NAME = 'config.yaml'
|
||||||
|
|
||||||
@@ -40,37 +40,38 @@ exec bspwm
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
def fake_config(self, path, dotfiles, profile,
|
def fake_config(self, path, dotfiles, profile,
|
||||||
dotpath, actions, trans):
|
dotpath, actions, transs):
|
||||||
"""Create a fake config file"""
|
"""Create a fake config file"""
|
||||||
with open(path, 'w') as f:
|
with open(path, 'w', encoding='utf-8') as file:
|
||||||
f.write('actions:\n')
|
file.write('actions:\n')
|
||||||
for action in actions:
|
for action in actions:
|
||||||
f.write(' {}: {}\n'.format(action.key, action.action))
|
file.write(f' {action.key}: {action.action}\n')
|
||||||
f.write('trans:\n')
|
file.write('trans:\n')
|
||||||
for tr in trans:
|
for trans in transs:
|
||||||
f.write(' {}: {}\n'.format(tr.key, tr.action))
|
file.write(f' {trans.key}: {trans.action}\n')
|
||||||
f.write('config:\n')
|
file.write('config:\n')
|
||||||
f.write(' backup: true\n')
|
file.write(' backup: true\n')
|
||||||
f.write(' create: true\n')
|
file.write(' create: true\n')
|
||||||
f.write(' dotpath: {}\n'.format(dotpath))
|
file.write(f' dotpath: {dotpath}\n')
|
||||||
f.write('dotfiles:\n')
|
file.write('dotfiles:\n')
|
||||||
for d in dotfiles:
|
for dotfile in dotfiles:
|
||||||
f.write(' {}:\n'.format(d.key))
|
linkval = dotfile.link.name.lower()
|
||||||
f.write(' dst: {}\n'.format(d.dst))
|
file.write(f' {dotfile.key}:\n')
|
||||||
f.write(' src: {}\n'.format(d.src))
|
file.write(f' dst: {dotfile.dst}\n')
|
||||||
f.write(' link: {}\n'.format(d.link.name.lower()))
|
file.write(f' src: {dotfile.src}\n')
|
||||||
if len(d.actions) > 0:
|
file.write(f' link: {linkval}\n')
|
||||||
f.write(' actions:\n')
|
if len(dotfile.actions) > 0:
|
||||||
for action in d.actions:
|
file.write(' actions:\n')
|
||||||
f.write(' - {}\n'.format(action.key))
|
for action in dotfile.actions:
|
||||||
if d.trans_r:
|
file.write(f' - {action.key}\n')
|
||||||
for tr in d.trans_r:
|
if dotfile.trans_r:
|
||||||
f.write(' trans_read: {}\n'.format(tr.key))
|
for trans in dotfile.trans_r:
|
||||||
f.write('profiles:\n')
|
file.write(f' trans_read: {trans.key}\n')
|
||||||
f.write(' {}:\n'.format(profile))
|
file.write('profiles:\n')
|
||||||
f.write(' dotfiles:\n')
|
file.write(f' {profile}:\n')
|
||||||
for d in dotfiles:
|
file.write(' dotfiles:\n')
|
||||||
f.write(' - {}\n'.format(d.key))
|
for dotfile in dotfiles:
|
||||||
|
file.write(f' - {dotfile.key}\n')
|
||||||
return path
|
return path
|
||||||
|
|
||||||
def test_install(self):
|
def test_install(self):
|
||||||
@@ -87,40 +88,43 @@ exec bspwm
|
|||||||
self.addCleanup(clean, dst)
|
self.addCleanup(clean, dst)
|
||||||
|
|
||||||
# create the dotfile in dotdrop
|
# create the dotfile in dotdrop
|
||||||
f1, c1 = create_random_file(tmp)
|
fcontent1, _ = create_random_file(tmp)
|
||||||
dst1 = os.path.join(dst, get_string(6))
|
dst1 = os.path.join(dst, get_string(6))
|
||||||
d1 = Dotfile(get_string(5), dst1, os.path.basename(f1))
|
dotfile1 = Dotfile(get_string(5), dst1, os.path.basename(fcontent1))
|
||||||
# fake a __str__
|
# fake a __str__
|
||||||
self.assertTrue(str(d1) != '')
|
self.assertTrue(str(dotfile1) != '')
|
||||||
f2, c2 = create_random_file(tmp)
|
fcontent2, _ = create_random_file(tmp)
|
||||||
dst2 = os.path.join(dst, get_string(6))
|
dst2 = os.path.join(dst, get_string(6))
|
||||||
d2 = Dotfile(get_string(5), dst2, os.path.basename(f2))
|
dotfile2 = Dotfile(get_string(5), dst2, os.path.basename(fcontent2))
|
||||||
with open(f2, 'w') as f:
|
with open(fcontent2, 'w', encoding='utf-8') as file:
|
||||||
f.write(self.TEMPLATE)
|
file.write(self.TEMPLATE)
|
||||||
f3, _ = create_random_file(tmp, binary=True)
|
fcontent3, _ = create_random_file(tmp, binary=True)
|
||||||
dst3 = os.path.join(dst, get_string(6))
|
dst3 = os.path.join(dst, get_string(6))
|
||||||
d3 = Dotfile(get_string(5), dst3, os.path.basename(f3))
|
dotfile3 = Dotfile(get_string(5), dst3, os.path.basename(fcontent3))
|
||||||
|
|
||||||
# create a directory dotfile
|
# create a directory dotfile
|
||||||
dir1 = os.path.join(tmp, 'somedir')
|
dir1 = os.path.join(tmp, 'somedir')
|
||||||
create_dir(dir1)
|
create_dir(dir1)
|
||||||
fd, _ = create_random_file(dir1)
|
fildfd, _ = create_random_file(dir1)
|
||||||
dstd = os.path.join(dst, get_string(6))
|
dstd = os.path.join(dst, get_string(6))
|
||||||
ddot = Dotfile(get_string(5), dstd, os.path.basename(dir1))
|
ddot = Dotfile(get_string(5), dstd, os.path.basename(dir1))
|
||||||
|
|
||||||
# to test backup
|
# to test backup
|
||||||
f4, c4 = create_random_file(tmp)
|
fcontent4, _ = create_random_file(tmp)
|
||||||
dst4 = os.path.join(dst, get_string(6))
|
dst4 = os.path.join(dst, get_string(6))
|
||||||
d4 = Dotfile(key=get_string(6), dst=dst4, src=os.path.basename(f4))
|
dotfile4 = Dotfile(key=get_string(6),
|
||||||
with open(dst4, 'w') as f:
|
dst=dst4,
|
||||||
f.write(get_string(16))
|
src=os.path.basename(fcontent4))
|
||||||
|
with open(dst4, 'w',
|
||||||
|
encoding='utf-8') as file:
|
||||||
|
file.write(get_string(16))
|
||||||
|
|
||||||
# to test link
|
# to test link
|
||||||
f5, c5 = create_random_file(tmp)
|
fcontent5, _ = create_random_file(tmp)
|
||||||
dst5 = os.path.join(dst, get_string(6))
|
dst5 = os.path.join(dst, get_string(6))
|
||||||
self.addCleanup(clean, dst5)
|
self.addCleanup(clean, dst5)
|
||||||
d5 = Dotfile(get_string(6), dst5,
|
dotfile5 = Dotfile(get_string(6), dst5,
|
||||||
os.path.basename(f5), link=LinkTypes.LINK)
|
os.path.basename(fcontent5), link=LinkTypes.LINK)
|
||||||
|
|
||||||
# create the dotfile directories in dotdrop
|
# create the dotfile directories in dotdrop
|
||||||
dir1 = create_dir(os.path.join(tmp, get_string(6)))
|
dir1 = create_dir(os.path.join(tmp, get_string(6)))
|
||||||
@@ -133,7 +137,7 @@ exec bspwm
|
|||||||
sub2, _ = create_random_file(dir1)
|
sub2, _ = create_random_file(dir1)
|
||||||
self.assertTrue(os.path.exists(sub2))
|
self.assertTrue(os.path.exists(sub2))
|
||||||
# make up the dotfile
|
# make up the dotfile
|
||||||
d6 = Dotfile(get_string(6), dst6, os.path.basename(dir1))
|
dotfile6 = Dotfile(get_string(6), dst6, os.path.basename(dir1))
|
||||||
|
|
||||||
# to test symlink directories
|
# to test symlink directories
|
||||||
dir2 = create_dir(os.path.join(tmp, get_string(6)))
|
dir2 = create_dir(os.path.join(tmp, get_string(6)))
|
||||||
@@ -146,47 +150,52 @@ exec bspwm
|
|||||||
sub4, _ = create_random_file(dir2)
|
sub4, _ = create_random_file(dir2)
|
||||||
self.assertTrue(os.path.exists(sub4))
|
self.assertTrue(os.path.exists(sub4))
|
||||||
# make up the dotfile
|
# make up the dotfile
|
||||||
d7 = Dotfile(get_string(6), dst7,
|
dotfile7 = Dotfile(get_string(6), dst7,
|
||||||
os.path.basename(dir2), link=LinkTypes.LINK)
|
os.path.basename(dir2), link=LinkTypes.LINK)
|
||||||
|
|
||||||
# to test actions
|
# to test actions
|
||||||
value = get_string(12)
|
value = get_string(12)
|
||||||
fact = '/tmp/action'
|
fact = '/tmp/action'
|
||||||
self.addCleanup(clean, fact)
|
self.addCleanup(clean, fact)
|
||||||
act1 = Action('testaction', 'post', 'echo "{}" > {}'.format(value,
|
act1 = Action('testaction', 'post', f'echo "{value}" > {fact}')
|
||||||
fact))
|
fcontent8, _ = create_random_file(tmp)
|
||||||
f8, c8 = create_random_file(tmp)
|
|
||||||
dst8 = os.path.join(dst, get_string(6))
|
dst8 = os.path.join(dst, get_string(6))
|
||||||
d8 = Dotfile(get_string(6), dst8, os.path.basename(f8), actions=[act1])
|
dotfile8 = Dotfile(get_string(6), dst8, os.path.basename(fcontent8),
|
||||||
|
actions=[act1])
|
||||||
|
|
||||||
# to test transformations
|
# to test transformations
|
||||||
trans1 = 'trans1'
|
trans1 = 'trans1'
|
||||||
trans2 = 'trans2'
|
trans2 = 'trans2'
|
||||||
|
# pylint: disable=C0209
|
||||||
cmd = 'cat {0} | sed \'s/%s/%s/g\' > {1}' % (trans1, trans2)
|
cmd = 'cat {0} | sed \'s/%s/%s/g\' > {1}' % (trans1, trans2)
|
||||||
tr = Action('testtrans', 'post', cmd)
|
self.addCleanup(clean, trans2)
|
||||||
f9, c9 = create_random_file(tmp, content=trans1)
|
the_trans = Action('testtrans', 'post', cmd)
|
||||||
|
fcontent9, _ = create_random_file(tmp, content=trans1)
|
||||||
dst9 = os.path.join(dst, get_string(6))
|
dst9 = os.path.join(dst, get_string(6))
|
||||||
d9 = Dotfile(get_string(6), dst9, os.path.basename(f9), trans_r=[tr])
|
dotfile9 = Dotfile(get_string(6), dst9, os.path.basename(fcontent9),
|
||||||
|
trans_r=[the_trans])
|
||||||
|
|
||||||
# to test template
|
# to test template
|
||||||
f10, _ = create_random_file(tmp, content='{{@@ header() @@}}')
|
f10, _ = create_random_file(tmp, content='{{@@ header() @@}}')
|
||||||
dst10 = os.path.join(dst, get_string(6))
|
dst10 = os.path.join(dst, get_string(6))
|
||||||
d10 = Dotfile(get_string(6), dst10, os.path.basename(f10))
|
dotfile10 = Dotfile(get_string(6), dst10, os.path.basename(f10))
|
||||||
|
|
||||||
# generate the config and stuff
|
# generate the config and stuff
|
||||||
profile = get_string(5)
|
profile = get_string(5)
|
||||||
confpath = os.path.join(tmp, self.CONFIG_NAME)
|
confpath = os.path.join(tmp, self.CONFIG_NAME)
|
||||||
dotfiles = [d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, ddot]
|
dotfiles = [dotfile1, dotfile2, dotfile3, dotfile4,
|
||||||
|
dotfile5, dotfile6, dotfile7, dotfile8,
|
||||||
|
dotfile9, dotfile10, ddot]
|
||||||
self.fake_config(confpath, dotfiles,
|
self.fake_config(confpath, dotfiles,
|
||||||
profile, tmp, [act1], [tr])
|
profile, tmp, [act1], [the_trans])
|
||||||
conf = Cfg(confpath, profile, debug=True)
|
conf = Cfg(confpath, profile, debug=True)
|
||||||
self.assertTrue(conf is not None)
|
self.assertTrue(conf is not None)
|
||||||
|
|
||||||
# install them
|
# install them
|
||||||
o = load_options(confpath, profile)
|
opt = load_options(confpath, profile)
|
||||||
o.safe = False
|
opt.safe = False
|
||||||
o.install_showdiff = True
|
opt.install_showdiff = True
|
||||||
cmd_install(o)
|
cmd_install(opt)
|
||||||
|
|
||||||
# now compare the generated files
|
# now compare the generated files
|
||||||
self.assertTrue(os.path.exists(dst1))
|
self.assertTrue(os.path.exists(dst1))
|
||||||
@@ -197,39 +206,47 @@ exec bspwm
|
|||||||
self.assertTrue(os.path.exists(dst7))
|
self.assertTrue(os.path.exists(dst7))
|
||||||
self.assertTrue(os.path.exists(dst8))
|
self.assertTrue(os.path.exists(dst8))
|
||||||
self.assertTrue(os.path.exists(dst10))
|
self.assertTrue(os.path.exists(dst10))
|
||||||
self.assertTrue(os.path.exists(fd))
|
self.assertTrue(os.path.exists(fildfd))
|
||||||
|
|
||||||
# check if 'dst5' is a link whose target is 'f5'
|
# check if 'dst5' is a link whose target is 'f5'
|
||||||
self.assertTrue(os.path.islink(dst5))
|
self.assertTrue(os.path.islink(dst5))
|
||||||
self.assertTrue(os.path.realpath(dst5) == os.path.realpath(f5))
|
self.assertTrue(os.path.realpath(dst5) == os.path.realpath(fcontent5))
|
||||||
|
|
||||||
# check if 'dst7' is a link whose target is 'dir2'
|
# check if 'dst7' is a link whose target is 'dir2'
|
||||||
self.assertTrue(os.path.islink(dst7))
|
self.assertTrue(os.path.islink(dst7))
|
||||||
self.assertTrue(os.path.realpath(dst7) == os.path.realpath(dir2))
|
self.assertTrue(os.path.realpath(dst7) == os.path.realpath(dir2))
|
||||||
|
|
||||||
# make sure backup is there
|
# make sure backup is there
|
||||||
b = dst4 + BACKUP_SUFFIX
|
backupf = dst4 + BACKUP_SUFFIX
|
||||||
self.assertTrue(os.path.exists(b))
|
self.assertTrue(os.path.exists(backupf))
|
||||||
|
|
||||||
self.assertTrue(filecmp.cmp(f1, dst1, shallow=True))
|
self.assertTrue(filecmp.cmp(fcontent1, dst1, shallow=True))
|
||||||
f2content = open(dst2, 'r').read()
|
f2content = ''
|
||||||
|
with open(dst2, 'r', encoding='utf-8') as file:
|
||||||
|
f2content = file.read()
|
||||||
self.assertTrue(f2content == self.RESULT)
|
self.assertTrue(f2content == self.RESULT)
|
||||||
self.assertTrue(filecmp.cmp(f3, dst3, shallow=True))
|
self.assertTrue(filecmp.cmp(fcontent3, dst3, shallow=True))
|
||||||
|
|
||||||
# test action has been executed
|
# test action has been executed
|
||||||
self.assertTrue(os.path.exists(fact))
|
self.assertTrue(os.path.exists(fact))
|
||||||
self.assertTrue(str(act1) != '')
|
self.assertTrue(str(act1) != '')
|
||||||
actcontent = open(fact, 'r').read().rstrip()
|
actcontent = ''
|
||||||
|
with open(fact, 'r', encoding='utf-8') as file:
|
||||||
|
actcontent = file.read().rstrip()
|
||||||
self.assertTrue(actcontent == value)
|
self.assertTrue(actcontent == value)
|
||||||
|
|
||||||
# test transformation has been done
|
# test transformation has been done
|
||||||
self.assertTrue(os.path.exists(dst9))
|
self.assertTrue(os.path.exists(dst9))
|
||||||
transcontent = open(dst9, 'r').read().rstrip()
|
transcontent = ''
|
||||||
|
with open(dst9, 'r', encoding='utf-8') as file:
|
||||||
|
transcontent = file.read().rstrip()
|
||||||
self.assertTrue(transcontent == trans2)
|
self.assertTrue(transcontent == trans2)
|
||||||
|
|
||||||
# test template has been remplaced
|
# test template has been remplaced
|
||||||
self.assertTrue(os.path.exists(dst10))
|
self.assertTrue(os.path.exists(dst10))
|
||||||
tempcontent = open(dst10, 'r').read().rstrip()
|
tempcontent = ''
|
||||||
|
with open(dst10, 'r', encoding='utf-8') as file:
|
||||||
|
tempcontent = file.read().rstrip()
|
||||||
self.assertTrue(tempcontent == header())
|
self.assertTrue(tempcontent == header())
|
||||||
|
|
||||||
def test_install_import_configs(self):
|
def test_install_import_configs(self):
|
||||||
@@ -251,7 +268,7 @@ exec bspwm
|
|||||||
imported_dotfile, _ = create_random_file(os.path.join(tmp, 'imported'))
|
imported_dotfile, _ = create_random_file(os.path.join(tmp, 'imported'))
|
||||||
imported_dotfile = {
|
imported_dotfile = {
|
||||||
'dst': os.path.join(dst, imported_dotfile),
|
'dst': os.path.join(dst, imported_dotfile),
|
||||||
'key': 'f_{}'.format(imported_dotfile),
|
'key': f'f_{imported_dotfile}',
|
||||||
'name': imported_dotfile,
|
'name': imported_dotfile,
|
||||||
'src': os.path.join(tmp, 'imported', imported_dotfile),
|
'src': os.path.join(tmp, 'imported', imported_dotfile),
|
||||||
}
|
}
|
||||||
@@ -259,7 +276,7 @@ exec bspwm
|
|||||||
create_random_file(os.path.join(tmp, 'importing'))
|
create_random_file(os.path.join(tmp, 'importing'))
|
||||||
importing_dotfile = {
|
importing_dotfile = {
|
||||||
'dst': os.path.join(dst, importing_dotfile),
|
'dst': os.path.join(dst, importing_dotfile),
|
||||||
'key': 'f_{}'.format(importing_dotfile),
|
'key': f'f_{importing_dotfile}',
|
||||||
'name': importing_dotfile,
|
'name': importing_dotfile,
|
||||||
'src': os.path.join(tmp, 'imported', importing_dotfile),
|
'src': os.path.join(tmp, 'imported', importing_dotfile),
|
||||||
}
|
}
|
||||||
@@ -323,11 +340,11 @@ exec bspwm
|
|||||||
})
|
})
|
||||||
|
|
||||||
# install them
|
# install them
|
||||||
o = load_options(importing_path, 'host2')
|
opt = load_options(importing_path, 'host2')
|
||||||
o.safe = False
|
opt.safe = False
|
||||||
o.install_showdiff = True
|
opt.install_showdiff = True
|
||||||
o.variables = {}
|
opt.variables = {}
|
||||||
cmd_install(o)
|
cmd_install(opt)
|
||||||
|
|
||||||
# now compare the generated files
|
# now compare the generated files
|
||||||
self.assertTrue(os.path.exists(importing_dotfile['dst']))
|
self.assertTrue(os.path.exists(importing_dotfile['dst']))
|
||||||
@@ -355,8 +372,8 @@ exec bspwm
|
|||||||
|
|
||||||
# Ensure all destination files point to source
|
# Ensure all destination files point to source
|
||||||
for src in srcs:
|
for src in srcs:
|
||||||
dst = os.path.join(dst_dir, src)
|
xyz = os.path.join(dst_dir, src)
|
||||||
self.assertEqual(os.path.realpath(dst), os.path.realpath(src))
|
self.assertEqual(os.path.realpath(xyz), os.path.realpath(src))
|
||||||
|
|
||||||
def test_fails_without_src(self):
|
def test_fails_without_src(self):
|
||||||
"""test fails without src"""
|
"""test fails without src"""
|
||||||
@@ -372,8 +389,8 @@ exec bspwm
|
|||||||
actionexec=None)
|
actionexec=None)
|
||||||
|
|
||||||
self.assertFalse(res)
|
self.assertFalse(res)
|
||||||
e = 'source dotfile does not exist: {}'.format(src)
|
exp = f'source dotfile does not exist: {src}'
|
||||||
self.assertEqual(err, e)
|
self.assertEqual(err, exp)
|
||||||
|
|
||||||
def test_fails_when_src_file(self):
|
def test_fails_when_src_file(self):
|
||||||
"""test fails when src file"""
|
"""test fails when src file"""
|
||||||
@@ -397,8 +414,8 @@ exec bspwm
|
|||||||
|
|
||||||
# ensure nothing performed
|
# ensure nothing performed
|
||||||
self.assertFalse(res)
|
self.assertFalse(res)
|
||||||
e = 'source dotfile is not a directory: {}'.format(src)
|
exp = f'source dotfile is not a directory: {src}'
|
||||||
self.assertEqual(err, e)
|
self.assertEqual(err, exp)
|
||||||
|
|
||||||
def test_creates_dst(self):
|
def test_creates_dst(self):
|
||||||
"""test creates dst"""
|
"""test creates dst"""
|
||||||
@@ -435,7 +452,7 @@ exec bspwm
|
|||||||
|
|
||||||
# Create destination file to be replaced
|
# Create destination file to be replaced
|
||||||
dst = os.path.join(dst_dir, get_string(6))
|
dst = os.path.join(dst_dir, get_string(6))
|
||||||
with open(dst, 'w'):
|
with open(dst, 'w', encoding='utf=8'):
|
||||||
pass
|
pass
|
||||||
self.assertTrue(os.path.isfile(dst))
|
self.assertTrue(os.path.isfile(dst))
|
||||||
|
|
||||||
@@ -457,8 +474,7 @@ exec bspwm
|
|||||||
|
|
||||||
# ensure prompted
|
# ensure prompted
|
||||||
ask.assert_called_with(
|
ask.assert_called_with(
|
||||||
'Remove regular file {} and replace with empty directory?'
|
f'Remove regular file {dst} and replace with empty directory?')
|
||||||
.format(dst))
|
|
||||||
|
|
||||||
def test_runs_templater(self):
|
def test_runs_templater(self):
|
||||||
"""test runs templater"""
|
"""test runs templater"""
|
||||||
@@ -484,15 +500,16 @@ exec bspwm
|
|||||||
linktype=LinkTypes.LINK_CHILDREN, actionexec=None)
|
linktype=LinkTypes.LINK_CHILDREN, actionexec=None)
|
||||||
|
|
||||||
for src in srcs:
|
for src in srcs:
|
||||||
dst = os.path.join(dst_dir, os.path.basename(src))
|
xyz = os.path.join(dst_dir, os.path.basename(src))
|
||||||
|
|
||||||
# ensure dst is link
|
# ensure dst is link
|
||||||
self.assertTrue(os.path.islink(dst))
|
self.assertTrue(os.path.islink(xyz))
|
||||||
# ensure dst not directly linked to src
|
# ensure dst not directly linked to src
|
||||||
self.assertNotEqual(os.path.realpath(dst), src)
|
self.assertNotEqual(os.path.realpath(xyz), src)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
"""entry point"""
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,16 +6,16 @@ basic unittest for jhelpers
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from dotdrop.cfg_aggregator import CfgAggregator
|
|
||||||
from tests.helpers import (clean,
|
from tests.helpers import (clean,
|
||||||
create_random_file, get_string, get_tempdir,
|
create_random_file, get_string, get_tempdir,
|
||||||
load_options)
|
load_options)
|
||||||
|
from dotdrop.cfg_aggregator import CfgAggregator
|
||||||
from dotdrop.dotfile import Dotfile
|
from dotdrop.dotfile import Dotfile
|
||||||
from dotdrop.dotdrop import cmd_install
|
from dotdrop.dotdrop import cmd_install
|
||||||
|
|
||||||
|
|
||||||
class TestJhelpers(unittest.TestCase):
|
class TestJhelpers(unittest.TestCase):
|
||||||
|
"""test case"""
|
||||||
|
|
||||||
CONFIG_NAME = 'config.yaml'
|
CONFIG_NAME = 'config.yaml'
|
||||||
|
|
||||||
@@ -58,19 +58,19 @@ dirname: /tmp/a/b
|
|||||||
|
|
||||||
def fake_config(self, path, dotfile, profile, dotpath):
|
def fake_config(self, path, dotfile, profile, dotpath):
|
||||||
"""Create a fake config file"""
|
"""Create a fake config file"""
|
||||||
with open(path, 'w') as f:
|
with open(path, 'w', encoding='utf-8') as file:
|
||||||
f.write('config:\n')
|
file.write('config:\n')
|
||||||
f.write(' backup: true\n')
|
file.write(' backup: true\n')
|
||||||
f.write(' create: true\n')
|
file.write(' create: true\n')
|
||||||
f.write(' dotpath: {}\n'.format(dotpath))
|
file.write(f' dotpath: {dotpath}\n')
|
||||||
f.write('dotfiles:\n')
|
file.write('dotfiles:\n')
|
||||||
f.write(' {}:\n'.format(dotfile.key))
|
file.write(f' {dotfile.key}:\n')
|
||||||
f.write(' dst: {}\n'.format(dotfile.dst))
|
file.write(f' dst: {dotfile.dst}\n')
|
||||||
f.write(' src: {}\n'.format(dotfile.src))
|
file.write(f' src: {dotfile.src}\n')
|
||||||
f.write('profiles:\n')
|
file.write('profiles:\n')
|
||||||
f.write(' {}:\n'.format(profile))
|
file.write(f' {profile}:\n')
|
||||||
f.write(' dotfiles:\n')
|
file.write(' dotfiles:\n')
|
||||||
f.write(' - {}\n'.format(dotfile.key))
|
file.write(f' - {dotfile.key}\n')
|
||||||
return path
|
return path
|
||||||
|
|
||||||
def test_jhelpers(self):
|
def test_jhelpers(self):
|
||||||
@@ -87,34 +87,37 @@ dirname: /tmp/a/b
|
|||||||
self.addCleanup(clean, dst)
|
self.addCleanup(clean, dst)
|
||||||
|
|
||||||
# create the dotfile in dotdrop
|
# create the dotfile in dotdrop
|
||||||
f1, c1 = create_random_file(tmp)
|
file1, _ = create_random_file(tmp)
|
||||||
with open(f1, 'w') as f:
|
with open(file1, 'w', encoding='utf-8') as file:
|
||||||
f.write(self.TEMPLATE)
|
file.write(self.TEMPLATE)
|
||||||
dst1 = os.path.join(dst, get_string(6))
|
dst1 = os.path.join(dst, get_string(6))
|
||||||
d1 = Dotfile(get_string(5), dst1, os.path.basename(f1))
|
dotfile1 = Dotfile(get_string(5), dst1, os.path.basename(file1))
|
||||||
|
|
||||||
# generate the config and stuff
|
# generate the config and stuff
|
||||||
profile = get_string(5)
|
profile = get_string(5)
|
||||||
confpath = os.path.join(tmp, self.CONFIG_NAME)
|
confpath = os.path.join(tmp, self.CONFIG_NAME)
|
||||||
self.fake_config(confpath, d1, profile, tmp)
|
self.fake_config(confpath, dotfile1, profile, tmp)
|
||||||
conf = CfgAggregator(confpath, profile, debug=True)
|
conf = CfgAggregator(confpath, profile, debug=True)
|
||||||
self.assertTrue(conf is not None)
|
self.assertTrue(conf is not None)
|
||||||
|
|
||||||
# install them
|
# install them
|
||||||
o = load_options(confpath, profile)
|
opt = load_options(confpath, profile)
|
||||||
o.safe = False
|
opt.safe = False
|
||||||
o.install_showdiff = True
|
opt.install_showdiff = True
|
||||||
o.variables = {}
|
opt.variables = {}
|
||||||
o.debug = True
|
opt.debug = True
|
||||||
cmd_install(o)
|
cmd_install(opt)
|
||||||
|
|
||||||
# now compare the generated files
|
# now compare the generated files
|
||||||
self.assertTrue(os.path.exists(dst1))
|
self.assertTrue(os.path.exists(dst1))
|
||||||
f1content = open(dst1, 'r').read()
|
f1content = ''
|
||||||
|
with open(dst1, 'r', encoding='utf-8') as file:
|
||||||
|
f1content = file.read()
|
||||||
self.assertTrue(f1content == self.RESULT)
|
self.assertTrue(f1content == self.RESULT)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
"""entry point"""
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -49,23 +49,23 @@ class TestListings(unittest.TestCase):
|
|||||||
self.addCleanup(clean, dotfilespath)
|
self.addCleanup(clean, dotfilespath)
|
||||||
|
|
||||||
# create the dotfiles to test
|
# create the dotfiles to test
|
||||||
d1, c1 = create_random_file(fold_config)
|
file1, _ = create_random_file(fold_config)
|
||||||
self.assertTrue(os.path.exists(d1))
|
self.assertTrue(os.path.exists(file1))
|
||||||
self.addCleanup(clean, d1)
|
self.addCleanup(clean, file1)
|
||||||
d2, c2 = create_random_file(fold_subcfg)
|
file2, _ = create_random_file(fold_subcfg)
|
||||||
self.assertTrue(os.path.exists(d2))
|
self.assertTrue(os.path.exists(file2))
|
||||||
self.addCleanup(clean, d2)
|
self.addCleanup(clean, file2)
|
||||||
d3, c3 = create_random_file(fold_tmp)
|
file3, _ = create_random_file(fold_tmp)
|
||||||
self.assertTrue(os.path.exists(d3))
|
self.assertTrue(os.path.exists(file3))
|
||||||
self.addCleanup(clean, d3)
|
self.addCleanup(clean, file3)
|
||||||
d4, c4 = create_random_file(fold_tmp, binary=True)
|
file4, _ = create_random_file(fold_tmp, binary=True)
|
||||||
self.assertTrue(os.path.exists(d4))
|
self.assertTrue(os.path.exists(file4))
|
||||||
self.addCleanup(clean, d4)
|
self.addCleanup(clean, file4)
|
||||||
d5 = get_tempdir()
|
file5 = get_tempdir()
|
||||||
self.assertTrue(os.path.exists(d5))
|
self.assertTrue(os.path.exists(file5))
|
||||||
self.addCleanup(clean, d5)
|
self.addCleanup(clean, file5)
|
||||||
d6, _ = create_random_file(d5)
|
file6, _ = create_random_file(file5)
|
||||||
self.assertTrue(os.path.exists(d6))
|
self.assertTrue(os.path.exists(file6))
|
||||||
|
|
||||||
# create the config file
|
# create the config file
|
||||||
profile = get_string(5)
|
profile = get_string(5)
|
||||||
@@ -75,29 +75,30 @@ class TestListings(unittest.TestCase):
|
|||||||
backup=self.CONFIG_BACKUP,
|
backup=self.CONFIG_BACKUP,
|
||||||
create=self.CONFIG_CREATE)
|
create=self.CONFIG_CREATE)
|
||||||
self.assertTrue(os.path.exists(confpath))
|
self.assertTrue(os.path.exists(confpath))
|
||||||
o = load_options(confpath, profile)
|
opt = load_options(confpath, profile)
|
||||||
dfiles = [d1, d2, d3, d4, d5]
|
dfiles = [file1, file2, file3, file4, file5]
|
||||||
|
|
||||||
# import the files
|
# import the files
|
||||||
o.import_path = dfiles
|
opt.import_path = dfiles
|
||||||
cmd_importer(o)
|
cmd_importer(opt)
|
||||||
o = load_options(confpath, profile)
|
opt = load_options(confpath, profile)
|
||||||
|
|
||||||
# files
|
# files
|
||||||
cmd_list_profiles(o)
|
cmd_list_profiles(opt)
|
||||||
|
|
||||||
# list files
|
# list files
|
||||||
o.files_templateonly = False
|
opt.files_templateonly = False
|
||||||
cmd_files(o)
|
cmd_files(opt)
|
||||||
o.files_templateonly = True
|
opt.files_templateonly = True
|
||||||
cmd_files(o)
|
cmd_files(opt)
|
||||||
|
|
||||||
# details
|
# details
|
||||||
o.detail_keys = None
|
opt.detail_keys = None
|
||||||
cmd_detail(o)
|
cmd_detail(opt)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
"""entry point"""
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ from tests.helpers import (clean, create_dir,
|
|||||||
|
|
||||||
|
|
||||||
class TestRemove(unittest.TestCase):
|
class TestRemove(unittest.TestCase):
|
||||||
|
"""test case"""
|
||||||
|
|
||||||
def load_yaml(self, path):
|
def load_yaml(self, path):
|
||||||
"""Load yaml to dict"""
|
"""Load yaml to dict"""
|
||||||
@@ -68,13 +69,13 @@ class TestRemove(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
|
|
||||||
yaml_dump(configdic, confpath)
|
yaml_dump(configdic, confpath)
|
||||||
o = load_options(confpath, 'host1')
|
opt = load_options(confpath, 'host1')
|
||||||
o.remove_path = ['f_test1']
|
opt.remove_path = ['f_test1']
|
||||||
o.remove_iskey = True
|
opt.remove_iskey = True
|
||||||
o.debug = True
|
opt.debug = True
|
||||||
o.safe = False
|
opt.safe = False
|
||||||
# by key
|
# by key
|
||||||
cmd_remove(o)
|
cmd_remove(opt)
|
||||||
|
|
||||||
# ensure file is deleted
|
# ensure file is deleted
|
||||||
self.assertFalse(os.path.exists(df1))
|
self.assertFalse(os.path.exists(df1))
|
||||||
@@ -82,48 +83,49 @@ class TestRemove(unittest.TestCase):
|
|||||||
self.assertTrue(os.path.exists(df3))
|
self.assertTrue(os.path.exists(df3))
|
||||||
|
|
||||||
# load dict
|
# load dict
|
||||||
y = yaml_load(confpath)
|
cont = yaml_load(confpath)
|
||||||
|
|
||||||
# ensure not present
|
# ensure not present
|
||||||
self.assertTrue('f_test1' not in y['dotfiles'])
|
self.assertTrue('f_test1' not in cont['dotfiles'])
|
||||||
self.assertTrue('f_test1' not in y['profiles']['host1']['dotfiles'])
|
self.assertTrue('f_test1' not in cont['profiles']['host1']['dotfiles'])
|
||||||
self.assertTrue('host2' not in y['profiles'])
|
self.assertTrue('host2' not in cont['profiles'])
|
||||||
|
|
||||||
# assert rest is intact
|
# assert rest is intact
|
||||||
self.assertTrue('f_test2' in y['dotfiles'].keys())
|
self.assertTrue('f_test2' in cont['dotfiles'].keys())
|
||||||
self.assertTrue('f_test3' in y['dotfiles'].keys())
|
self.assertTrue('f_test3' in cont['dotfiles'].keys())
|
||||||
self.assertTrue('f_test2' in y['profiles']['host1']['dotfiles'])
|
self.assertTrue('f_test2' in cont['profiles']['host1']['dotfiles'])
|
||||||
self.assertTrue('f_test3' in y['profiles']['host1']['dotfiles'])
|
self.assertTrue('f_test3' in cont['profiles']['host1']['dotfiles'])
|
||||||
self.assertTrue(y['profiles']['host3']['dotfiles'] == ['f_test2'])
|
self.assertTrue(cont['profiles']['host3']['dotfiles'] == ['f_test2'])
|
||||||
|
|
||||||
o = load_options(confpath, 'host1')
|
opt = load_options(confpath, 'host1')
|
||||||
o.remove_path = ['/tmp/some-fake-path']
|
opt.remove_path = ['/tmp/some-fake-path']
|
||||||
o.remove_iskey = False
|
opt.remove_iskey = False
|
||||||
o.debug = True
|
opt.debug = True
|
||||||
o.safe = False
|
opt.safe = False
|
||||||
# by path
|
# by path
|
||||||
cmd_remove(o)
|
cmd_remove(opt)
|
||||||
|
|
||||||
# ensure file is deleted
|
# ensure file is deleted
|
||||||
self.assertTrue(os.path.exists(df2))
|
self.assertTrue(os.path.exists(df2))
|
||||||
self.assertFalse(os.path.exists(df3))
|
self.assertFalse(os.path.exists(df3))
|
||||||
|
|
||||||
# load dict
|
# load dict
|
||||||
y = yaml_load(confpath)
|
cont = yaml_load(confpath)
|
||||||
|
|
||||||
# ensure not present
|
# ensure not present
|
||||||
self.assertTrue('f_test3' not in y['dotfiles'])
|
self.assertTrue('f_test3' not in cont['dotfiles'])
|
||||||
self.assertTrue('f_test3' not in y['profiles']['host1']['dotfiles'])
|
self.assertTrue('f_test3' not in cont['profiles']['host1']['dotfiles'])
|
||||||
|
|
||||||
# assert rest is intact
|
# assert rest is intact
|
||||||
self.assertTrue('host1' in y['profiles'].keys())
|
self.assertTrue('host1' in cont['profiles'].keys())
|
||||||
self.assertFalse('host2' in y['profiles'].keys())
|
self.assertFalse('host2' in cont['profiles'].keys())
|
||||||
self.assertTrue('host3' in y['profiles'].keys())
|
self.assertTrue('host3' in cont['profiles'].keys())
|
||||||
self.assertTrue(y['profiles']['host1']['dotfiles'] == ['f_test2'])
|
self.assertTrue(cont['profiles']['host1']['dotfiles'] == ['f_test2'])
|
||||||
self.assertTrue(y['profiles']['host3']['dotfiles'] == ['f_test2'])
|
self.assertTrue(cont['profiles']['host3']['dotfiles'] == ['f_test2'])
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
"""entry point"""
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -47,13 +47,13 @@ class TestUpdate(unittest.TestCase):
|
|||||||
self.addCleanup(clean, dotfilespath)
|
self.addCleanup(clean, dotfilespath)
|
||||||
|
|
||||||
# create the dotfiles to test
|
# create the dotfiles to test
|
||||||
d1, _ = create_random_file(fold_config)
|
dotfilefile1, _ = create_random_file(fold_config)
|
||||||
self.assertTrue(os.path.exists(d1))
|
self.assertTrue(os.path.exists(dotfilefile1))
|
||||||
self.addCleanup(clean, d1)
|
self.addCleanup(clean, dotfilefile1)
|
||||||
|
|
||||||
d2, _ = create_random_file(fold_config)
|
dotfilefile2, _ = create_random_file(fold_config)
|
||||||
self.assertTrue(os.path.exists(d2))
|
self.assertTrue(os.path.exists(dotfilefile2))
|
||||||
self.addCleanup(clean, d2)
|
self.addCleanup(clean, dotfilefile2)
|
||||||
|
|
||||||
# template
|
# template
|
||||||
d3t, _ = create_random_file(fold_config)
|
d3t, _ = create_random_file(fold_config)
|
||||||
@@ -96,7 +96,7 @@ class TestUpdate(unittest.TestCase):
|
|||||||
self.assertTrue(os.path.exists(confpath))
|
self.assertTrue(os.path.exists(confpath))
|
||||||
opt = load_options(confpath, profile)
|
opt = load_options(confpath, profile)
|
||||||
opt.update_showpatch = True
|
opt.update_showpatch = True
|
||||||
dfiles = [d1, dir1, d2, d3t, dsubstmp]
|
dfiles = [dotfilefile1, dir1, dotfilefile2, d3t, dsubstmp]
|
||||||
|
|
||||||
# import the files
|
# import the files
|
||||||
opt.import_path = dfiles
|
opt.import_path = dfiles
|
||||||
@@ -138,7 +138,7 @@ class TestUpdate(unittest.TestCase):
|
|||||||
self.assertFalse(os.path.exists(gone))
|
self.assertFalse(os.path.exists(gone))
|
||||||
|
|
||||||
# edit the files
|
# edit the files
|
||||||
edit_content(d1, 'newcontent')
|
edit_content(dotfilefile1, 'newcontent')
|
||||||
edit_content(dirf1, 'newcontent')
|
edit_content(dirf1, 'newcontent')
|
||||||
|
|
||||||
# add more file
|
# add more file
|
||||||
@@ -150,12 +150,12 @@ class TestUpdate(unittest.TestCase):
|
|||||||
create_random_file(dpath)
|
create_random_file(dpath)
|
||||||
|
|
||||||
# update it
|
# update it
|
||||||
opt.update_path = [d1, dir1]
|
opt.update_path = [dotfilefile1, dir1]
|
||||||
cmd_update(opt)
|
cmd_update(opt)
|
||||||
|
|
||||||
# test content
|
# test content
|
||||||
newcontent = ''
|
newcontent = ''
|
||||||
with open(d1, 'r', encoding='utf-8') as file:
|
with open(dotfilefile1, 'r', encoding='utf-8') as file:
|
||||||
newcontent = file.read()
|
newcontent = file.read()
|
||||||
self.assertTrue(newcontent == 'newcontent')
|
self.assertTrue(newcontent == 'newcontent')
|
||||||
newcontent = ''
|
newcontent = ''
|
||||||
@@ -163,14 +163,14 @@ class TestUpdate(unittest.TestCase):
|
|||||||
newcontent = file.read()
|
newcontent = file.read()
|
||||||
self.assertTrue(newcontent == 'newcontent')
|
self.assertTrue(newcontent == 'newcontent')
|
||||||
|
|
||||||
edit_content(d2, 'newcontentbykey')
|
edit_content(dotfilefile2, 'newcontentbykey')
|
||||||
|
|
||||||
# update it by key
|
# update it by key
|
||||||
dfiles = opt.dotfiles
|
dfiles = opt.dotfiles
|
||||||
d2key = ''
|
d2key = ''
|
||||||
for dotfile in dfiles:
|
for dotfile in dfiles:
|
||||||
src = os.path.expanduser(dotfile.dst)
|
src = os.path.expanduser(dotfile.dst)
|
||||||
if src == d2:
|
if src == dotfilefile2:
|
||||||
d2key = dotfile.key
|
d2key = dotfile.key
|
||||||
break
|
break
|
||||||
self.assertTrue(d2key != '')
|
self.assertTrue(d2key != '')
|
||||||
@@ -180,7 +180,7 @@ class TestUpdate(unittest.TestCase):
|
|||||||
|
|
||||||
# test content
|
# test content
|
||||||
newcontent = ''
|
newcontent = ''
|
||||||
with open(d2, 'r', encoding='utf-8') as file:
|
with open(dotfilefile2, 'r', encoding='utf-8') as file:
|
||||||
newcontent = file.read()
|
newcontent = file.read()
|
||||||
self.assertTrue(newcontent == 'newcontentbykey')
|
self.assertTrue(newcontent == 'newcontentbykey')
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ from tests.helpers import (SubsetTestCase, _fake_args, clean,
|
|||||||
|
|
||||||
|
|
||||||
class TestConfig(SubsetTestCase):
|
class TestConfig(SubsetTestCase):
|
||||||
|
"""test case"""
|
||||||
|
|
||||||
CONFIG_BACKUP = False
|
CONFIG_BACKUP = False
|
||||||
CONFIG_CREATE = True
|
CONFIG_CREATE = True
|
||||||
@@ -52,6 +53,8 @@ class TestConfig(SubsetTestCase):
|
|||||||
self.assertTrue(conf.dump() != '')
|
self.assertTrue(conf.dump() != '')
|
||||||
|
|
||||||
def test_def_link(self):
|
def test_def_link(self):
|
||||||
|
"""unittest"""
|
||||||
|
# pylint: disable=E1120
|
||||||
self._test_link_import('nolink', LinkTypes.ABSOLUTE, 'absolute')
|
self._test_link_import('nolink', LinkTypes.ABSOLUTE, 'absolute')
|
||||||
self._test_link_import('nolink', LinkTypes.RELATIVE, 'relative')
|
self._test_link_import('nolink', LinkTypes.RELATIVE, 'relative')
|
||||||
self._test_link_import('nolink', LinkTypes.NOLINK, 'nolink')
|
self._test_link_import('nolink', LinkTypes.NOLINK, 'nolink')
|
||||||
@@ -75,7 +78,7 @@ class TestConfig(SubsetTestCase):
|
|||||||
@patch('dotdrop.cfg_yaml.os.path.exists', create=True)
|
@patch('dotdrop.cfg_yaml.os.path.exists', create=True)
|
||||||
def _test_link_import(self, cfgstring, expected,
|
def _test_link_import(self, cfgstring, expected,
|
||||||
cliargs, mock_exists, mock_open):
|
cliargs, mock_exists, mock_open):
|
||||||
data = '''
|
data = f'''
|
||||||
config:
|
config:
|
||||||
backup: true
|
backup: true
|
||||||
create: true
|
create: true
|
||||||
@@ -83,11 +86,11 @@ config:
|
|||||||
banner: true
|
banner: true
|
||||||
longkey: false
|
longkey: false
|
||||||
keepdot: false
|
keepdot: false
|
||||||
link_on_import: {}
|
link_on_import: {cfgstring}
|
||||||
link_dotfile_default: nolink
|
link_dotfile_default: nolink
|
||||||
dotfiles:
|
dotfiles:
|
||||||
profiles:
|
profiles:
|
||||||
'''.format(cfgstring)
|
'''
|
||||||
|
|
||||||
mock_open.side_effect = [
|
mock_open.side_effect = [
|
||||||
unittest.mock.mock_open(read_data=data).return_value,
|
unittest.mock.mock_open(read_data=data).return_value,
|
||||||
@@ -100,14 +103,14 @@ profiles:
|
|||||||
args['--cfg'] = 'mocked'
|
args['--cfg'] = 'mocked'
|
||||||
args['--link'] = cliargs
|
args['--link'] = cliargs
|
||||||
args['--verbose'] = True
|
args['--verbose'] = True
|
||||||
o = Options(args=args)
|
opt = Options(args=args)
|
||||||
|
|
||||||
self.assertTrue(o.import_link == expected)
|
self.assertTrue(opt.import_link == expected)
|
||||||
|
|
||||||
@patch('dotdrop.cfg_yaml.open', create=True)
|
@patch('dotdrop.cfg_yaml.open', create=True)
|
||||||
@patch('dotdrop.cfg_yaml.os.path.exists', create=True)
|
@patch('dotdrop.cfg_yaml.os.path.exists', create=True)
|
||||||
def _test_link_import_fail(self, value, mock_exists, mock_open):
|
def _test_link_import_fail(self, value, mock_exists, mock_open):
|
||||||
data = '''
|
data = f'''
|
||||||
config:
|
config:
|
||||||
backup: true
|
backup: true
|
||||||
create: true
|
create: true
|
||||||
@@ -115,11 +118,11 @@ config:
|
|||||||
banner: true
|
banner: true
|
||||||
longkey: false
|
longkey: false
|
||||||
keepdot: false
|
keepdot: false
|
||||||
link_on_import: {}
|
link_on_import: {value}
|
||||||
link_dotfile_default: nolink
|
link_dotfile_default: nolink
|
||||||
dotfiles:
|
dotfiles:
|
||||||
profiles:
|
profiles:
|
||||||
'''.format(value)
|
'''
|
||||||
|
|
||||||
mock_open.side_effect = [
|
mock_open.side_effect = [
|
||||||
unittest.mock.mock_open(read_data=data).return_value
|
unittest.mock.mock_open(read_data=data).return_value
|
||||||
@@ -132,10 +135,11 @@ profiles:
|
|||||||
args['--verbose'] = True
|
args['--verbose'] = True
|
||||||
|
|
||||||
with self.assertRaises(YamlException):
|
with self.assertRaises(YamlException):
|
||||||
o = Options(args=args)
|
opt = Options(args=args)
|
||||||
print(o.import_link)
|
print(opt.import_link)
|
||||||
|
|
||||||
def test_include(self):
|
def test_include(self):
|
||||||
|
"""unittest"""
|
||||||
tmp = get_tempdir()
|
tmp = get_tempdir()
|
||||||
self.assertTrue(os.path.exists(tmp))
|
self.assertTrue(os.path.exists(tmp))
|
||||||
self.addCleanup(clean, tmp)
|
self.addCleanup(clean, tmp)
|
||||||
@@ -358,32 +362,32 @@ profiles:
|
|||||||
self.assertIsNotNone(imported_cfg)
|
self.assertIsNotNone(imported_cfg)
|
||||||
|
|
||||||
# test profiles
|
# test profiles
|
||||||
self.assertIsSubset(imported_cfg.profiles,
|
self.assert_is_subset(imported_cfg.profiles,
|
||||||
importing_cfg.profiles)
|
importing_cfg.profiles)
|
||||||
|
|
||||||
# test dotfiles
|
# test dotfiles
|
||||||
self.assertIsSubset(imported_cfg.dotfiles, importing_cfg.dotfiles)
|
self.assert_is_subset(imported_cfg.dotfiles, importing_cfg.dotfiles)
|
||||||
|
|
||||||
# test actions
|
# test actions
|
||||||
pre_ed = post_ed = pre_ing = post_ing = {}
|
pre_ed = post_ed = pre_ing = post_ing = {}
|
||||||
for k, v in imported_cfg.actions.items():
|
for k, val in imported_cfg.actions.items():
|
||||||
kind, _ = v
|
kind, _ = val
|
||||||
if kind == 'pre':
|
if kind == 'pre':
|
||||||
pre_ed[k] = v
|
pre_ed[k] = val
|
||||||
elif kind == 'post':
|
elif kind == 'post':
|
||||||
post_ed[k] = v
|
post_ed[k] = val
|
||||||
for k, v in importing_cfg.actions.items():
|
for k, val in importing_cfg.actions.items():
|
||||||
kind, _ = v
|
kind, _ = val
|
||||||
if kind == 'pre':
|
if kind == 'pre':
|
||||||
pre_ing[k] = v
|
pre_ing[k] = val
|
||||||
elif kind == 'post':
|
elif kind == 'post':
|
||||||
post_ing[k] = v
|
post_ing[k] = val
|
||||||
self.assertIsSubset(pre_ed, pre_ing)
|
self.assert_is_subset(pre_ed, pre_ing)
|
||||||
self.assertIsSubset(post_ed, post_ing)
|
self.assert_is_subset(post_ed, post_ing)
|
||||||
|
|
||||||
# test transactions
|
# test transactions
|
||||||
self.assertIsSubset(imported_cfg.trans_r, importing_cfg.trans_r)
|
self.assert_is_subset(imported_cfg.trans_r, importing_cfg.trans_r)
|
||||||
self.assertIsSubset(imported_cfg.trans_w, importing_cfg.trans_w)
|
self.assert_is_subset(imported_cfg.trans_w, importing_cfg.trans_w)
|
||||||
|
|
||||||
# test variables
|
# test variables
|
||||||
imported_vars = {
|
imported_vars = {
|
||||||
@@ -396,10 +400,10 @@ profiles:
|
|||||||
for k, v in importing_cfg.variables.items()
|
for k, v in importing_cfg.variables.items()
|
||||||
if not k.startswith('_')
|
if not k.startswith('_')
|
||||||
}
|
}
|
||||||
self.assertIsSubset(imported_vars, importing_vars)
|
self.assert_is_subset(imported_vars, importing_vars)
|
||||||
|
|
||||||
# test prodots
|
# test prodots
|
||||||
self.assertIsSubset(imported_cfg.profiles, importing_cfg.profiles)
|
self.assert_is_subset(imported_cfg.profiles, importing_cfg.profiles)
|
||||||
|
|
||||||
def test_import_configs_override(self):
|
def test_import_configs_override(self):
|
||||||
"""Test import_configs when some config keys overlap."""
|
"""Test import_configs when some config keys overlap."""
|
||||||
@@ -563,8 +567,8 @@ profiles:
|
|||||||
self.assertIsNotNone(imported_cfg)
|
self.assertIsNotNone(imported_cfg)
|
||||||
|
|
||||||
# test profiles
|
# test profiles
|
||||||
self.assertIsSubset(imported_cfg.profiles,
|
self.assert_is_subset(imported_cfg.profiles,
|
||||||
importing_cfg.profiles)
|
importing_cfg.profiles)
|
||||||
|
|
||||||
# test dotfiles
|
# test dotfiles
|
||||||
self.assertEqual(importing_cfg.dotfiles['f_vimrc'],
|
self.assertEqual(importing_cfg.dotfiles['f_vimrc'],
|
||||||
@@ -609,6 +613,7 @@ profiles:
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
"""entry point"""
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user