def test_attrs(mock_exists, mock_samefile, mock_rename, mock_trash): basedir = Path('~') path = Path('~') / 'test.py' mock_exists.return_value = False mock_samefile.return_value = False rename = Rename(name='{nr.upper}-{path.stem} Kopie.py') new_path = rename.run(basedir, path, {'nr': DotDict({'upper': 1})}, False) mock_exists.assert_called() mock_trash.assert_not_called() mock_rename.assert_called_with(Path('~/1-test Kopie.py').expanduser()) assert new_path is not None
def test_attrs(mock_exists, mock_samefile, mock_copy, mock_trash, mock_mkdir): basedir = Path('~') path = Path('~') / 'test.py' mock_exists.return_value = False mock_samefile.return_value = False copy = Copy(dest='~/{nr.upper}-name.py', overwrite=False) copy.run(basedir, path, {'nr': DotDict({'upper': 1})}, False) mock_mkdir.assert_called_with(exist_ok=True, parents=True) mock_exists.assert_called_with() mock_trash.assert_not_called() mock_copy.assert_called_with( src=os.path.join(USER_DIR, 'test.py'), dst=os.path.join(USER_DIR, '1-name.py'))
def test_attrs(mock_exists, mock_samefile, mock_rename, mock_trash): attrs = { "basedir": Path.home(), "path": Path.home() / "test.py", "nr": DotDict({"upper": 1}), } mock_exists.return_value = False mock_samefile.return_value = False rename = Rename(name="{nr.upper}-{path.stem} Kopie.py") new_path = rename.run(attrs, False) mock_exists.assert_called() mock_trash.assert_not_called() mock_rename.assert_called_with(Path("~/1-test Kopie.py").expanduser()) assert new_path is not None
def test_attrs(mock_exists, mock_samefile, mock_rename, mock_trash): attrs = { 'basedir': Path.home(), 'path': Path.home() / 'test.py', 'nr': DotDict({'upper': 1}), } mock_exists.return_value = False mock_samefile.return_value = False rename = Rename(name='{nr.upper}-{path.stem} Kopie.py') new_path = rename.run(attrs, False) mock_exists.assert_called() mock_trash.assert_not_called() mock_rename.assert_called_with(Path('~/1-test Kopie.py').expanduser()) assert new_path is not None
def test_attrs(mock_exists, mock_samefile, mock_copy, mock_trash, mock_mkdir): attrs = { "basedir": Path.home(), "path": Path.home() / "test.py", "nr": DotDict({"upper": 1}), } mock_exists.return_value = False mock_samefile.return_value = False copy = Copy(dest="~/{nr.upper}-name.py", overwrite=False) copy.run(attrs, False) mock_mkdir.assert_called_with(exist_ok=True, parents=True) mock_exists.assert_called_with() mock_trash.assert_not_called() mock_copy.assert_called_with(src=os.path.join(USER_DIR, "test.py"), dst=os.path.join(USER_DIR, "1-name.py"))
def pipeline(self, args: DotDict) -> Optional[Mapping[str, Any]]: simulate = args.simulate if simulate: self.print("Code not run in simulation. (Args: %s)" % args) return None logger.info('Executing python:\n"""\n%s\n""", args=%s', self.code, args) self.create_method(name="usercode", argnames=args.keys(), code=self.code) self.print("Running python script.") result = self.usercode(**args) # pylint: disable=assignment-from-no-return return result
def test_dotdict_merge(): a = DotDict() b = {1: {2: 2, 3: 3, 4: {5: "fin."}}} a.update(b) assert a == b b[1][2] = 5 assert a != b a.update({1: {4: {5: "new.", 6: "fin."}, 2: "x"}}) assert a == {1: {2: "x", 3: 3, 4: {5: "new.", 6: "fin."}}}
def test_attrs(mock_exists, mock_samefile, mock_move, mock_trash, mock_mkdir): attrs = { 'basedir': Path.home(), 'path': Path.home() / 'test.py', 'nr': DotDict({'upper': 1}) } mock_exists.return_value = False mock_samefile.return_value = False move = Move(dest='~/{nr.upper}-name.py', overwrite=False) new_path = move.run(attrs, False) mock_mkdir.assert_called_with(exist_ok=True, parents=True) mock_exists.assert_called_with() mock_trash.assert_not_called() mock_move.assert_called_with(src=os.path.join(USER_DIR, 'test.py'), dst=os.path.join(USER_DIR, '1-name.py')) assert new_path is not None
import os from organize.actions import Move from organize.compat import Path from organize.utils import DotDict USER_DIR = os.path.expanduser("~") ARGS = DotDict(basedir=Path.home(), path=Path.home() / "test.py", simulate=False) def test_tilde_expansion(mock_exists, mock_samefile, mock_move, mock_trash, mock_mkdir): mock_exists.return_value = False mock_samefile.return_value = False move = Move(dest="~/newname.py", overwrite=False) updates = move.run(**ARGS) mock_mkdir.assert_called_with(exist_ok=True, parents=True) mock_exists.assert_called_with() mock_trash.assert_not_called() mock_move.assert_called_with(src=os.path.join(USER_DIR, "test.py"), dst=os.path.join(USER_DIR, "newname.py")) assert updates == {"path": Path("~/newname.py").expanduser()} def test_into_folder(mock_exists, mock_samefile, mock_move, mock_trash, mock_mkdir): mock_exists.return_value = False mock_samefile.return_value = False
def run(self, **kwargs): return self.pipeline(DotDict(kwargs))
def run(self, **kwargs: Dict) -> FilterResult: return self.pipeline(DotDict(kwargs))
def parse(self, path): result = DotDict(self.expr.match(path.name).groupdict()) return {'regex': result}
def test_dotdict_keeptype(): a = DotDict() a.update({"nr": {"upper": 1}}) assert a.nr.upper == 1 assert "{nr.upper}".format(**a) == "1"
def run(self, **kwargs) -> Optional[Mapping[str, Any]]: return self.pipeline(DotDict(kwargs))