1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-04 17:59:46 +00:00

refactor link default config variables

This commit is contained in:
deadc0de6
2019-03-29 14:43:08 +01:00
parent 018be3be40
commit 3e58857d43
9 changed files with 362 additions and 62 deletions

View File

@@ -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,76 @@ class TestConfig(unittest.TestCase):
self.assertTrue(conf._is_valid())
self.assertTrue(conf.dump() != '')
def test_def_link(self):
self._test_link_import('nolink', LinkTypes.NOLINK, False)
self._test_link_import('link', LinkTypes.PARENT, False)
self._test_link_import('nolink', LinkTypes.PARENT, True)
self._test_link_import('link', LinkTypes.NOLINK, True)
self._test_link_import_fail('whatever')
self._test_link_import_fail('link_children')
@patch('dotdrop.config.open', create=True)
@patch('dotdrop.config.os.path.exists', create=True)
def _test_link_import(self, cfgstring, expected,
invert, mock_exists, mock_open):
data = '''
config:
backup: true
create: true
dotpath: dotfiles
banner: true
longkey: false
keepdot: false
link_import_default: {}
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'
if invert:
args['--inv-link'] = True
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_import_default: {}
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.PARENT
o.import_link = LinkTypes.PARENT
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)