1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-04 15:39:43 +00:00

update tests and improve

This commit is contained in:
deadc0de6
2018-09-25 08:51:56 +02:00
parent 8d60e0ca5c
commit 3819511e72
5 changed files with 36 additions and 24 deletions

View File

@@ -55,6 +55,15 @@ def create_random_file(directory, content=None, binary=False):
return path, content
def edit_content(path, newcontent, binary=False):
'''edit file content'''
mode = 'w'
if binary:
mode = 'wb'
with open(path, mode) as f:
f.write(newcontent)
def create_dir(path):
'''Create a directory'''
if not os.path.exists(path):

View File

@@ -41,7 +41,8 @@ class TestCompare(unittest.TestCase):
if not ret:
results[path] = False
continue
diff = comp.compare(insttmp, dotfile.dst)
diff = comp.compare(insttmp, dotfile.dst,
ignore=['whatever', 'whatelse'])
print('XXXX diff for {} and {}:\n{}'.format(dotfile.src,
dotfile.dst,
diff))
@@ -49,13 +50,6 @@ class TestCompare(unittest.TestCase):
results[path] = diff == ''
return results
def edit_content(self, path, newcontent, binary=False):
mode = 'w'
if binary:
mode = 'wb'
with open(path, mode) as f:
f.write(newcontent)
def test_compare(self):
'''Test the compare function'''
# setup some directories
@@ -118,13 +112,13 @@ class TestCompare(unittest.TestCase):
self.assertTrue(results == expected)
# modify file
self.edit_content(d1, get_string(20))
edit_content(d1, get_string(20))
expected = {d1: False, d2: True, d3: True, d4: True, d5: True}
results = self.compare(opts, conf, tmp, len(dfiles))
self.assertTrue(results == expected)
# modify binary file
self.edit_content(d4, bytes(get_string(20), 'ascii'), binary=True)
edit_content(d4, bytes(get_string(20), 'ascii'), binary=True)
expected = {d1: False, d2: True, d3: True, d4: False, d5: True}
results = self.compare(opts, conf, tmp, len(dfiles))
self.assertTrue(results == expected)
@@ -137,8 +131,8 @@ class TestCompare(unittest.TestCase):
self.assertTrue(results == expected)
# modify all files
self.edit_content(d2, get_string(20))
self.edit_content(d3, get_string(21))
edit_content(d2, get_string(20))
edit_content(d3, get_string(21))
expected = {d1: False, d2: False, d3: False, d4: False, d5: False}
results = self.compare(opts, conf, tmp, len(dfiles))
self.assertTrue(results == expected)

View File

@@ -199,8 +199,7 @@ class TestImport(unittest.TestCase):
# fake test update
editcontent = 'edited'
with open(dotfile1, 'w') as f:
f.write('edited')
edit_content(dotfile1, editcontent)
opts['safe'] = False
update(opts, conf, [dotfile1])
c2 = open(indt1, 'r').read()

View File

@@ -156,10 +156,16 @@ exec bspwm
dst9 = os.path.join(dst, get_string(6))
d9 = Dotfile(get_string(6), dst9, os.path.basename(f9), trans=[tr])
# to test template
f10, _ = create_random_file(tmp, content='{{@@ profile @@}}')
dst10 = os.path.join(dst, get_string(6))
d10 = Dotfile(get_string(6), dst10, os.path.basename(f10))
# generate the config and stuff
profile = get_string(5)
confpath = os.path.join(tmp, self.CONFIG_NAME)
self.fake_config(confpath, [d1, d2, d3, d4, d5, d6, d7, d8, d9, ddot],
dotfiles = [d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, ddot]
self.fake_config(confpath, dotfiles,
profile, tmp, [act1], [tr])
conf = Cfg(confpath)
self.assertTrue(conf is not None)
@@ -179,6 +185,7 @@ exec bspwm
self.assertTrue(os.path.exists(dst6))
self.assertTrue(os.path.exists(dst7))
self.assertTrue(os.path.exists(dst8))
self.assertTrue(os.path.exists(dst10))
self.assertTrue(os.path.exists(fd))
# check if 'dst5' is a link whose target is 'f5'
@@ -209,6 +216,11 @@ exec bspwm
transcontent = open(dst9, 'r').read().rstrip()
self.assertTrue(transcontent == trans2)
# test template has been remplaced
self.assertTrue(os.path.exists(dst10))
tempcontent = open(dst10, 'r').read().rstrip()
self.assertTrue(tempcontent == profile)
def main():
unittest.main()

View File

@@ -24,13 +24,6 @@ class TestUpdate(unittest.TestCase):
CONFIG_DOTPATH = 'dotfiles'
CONFIG_NAME = 'config.yaml'
def edit_content(self, path, newcontent, binary=False):
mode = 'w'
if binary:
mode = 'wb'
with open(path, mode) as f:
f.write(newcontent)
def test_update(self):
'''Test the update function'''
# setup some directories
@@ -79,12 +72,17 @@ class TestUpdate(unittest.TestCase):
conf, opts = load_config(confpath, profile)
# edit the files
self.edit_content(d1, 'newcontent')
self.edit_content(dirf1, 'newcontent')
edit_content(d1, 'newcontent')
edit_content(dirf1, 'newcontent')
# add more file
dirf2, _ = create_random_file(dpath)
# add more dirs
dpath = os.path.join(dpath, get_string(5))
create_dir(dpath)
create_random_file(dpath)
# update it
opts['safe'] = False
opts['debug'] = True