1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-05 05:39:43 +00:00

more tests

This commit is contained in:
deadc0de6
2023-02-05 21:49:49 +01:00
committed by deadc0de
parent fc2261c860
commit 6404c277ef
3 changed files with 102 additions and 15 deletions

View File

@@ -117,7 +117,7 @@ def create_dir(path):
def _fake_args():
args = {}
args['--verbose'] = False
args['--verbose'] = True
args['--no-banner'] = False
args['--dry'] = False
args['--force'] = False

View File

@@ -12,6 +12,7 @@ import os
import unittest
from unittest.mock import patch
from dotdrop.options import Options, Logger
from dotdrop.exceptions import YamlException
class FakeOptions(Options):
@@ -101,8 +102,6 @@ class TestOptions(unittest.TestCase):
home = os.path.expanduser('~/.config')
expected = f'{home}/dotdrop/config.yaml'
mock_exists.side_effect = side_effect(valid=expected)
log = Logger(debug=True)
log.dbg(f'expected: {expected}')
args = get_args({'--cfg': ''})
os.environ['XDG_CONFIG_HOME'] = home
fake = FakeOptions(args)
@@ -115,52 +114,121 @@ class TestOptions(unittest.TestCase):
home = os.path.expanduser('~/.config')
expected = f'{home}/dotdrop/config.toml'
mock_exists.side_effect = side_effect(valid=expected)
log = Logger(debug=True)
log.dbg(f'expected: {expected}')
args = get_args({'--cfg': ''})
os.environ['XDG_CONFIG_HOME'] = home
fake = FakeOptions(args)
self.assertEqual(fake._get_config_path(), expected)
@patch('os.path.exists')
def test_get_path_fs_yaml(self, mock_exists):
def test_get_path_fs_xdg_yaml(self, mock_exists):
"""from fs yaml"""
clean_setup()
home = os.path.expanduser('~/.config')
expected = f'{home}/dotdrop/config.toml'
expected = f'{home}/dotdrop/config.yaml'
mock_exists.side_effect = side_effect(valid=expected)
log = Logger(debug=True)
log.dbg(f'expected: {expected}')
args = get_args({'--cfg': ''})
fake = FakeOptions(args)
self.assertEqual(fake._get_config_path(), expected)
@patch('os.path.exists')
def test_get_path_fs_xdg(self, mock_exists):
def test_get_path_fs_xdg_etc_yaml(self, mock_exists):
"""from fs xdg"""
clean_setup()
home = os.path.expanduser('/etc/xdg')
expected = f'{home}/dotdrop/config.yaml'
mock_exists.side_effect = side_effect(valid=expected)
args = get_args({'--cfg': ''})
fake = FakeOptions(args)
self.assertEqual(fake._get_config_path(), expected)
@patch('os.path.exists')
def test_get_path_fs_etc_dotdrop_yaml(self, mock_exists):
"""from fs etc"""
clean_setup()
home = os.path.expanduser('/etc')
expected = f'{home}/dotdrop/config.yaml'
mock_exists.side_effect = side_effect(valid=expected)
args = get_args({'--cfg': ''})
fake = FakeOptions(args)
self.assertEqual(fake._get_config_path(), expected)
@patch('os.path.exists')
def test_get_path_fs_etc_xdg_yaml(self, mock_exists):
"""from fs etc/xdg"""
clean_setup()
home = os.path.expanduser('/etc/xdg')
expected = f'{home}/dotdrop/config.yaml'
mock_exists.side_effect = side_effect(valid=expected)
args = get_args({'--cfg': ''})
fake = FakeOptions(args)
self.assertEqual(fake._get_config_path(), expected)
@patch('os.path.exists')
def test_get_path_fs_xdg_toml(self, mock_exists):
"""from fs toml"""
clean_setup()
home = os.path.expanduser('~/.config')
expected = f'{home}/dotdrop/config.toml'
mock_exists.side_effect = side_effect(valid=expected)
args = get_args({'--cfg': ''})
fake = FakeOptions(args)
self.assertEqual(fake._get_config_path(), expected)
@patch('os.path.exists')
def test_get_path_fs_xdg_etc_toml(self, mock_exists):
"""from fs xdg"""
clean_setup()
home = os.path.expanduser('/etc/xdg')
expected = f'{home}/dotdrop/config.toml'
mock_exists.side_effect = side_effect(valid=expected)
log = Logger(debug=True)
log.dbg(f'expected: {expected}')
args = get_args({'--cfg': ''})
fake = FakeOptions(args)
self.assertEqual(fake._get_config_path(), expected)
@patch('os.path.exists')
def test_get_path_fs_etc(self, mock_exists):
def test_get_path_fs_etc_dotdrop_toml(self, mock_exists):
"""from fs etc"""
clean_setup()
home = os.path.expanduser('/etc')
expected = f'{home}/dotdrop/config.toml'
mock_exists.side_effect = side_effect(valid=expected)
log = Logger(debug=True)
log.dbg(f'expected: {expected}')
args = get_args({'--cfg': ''})
fake = FakeOptions(args)
self.assertEqual(fake._get_config_path(), expected)
@patch('os.path.exists')
def test_get_path_fs_etc_xdg_toml(self, mock_exists):
"""from fs etc/xdg"""
clean_setup()
home = os.path.expanduser('/etc/xdg')
expected = f'{home}/dotdrop/config.toml'
mock_exists.side_effect = side_effect(valid=expected)
args = get_args({'--cfg': ''})
fake = FakeOptions(args)
self.assertEqual(fake._get_config_path(), expected)
@patch('os.path.exists')
def test_get_path_none(self, mock_exists):
"""path is none"""
clean_setup()
mock_exists.return_value = False
args = get_args({})
fake = FakeOptions(args)
self.assertEqual(None, fake._get_config_path())
@patch('os.path.exists')
def test_options_debug(self, mock_exists):
"""test debug"""
mock_exists.return_value = False
args = {
'--verbose': True,
'--dry': False,
'--cfg': 'path',
'--profile': 'profile',
}
with self.assertRaises(YamlException):
Options(args)
def main():
"""entry point"""

View File

@@ -52,6 +52,25 @@ class TestConfig(SubsetTestCase):
self.assertTrue(dpath == self.CONFIG_DOTPATH)
self.assertTrue(conf.dump() != '')
def test_raises(self):
"""test raises on not existing path"""
with self.assertRaises(YamlException):
Cfg('path', debug=True)
def test_resolve_link(self):
"""test bad link value"""
tmp = get_tempdir()
self.assertTrue(os.path.exists(tmp))
self.addCleanup(clean, tmp)
confpath = create_fake_config(tmp,
configname=self.CONFIG_NAME,
dotpath=self.CONFIG_DOTPATH,
backup=self.CONFIG_BACKUP,
create=self.CONFIG_CREATE)
cfg = Cfg(confpath, debug=True)
with self.assertRaises(YamlException):
cfg._resolve_dotfile_link('fake')
def test_def_link(self):
"""unittest"""
# pylint: disable=E1120