1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-09 18:44:16 +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

@@ -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))