1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-11 00:54:16 +00:00

adding tests for backup

This commit is contained in:
deadc0de6
2017-03-16 13:20:43 +01:00
parent 59cbce5c98
commit 6b59e22d49

View File

@@ -10,6 +10,7 @@ import filecmp
from tests.helpers import * from tests.helpers import *
from dotdrop.dotfile import Dotfile from dotdrop.dotfile import Dotfile
from dotdrop.dotdrop import install from dotdrop.dotdrop import install
from dotdrop.installer import Installer
class TestInstall(unittest.TestCase): class TestInstall(unittest.TestCase):
@@ -33,7 +34,7 @@ exec bspwm
'''Create a fake config file''' '''Create a fake config file'''
with open(path, 'w') as f: with open(path, 'w') as f:
f.write('config:\n') f.write('config:\n')
f.write(' backup: false\n') f.write(' backup: true\n')
f.write(' create: true\n') f.write(' create: true\n')
f.write(' dotpath: %s\n' % (dotpath)) f.write(' dotpath: %s\n' % (dotpath))
f.write('dotfiles:\n') f.write('dotfiles:\n')
@@ -70,15 +71,23 @@ exec bspwm
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)) d3 = Dotfile(get_string(5), dst3, os.path.basename(f3))
# to test backup
f4, c4 = create_random_file(tmp)
dst4 = os.path.join(dst, get_string(6))
d4 = Dotfile(get_string(6), dst4, os.path.basename(f4))
with open(dst4, 'w') as f:
f.write(get_string(16))
# 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], profile, tmp) self.fake_config(confpath, [d1, d2, d3, d4], profile, tmp)
conf = Cfg(confpath, tmp) conf = Cfg(confpath, tmp)
self.assertTrue(conf is not None) self.assertTrue(conf is not None)
# install them # install them
conf, opts = load_config(confpath, tmp, profile) conf, opts = load_config(confpath, tmp, profile)
opts['safe'] = False
install(opts, conf) install(opts, conf)
# now compare the generated files # now compare the generated files
@@ -86,6 +95,10 @@ exec bspwm
self.assertTrue(os.path.exists(dst2)) self.assertTrue(os.path.exists(dst2))
self.assertTrue(os.path.exists(dst3)) self.assertTrue(os.path.exists(dst3))
# make sure backup is there
b = dst4 + Installer.BACKUP_SUFFIX
self.assertTrue(os.path.exists(b))
self.assertTrue(filecmp.cmp(f1, dst1, shallow=True)) self.assertTrue(filecmp.cmp(f1, dst1, shallow=True))
f2content = open(dst2, 'r').read() f2content = open(dst2, 'r').read()
self.assertTrue(f2content == self.RESULT) self.assertTrue(f2content == self.RESULT)