mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-14 18:12:26 +00:00
update tests and improve
This commit is contained in:
@@ -55,6 +55,15 @@ def create_random_file(directory, content=None, binary=False):
|
|||||||
return path, content
|
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):
|
def create_dir(path):
|
||||||
'''Create a directory'''
|
'''Create a directory'''
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
|
|||||||
@@ -41,7 +41,8 @@ class TestCompare(unittest.TestCase):
|
|||||||
if not ret:
|
if not ret:
|
||||||
results[path] = False
|
results[path] = False
|
||||||
continue
|
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,
|
print('XXXX diff for {} and {}:\n{}'.format(dotfile.src,
|
||||||
dotfile.dst,
|
dotfile.dst,
|
||||||
diff))
|
diff))
|
||||||
@@ -49,13 +50,6 @@ class TestCompare(unittest.TestCase):
|
|||||||
results[path] = diff == ''
|
results[path] = diff == ''
|
||||||
return results
|
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):
|
def test_compare(self):
|
||||||
'''Test the compare function'''
|
'''Test the compare function'''
|
||||||
# setup some directories
|
# setup some directories
|
||||||
@@ -118,13 +112,13 @@ class TestCompare(unittest.TestCase):
|
|||||||
self.assertTrue(results == expected)
|
self.assertTrue(results == expected)
|
||||||
|
|
||||||
# modify file
|
# 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}
|
expected = {d1: False, d2: True, d3: True, d4: True, d5: True}
|
||||||
results = self.compare(opts, conf, tmp, len(dfiles))
|
results = self.compare(opts, conf, tmp, len(dfiles))
|
||||||
self.assertTrue(results == expected)
|
self.assertTrue(results == expected)
|
||||||
|
|
||||||
# modify binary file
|
# 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}
|
expected = {d1: False, d2: True, d3: True, d4: False, d5: True}
|
||||||
results = self.compare(opts, conf, tmp, len(dfiles))
|
results = self.compare(opts, conf, tmp, len(dfiles))
|
||||||
self.assertTrue(results == expected)
|
self.assertTrue(results == expected)
|
||||||
@@ -137,8 +131,8 @@ class TestCompare(unittest.TestCase):
|
|||||||
self.assertTrue(results == expected)
|
self.assertTrue(results == expected)
|
||||||
|
|
||||||
# modify all files
|
# modify all files
|
||||||
self.edit_content(d2, get_string(20))
|
edit_content(d2, get_string(20))
|
||||||
self.edit_content(d3, get_string(21))
|
edit_content(d3, get_string(21))
|
||||||
expected = {d1: False, d2: False, d3: False, d4: False, d5: False}
|
expected = {d1: False, d2: False, d3: False, d4: False, d5: False}
|
||||||
results = self.compare(opts, conf, tmp, len(dfiles))
|
results = self.compare(opts, conf, tmp, len(dfiles))
|
||||||
self.assertTrue(results == expected)
|
self.assertTrue(results == expected)
|
||||||
|
|||||||
@@ -199,8 +199,7 @@ class TestImport(unittest.TestCase):
|
|||||||
|
|
||||||
# fake test update
|
# fake test update
|
||||||
editcontent = 'edited'
|
editcontent = 'edited'
|
||||||
with open(dotfile1, 'w') as f:
|
edit_content(dotfile1, editcontent)
|
||||||
f.write('edited')
|
|
||||||
opts['safe'] = False
|
opts['safe'] = False
|
||||||
update(opts, conf, [dotfile1])
|
update(opts, conf, [dotfile1])
|
||||||
c2 = open(indt1, 'r').read()
|
c2 = open(indt1, 'r').read()
|
||||||
|
|||||||
@@ -156,10 +156,16 @@ exec bspwm
|
|||||||
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=[tr])
|
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
|
# 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, 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])
|
profile, tmp, [act1], [tr])
|
||||||
conf = Cfg(confpath)
|
conf = Cfg(confpath)
|
||||||
self.assertTrue(conf is not None)
|
self.assertTrue(conf is not None)
|
||||||
@@ -179,6 +185,7 @@ exec bspwm
|
|||||||
self.assertTrue(os.path.exists(dst6))
|
self.assertTrue(os.path.exists(dst6))
|
||||||
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(fd))
|
self.assertTrue(os.path.exists(fd))
|
||||||
|
|
||||||
# check if 'dst5' is a link whose target is 'f5'
|
# check if 'dst5' is a link whose target is 'f5'
|
||||||
@@ -209,6 +216,11 @@ exec bspwm
|
|||||||
transcontent = open(dst9, 'r').read().rstrip()
|
transcontent = open(dst9, 'r').read().rstrip()
|
||||||
self.assertTrue(transcontent == trans2)
|
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():
|
def main():
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
@@ -24,13 +24,6 @@ class TestUpdate(unittest.TestCase):
|
|||||||
CONFIG_DOTPATH = 'dotfiles'
|
CONFIG_DOTPATH = 'dotfiles'
|
||||||
CONFIG_NAME = 'config.yaml'
|
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):
|
def test_update(self):
|
||||||
'''Test the update function'''
|
'''Test the update function'''
|
||||||
# setup some directories
|
# setup some directories
|
||||||
@@ -79,12 +72,17 @@ class TestUpdate(unittest.TestCase):
|
|||||||
conf, opts = load_config(confpath, profile)
|
conf, opts = load_config(confpath, profile)
|
||||||
|
|
||||||
# edit the files
|
# edit the files
|
||||||
self.edit_content(d1, 'newcontent')
|
edit_content(d1, 'newcontent')
|
||||||
self.edit_content(dirf1, 'newcontent')
|
edit_content(dirf1, 'newcontent')
|
||||||
|
|
||||||
# add more file
|
# add more file
|
||||||
dirf2, _ = create_random_file(dpath)
|
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
|
# update it
|
||||||
opts['safe'] = False
|
opts['safe'] = False
|
||||||
opts['debug'] = True
|
opts['debug'] = True
|
||||||
|
|||||||
Reference in New Issue
Block a user