From bf23f6b341dd17e319a2aa84ddb951ebab75e353 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Wed, 13 Mar 2019 08:31:39 +0100 Subject: [PATCH] refactor linkall to link_children --- dotdrop/dotdrop.py | 3 ++- dotdrop/installer.py | 4 ++-- tests/test_install.py | 35 ++++++++++++++++++----------------- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index ae8e23f..bc84824 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -63,7 +63,8 @@ def cmd_install(o): if hasattr(dotfile, 'link') and dotfile.link == LinkTypes.PARENTS: r = inst.link(t, dotfile.src, dotfile.dst, actions=preactions) elif hasattr(dotfile, 'link') and dotfile.link == LinkTypes.CHILDREN: - r = inst.linkall(t, dotfile.src, dotfile.dst, actions=preactions) + r = inst.link_children(t, dotfile.src, dotfile.dst, + actions=preactions) else: src = dotfile.src tmp = None diff --git a/dotdrop/installer.py b/dotdrop/installer.py index 6cf7074..68ee6a7 100644 --- a/dotdrop/installer.py +++ b/dotdrop/installer.py @@ -101,10 +101,10 @@ class Installer: src = tmp return self._link(src, dst, actions=actions) - def linkall(self, templater, src, dst, actions=[]): + def link_children(self, templater, src, dst, actions=[]): """link all dotfiles in a given directory""" if self.debug: - self.log.dbg('linkall {} to {}'.format(src, dst)) + self.log.dbg('link_children {} to {}'.format(src, dst)) self.action_executed = False parent = os.path.join(self.base, os.path.expanduser(src)) diff --git a/tests/test_install.py b/tests/test_install.py index e040b28..ea8e5b1 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -57,10 +57,12 @@ exec bspwm f.write(' {}:\n'.format(d.key)) f.write(' dst: {}\n'.format(d.dst)) f.write(' src: {}\n'.format(d.src)) - f.write(' link: {}\n' - .format(str(d.link == LinkTypes.PARENTS).lower())) - f.write(' link_children: {}\n' - .format(str(d.link == LinkTypes.CHILDREN).lower())) + 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())) if len(d.actions) > 0: f.write(' actions:\n') for action in d.actions: @@ -249,8 +251,8 @@ exec bspwm srcs = [create_random_file(src_dir)[0] for _ in range(3)] installer = Installer() - installer.linkall(templater=MagicMock(), src=src_dir, dst=dst_dir, - actions=[]) + installer.link_children(templater=MagicMock(), src=src_dir, + dst=dst_dir, actions=[]) # Ensure all destination files point to source for src in srcs: @@ -265,9 +267,8 @@ exec bspwm logger = MagicMock() installer.log.err = logger - res = installer.linkall(templater=MagicMock(), - src=src, - dst='/dev/null', actions=[]) + res = installer.link_children(templater=MagicMock(), src=src, + dst='/dev/null', actions=[]) self.assertEqual(res, []) logger.assert_called_with('source dotfile does not exist: {}' @@ -288,8 +289,8 @@ exec bspwm installer.log.err = logger # pass src file not src dir - res = installer.linkall(templater=templater, src=src, dst='/dev/null', - actions=[]) + res = installer.link_children(templater=templater, src=src, + dst='/dev/null', actions=[]) # ensure nothing performed self.assertEqual(res, []) @@ -312,8 +313,8 @@ exec bspwm self.assertFalse(os.path.exists(dst_dir)) installer = Installer() - installer.linkall(templater=MagicMock(), src=src_dir, dst=dst_dir, - actions=[]) + installer.link_children(templater=MagicMock(), src=src_dir, + dst=dst_dir, actions=[]) # ensure dst dir created self.assertTrue(os.path.exists(dst_dir)) @@ -344,8 +345,8 @@ exec bspwm installer.safe = True installer.log.ask = ask - installer.linkall(templater=MagicMock(), src=src_dir, dst=dst, - actions=[]) + installer.link_children(templater=MagicMock(), src=src_dir, dst=dst, + actions=[]) # ensure destination now a directory self.assertTrue(os.path.isdir(dst)) @@ -378,8 +379,8 @@ exec bspwm # make templategen treat everything as a template mocked_templategen.is_template.return_value = True - installer.linkall(templater=templater, src=src_dir, dst=dst_dir, - actions=[]) + installer.link_children(templater=templater, src=src_dir, dst=dst_dir, + actions=[]) for src in srcs: dst = os.path.join(dst_dir, os.path.basename(src))