1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-04 18:34:48 +00:00

merge defaultlink

This commit is contained in:
deadc0de6
2019-04-08 07:51:36 +02:00
22 changed files with 1295 additions and 84 deletions

View File

@@ -89,7 +89,7 @@ def _fake_args():
args['--force'] = False
args['--nodiff'] = False
args['--showdiff'] = True
args['--inv-link'] = False
args['--link'] = 'nolink'
args['--template'] = False
args['--temp'] = False
args['<key>'] = []
@@ -118,14 +118,13 @@ def load_options(confpath, profile):
args['--cfg'] = confpath
args['--profile'] = profile
# and get the options
# TODO need to patch options
o = Options(args=args)
o.profile = profile
o.dry = False
o.profile = profile
o.safe = True
o.install_diff = True
o.link = LinkTypes.NOLINK.value
o.import_link = LinkTypes.NOLINK
o.install_showdiff = True
o.debug = True
if ENV_NODEBUG in os.environ:

View File

@@ -6,11 +6,15 @@ basic unittest for the config parser
import unittest
from unittest.mock import patch
import os
import yaml
from dotdrop.config import Cfg
from tests.helpers import get_tempdir, clean, create_fake_config
from dotdrop.options import Options
from dotdrop.linktypes import LinkTypes
from tests.helpers import get_tempdir, clean, \
create_fake_config, _fake_args
class TestConfig(unittest.TestCase):
@@ -45,6 +49,84 @@ class TestConfig(unittest.TestCase):
self.assertTrue(conf._is_valid())
self.assertTrue(conf.dump() != '')
def test_def_link(self):
self._test_link_import('nolink', LinkTypes.LINK, 'link')
self._test_link_import('nolink', LinkTypes.NOLINK, 'nolink')
self._test_link_import('nolink',
LinkTypes.LINK_CHILDREN,
'link_children')
self._test_link_import('link', LinkTypes.LINK, 'link')
self._test_link_import('link', LinkTypes.NOLINK, 'nolink')
self._test_link_import('link',
LinkTypes.LINK_CHILDREN,
'link_children')
self._test_link_import('link_children', LinkTypes.LINK, 'link')
self._test_link_import('link_children', LinkTypes.NOLINK, 'nolink')
self._test_link_import('link_children', LinkTypes.LINK_CHILDREN,
'link_children')
self._test_link_import_fail('whatever')
@patch('dotdrop.config.open', create=True)
@patch('dotdrop.config.os.path.exists', create=True)
def _test_link_import(self, cfgstring, expected,
cliargs, mock_exists, mock_open):
data = '''
config:
backup: true
create: true
dotpath: dotfiles
banner: true
longkey: false
keepdot: false
link_on_import: {}
link_dotfile_default: nolink
dotfiles:
profiles:
'''.format(cfgstring)
mock_open.side_effect = [
unittest.mock.mock_open(read_data=data).return_value
]
mock_exists.return_value = True
args = _fake_args()
args['--profile'] = 'p1'
args['--cfg'] = 'mocked'
args['--link'] = cliargs
o = Options(args=args)
self.assertTrue(o.import_link == expected)
@patch('dotdrop.config.open', create=True)
@patch('dotdrop.config.os.path.exists', create=True)
def _test_link_import_fail(self, value, mock_exists, mock_open):
data = '''
config:
backup: true
create: true
dotpath: dotfiles
banner: true
longkey: false
keepdot: false
link_on_import: {}
link_dotfile_default: nolink
dotfiles:
profiles:
'''.format(value)
mock_open.side_effect = [
unittest.mock.mock_open(read_data=data).return_value
]
mock_exists.return_value = True
args = _fake_args()
args['--profile'] = 'p1'
args['--cfg'] = 'mocked'
with self.assertRaisesRegex(ValueError, 'config is not valid'):
o = Options(args=args)
print(o.import_link)
def test_include(self):
tmp = get_tempdir()
self.assertTrue(os.path.exists(tmp))

View File

@@ -112,11 +112,11 @@ class TestImport(unittest.TestCase):
o.import_path = dfiles
cmd_importer(o)
# import symlink
o.link = LinkTypes.PARENTS
o.import_link = LinkTypes.LINK
sfiles = [dotfile6, dotfile7]
o.import_path = sfiles
cmd_importer(o)
o.link = LinkTypes.NOLINK
o.import_link = LinkTypes.NOLINK
# reload the config
o = load_options(confpath, profile)
@@ -191,12 +191,6 @@ class TestImport(unittest.TestCase):
sub4)
self.assertTrue(os.path.exists(s4))
# test symlink on filesystem
self.assertTrue(os.path.islink(dotfile6))
self.assertTrue(os.path.realpath(dotfile6) == indt6)
self.assertTrue(os.path.islink(dotfile7))
self.assertTrue(os.path.realpath(dotfile7) == indt7)
cmd_list_profiles(o)
cmd_list_files(o)

View File

@@ -17,8 +17,8 @@ from dotdrop.installer import Installer
from dotdrop.action import Action
from dotdrop.dotdrop import cmd_install
from dotdrop.options import BACKUP_SUFFIX
from dotdrop.linktypes import LinkTypes
from dotdrop.utils import header
from dotdrop.linktypes import LinkTypes
class TestInstall(unittest.TestCase):
@@ -57,12 +57,7 @@ exec bspwm
f.write(' {}:\n'.format(d.key))
f.write(' dst: {}\n'.format(d.dst))
f.write(' src: {}\n'.format(d.src))
if d.link == LinkTypes.CHILDREN:
f.write(' link_children: {}\n'
.format(str(d.link == LinkTypes.CHILDREN).lower()))
else:
f.write(' link: {}\n'
.format(str(d.link == LinkTypes.PARENTS).lower()))
f.write(' link: {}\n'.format(d.link.name.lower()))
if len(d.actions) > 0:
f.write(' actions:\n')
for action in d.actions:
@@ -122,7 +117,8 @@ exec bspwm
f5, c5 = create_random_file(tmp)
dst5 = os.path.join(dst, get_string(6))
self.addCleanup(clean, dst5)
d5 = Dotfile(get_string(6), dst5, os.path.basename(f5), link=True)
d5 = Dotfile(get_string(6), dst5,
os.path.basename(f5), link=LinkTypes.LINK)
# create the dotfile directories in dotdrop
dir1 = create_dir(os.path.join(tmp, get_string(6)))
@@ -148,7 +144,8 @@ exec bspwm
sub4, _ = create_random_file(dir2)
self.assertTrue(os.path.exists(sub4))
# make up the dotfile
d7 = Dotfile(get_string(6), dst7, os.path.basename(dir2), link=True)
d7 = Dotfile(get_string(6), dst7,
os.path.basename(dir2), link=LinkTypes.LINK)
# to test actions
value = get_string(12)