예제 #1
0
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
예제 #2
0
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'))
예제 #3
0
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
예제 #4
0
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
예제 #5
0
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"))
예제 #6
0
    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
예제 #7
0
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."}}}
예제 #8
0
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
예제 #9
0
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
예제 #10
0
파일: filter.py 프로젝트: r2d2m/organize
 def run(self, **kwargs):
     return self.pipeline(DotDict(kwargs))
예제 #11
0
 def run(self, **kwargs: Dict) -> FilterResult:
     return self.pipeline(DotDict(kwargs))
예제 #12
0
 def parse(self, path):
     result = DotDict(self.expr.match(path.name).groupdict())
     return {'regex': result}
예제 #13
0
def test_dotdict_keeptype():
    a = DotDict()
    a.update({"nr": {"upper": 1}})
    assert a.nr.upper == 1

    assert "{nr.upper}".format(**a) == "1"
예제 #14
0
 def run(self, **kwargs) -> Optional[Mapping[str, Any]]:
     return self.pipeline(DotDict(kwargs))