mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-04 20:54:51 +00:00
add more tests
This commit is contained in:
@@ -93,6 +93,13 @@ exec bspwm
|
||||
dst3 = os.path.join(dst, get_string(6))
|
||||
d3 = Dotfile(get_string(5), dst3, os.path.basename(f3))
|
||||
|
||||
# create a directory dotfile
|
||||
dir1 = os.path.join(tmp, 'somedir')
|
||||
create_dir(dir1)
|
||||
fd, _ = create_random_file(dir1)
|
||||
dstd = os.path.join(dst, get_string(6))
|
||||
ddot = Dotfile(get_string(5), dstd, os.path.basename(dir1))
|
||||
|
||||
# to test backup
|
||||
f4, c4 = create_random_file(tmp)
|
||||
dst4 = os.path.join(dst, get_string(6))
|
||||
@@ -152,7 +159,7 @@ exec bspwm
|
||||
# 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],
|
||||
self.fake_config(confpath, [d1, d2, d3, d4, d5, d6, d7, d8, d9, ddot],
|
||||
profile, tmp, [act1], [tr])
|
||||
conf = Cfg(confpath)
|
||||
self.assertTrue(conf is not None)
|
||||
@@ -172,6 +179,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(fd))
|
||||
|
||||
# check if 'dst5' is a link whose target is 'f5'
|
||||
self.assertTrue(os.path.islink(dst5))
|
||||
|
||||
92
tests/test_update.py
Normal file
92
tests/test_update.py
Normal file
@@ -0,0 +1,92 @@
|
||||
"""
|
||||
author: deadc0de6 (https://github.com/deadc0de6)
|
||||
Copyright (c) 2017, deadc0de6
|
||||
basic unittest for the update function
|
||||
"""
|
||||
|
||||
|
||||
import unittest
|
||||
import os
|
||||
import yaml
|
||||
|
||||
from dotdrop.config import Cfg
|
||||
from dotdrop.dotdrop import importer
|
||||
from dotdrop.dotdrop import update
|
||||
from dotdrop.dotfile import Dotfile
|
||||
|
||||
from tests.helpers import *
|
||||
|
||||
|
||||
class TestUpdate(unittest.TestCase):
|
||||
|
||||
CONFIG_BACKUP = False
|
||||
CONFIG_CREATE = True
|
||||
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
|
||||
fold_config = os.path.join(os.path.expanduser('~'), '.config')
|
||||
create_dir(fold_config)
|
||||
fold_subcfg = os.path.join(os.path.expanduser('~'), '.config',
|
||||
get_string(5))
|
||||
create_dir(fold_subcfg)
|
||||
self.addCleanup(clean, fold_subcfg)
|
||||
fold_tmp = get_tempdir()
|
||||
create_dir(fold_tmp)
|
||||
self.addCleanup(clean, fold_tmp)
|
||||
|
||||
# create the directories
|
||||
tmp = get_tempdir()
|
||||
self.assertTrue(os.path.exists(tmp))
|
||||
self.addCleanup(clean, tmp)
|
||||
|
||||
dotfilespath = get_tempdir()
|
||||
self.assertTrue(os.path.exists(dotfilespath))
|
||||
self.addCleanup(clean, dotfilespath)
|
||||
|
||||
# create the dotfiles to test
|
||||
d1, c1 = create_random_file(fold_config)
|
||||
self.assertTrue(os.path.exists(d1))
|
||||
self.addCleanup(clean, d1)
|
||||
|
||||
# create the config file
|
||||
profile = get_string(5)
|
||||
confpath = create_fake_config(dotfilespath,
|
||||
configname=self.CONFIG_NAME,
|
||||
dotpath=self.CONFIG_DOTPATH,
|
||||
backup=self.CONFIG_BACKUP,
|
||||
create=self.CONFIG_CREATE)
|
||||
self.assertTrue(os.path.exists(confpath))
|
||||
conf, opts = load_config(confpath, profile)
|
||||
dfiles = [d1]
|
||||
|
||||
# import the files
|
||||
importer(opts, conf, dfiles)
|
||||
conf, opts = load_config(confpath, profile)
|
||||
|
||||
# edit the file
|
||||
self.edit_content(d1, 'newcontent')
|
||||
|
||||
# update it
|
||||
update(opts, conf, d1)
|
||||
|
||||
# test content
|
||||
newcontent = open(d1, 'r').read()
|
||||
self.assertTrue(newcontent == 'newcontent')
|
||||
|
||||
|
||||
def main():
|
||||
unittest.main()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user