Beispiel #1
0
def test_increment_filename_version():
    assert (increment_filename_version(Path.home() / "f3" /
                                       "test_123.7z") == Path.home() / "f3" /
            "test_123 2.7z")
    assert (increment_filename_version(
        Path.home() / "f3" / "test_123_2 10.7z") == Path.home() / "f3" /
            "test_123_2 11.7z")
Beispiel #2
0
def test_increment_filename_version():
    assert (increment_filename_version(Path.home() / 'f3' /
                                       'test_123.7z') == Path.home() / 'f3' /
            'test_123 2.7z')
    assert (increment_filename_version(
        Path.home() / 'f3' / 'test_123_2 10.7z') == Path.home() / 'f3' /
            'test_123_2 11.7z')
def test_keep_name(mock_exists, mock_samefile, mock_rename, mock_trash):
    attrs = {"basedir": Path.home(), "path": Path.home() / "test.pdf"}
    mock_exists.return_value = True
    mock_samefile.return_value = True
    rename = Rename(name="{path.stem}.pdf", overwrite=False)
    new_path = rename.run(attrs, False)
    mock_exists.assert_called()
    mock_trash.assert_not_called()
    mock_rename.assert_not_called()
    assert new_path is not None
def test_already_exists_multiple(mock_exists, mock_samefile, mock_rename, mock_trash):
    attrs = {"basedir": Path.home(), "path": Path.home() / "test.py"}
    mock_exists.side_effect = [True, True, True, False]
    mock_samefile.return_value = False
    rename = Rename(name="asd.txt", overwrite=False)
    new_path = rename.run(attrs, False)
    mock_exists.assert_called()
    mock_trash.assert_not_called()
    mock_rename.assert_called_with(Path("~/asd 4.txt").expanduser())
    assert new_path is not None
def test_makedirs(mock_parent, mock_copy, mock_trash):
    attrs = {"basedir": Path.home(), "path": Path.home() / "test.py"}
    copy = Copy(dest="~/some/new/folder/", overwrite=False)
    copy.run(attrs, False)
    mock_parent.mkdir.assert_called_with(parents=True, exist_ok=True)
    mock_trash.assert_not_called()
    mock_copy.assert_called_with(
        src=os.path.join(USER_DIR, "test.py"),
        dst=os.path.join(USER_DIR, "some", "new", "folder", "test.py"),
    )
def test_overwrite(mock_exists, mock_samefile, mock_rename, mock_trash):
    attrs = {"basedir": Path.home(), "path": Path.home() / "test.py"}
    mock_exists.return_value = True
    mock_samefile.return_value = False
    rename = Rename(name="{path.stem} Kopie.py", overwrite=True)
    new_path = rename.run(attrs, False)
    mock_exists.assert_called()
    mock_trash.assert_called_with(os.path.join(USER_DIR, "test Kopie.py"))
    mock_rename.assert_called_with(Path("~/test Kopie.py").expanduser())
    assert new_path is not None
def test_tilde_expansion(mock_exists, mock_samefile, mock_rename, mock_trash):
    attrs = {"basedir": Path.home(), "path": Path.home() / "test.py"}
    mock_exists.return_value = False
    mock_samefile.return_value = False
    rename = Rename(name="newname.py", overwrite=False)
    new_path = rename.run(attrs, False)
    mock_exists.assert_called()
    mock_trash.assert_not_called()
    expected_path = (Path.home() / "newname.py").expanduser()
    mock_rename.assert_called_with(expected_path)
    assert new_path == expected_path
def test_overwrite_samefile(mock_exists, mock_samefile, mock_rename,
                            mock_trash):
    attrs = {'basedir': Path.home(), 'path': Path.home() / 'test.PDF'}
    mock_exists.return_value = True
    mock_samefile.return_value = True
    rename = Rename(name='{path.stem}.pdf', overwrite=False)
    new_path = rename.run(attrs, False)
    mock_exists.assert_called()
    mock_trash.assert_not_called()
    mock_rename.assert_called_with((Path.home() / 'test.pdf').expanduser())
    assert new_path is not None
Beispiel #9
0
def test_dont_keep_case_sensitive(mock_exists, mock_samefile, mock_move,
                                  mock_trash, mock_mkdir):
    attrs = {"basedir": Path.home(), "path": Path.home() / "test.py"}
    mock_exists.return_value = True
    mock_samefile.return_value = True
    move = Move(dest="~/TEST.PY")
    new_path = move.run(attrs, False)
    mock_mkdir.assert_called()
    mock_exists.assert_called_with()
    mock_trash.assert_not_called()
    mock_move.assert_called()
    assert new_path is not None
def test_makedirs(mock_parent, mock_copy, mock_trash):
    attrs = {
        'basedir': Path.home(),
        'path': Path.home() / 'test.py',
    }
    copy = Copy(dest='~/some/new/folder/', overwrite=False)
    copy.run(attrs, False)
    mock_parent.mkdir.assert_called_with(parents=True, exist_ok=True)
    mock_trash.assert_not_called()
    mock_copy.assert_called_with(
        src=os.path.join(USER_DIR, 'test.py'),
        dst=os.path.join(USER_DIR, 'some', 'new', 'folder', 'test.py'))
Beispiel #11
0
def test_splitglob():
    assert splitglob('~/Downloads') == (Path.home() / 'Downloads', '')
    assert (splitglob(r'/Test/\* tmp\*/*[!H]/**/*.*') == (
        Path(r'/Test/\* tmp\*'), '*[!H]/**/*.*'))
    assert (splitglob('~/Downloads/Program 0.1*.exe') == (Path.home() /
                                                          'Downloads',
                                                          'Program 0.1*.exe'))
    assert (splitglob('~/Downloads/Program[ms].exe') == (Path.home() /
                                                         'Downloads',
                                                         'Program[ms].exe'))
    assert (splitglob('~/Downloads/Program.exe') == (Path.home() /
                                                     'Downloads' /
                                                     'Program.exe', ''))
Beispiel #12
0
def test_tilde_expansion(mock_exists, mock_samefile, mock_move, mock_trash,
                         mock_mkdir):
    attrs = {"basedir": Path.home(), "path": Path.home() / "test.py"}
    mock_exists.return_value = False
    mock_samefile.return_value = False
    move = Move(dest="~/newname.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, "newname.py"))
    assert new_path == Path("~/newname.py").expanduser()
def test_already_exists(mock_exists, mock_samefile, mock_rename, mock_trash):
    attrs = {
        'basedir': Path.home(),
        'path': Path.home() / 'test.py',
    }
    mock_exists.side_effect = [True, False]
    mock_samefile.return_value = False
    rename = Rename(name='asd.txt', overwrite=False)
    new_path = rename.run(attrs, False)
    mock_exists.assert_called()
    mock_trash.assert_not_called()
    mock_rename.assert_called_with(Path('~/asd 2.txt').expanduser())
    assert new_path is not None
def test_overwrite(mock_exists, mock_samefile, mock_rename, mock_trash):
    attrs = {
        'basedir': Path.home(),
        'path': Path.home() / 'test.py',
    }
    mock_exists.return_value = True
    mock_samefile.return_value = False
    rename = Rename(name='{path.stem} Kopie.py', overwrite=True)
    new_path = rename.run(attrs, False)
    mock_exists.assert_called()
    mock_trash.assert_called_with(os.path.join(USER_DIR, 'test Kopie.py'))
    mock_rename.assert_called_with(Path('~/test Kopie.py').expanduser())
    assert new_path is not None
def test_keep_location(mock_exists, mock_samefile, mock_move, mock_trash, mock_mkdir):
    attrs = {
        'basedir': Path.home(),
        'path': Path.home() / 'test.py',
    }
    mock_exists.return_value = True
    mock_samefile.return_value = True
    move = Move(dest='~/test.py')
    new_path = move.run(attrs, False)
    mock_mkdir.assert_not_called()
    mock_exists.assert_called_with()
    mock_trash.assert_not_called()
    mock_move.assert_not_called()
    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_tilde_expansion(mock_exists, mock_samefile, mock_copy, mock_trash,
                         mock_mkdir):
    attrs = {"basedir": Path.home(), "path": Path.home() / "test.py"}
    mock_exists.return_value = False
    mock_samefile.return_value = False
    copy = Copy(dest="~/newname.py", overwrite=False)
    new_path = 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, "newname.py"))
    # keep old file path
    assert new_path == None
def test_into_folder(mock_exists, mock_samefile, mock_copy, mock_trash,
                     mock_mkdir):
    attrs = {"basedir": Path.home(), "path": Path.home() / "test.py"}
    mock_exists.return_value = False
    mock_samefile.return_value = False
    copy = Copy(dest="~/somefolder/", 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, "somefolder", "test.py"),
    )
def test_already_exists_multiple(mock_exists, mock_samefile, mock_copy,
                                 mock_trash, mock_mkdir):
    attrs = {"basedir": Path.home(), "path": Path.home() / "test.py"}
    mock_exists.side_effect = [True, True, True, False]
    mock_samefile.return_value = False
    copy = Copy(dest="~/folder/", 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, "folder", "test 4.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_already_exists_multiple(mock_exists, mock_samefile, mock_copy, mock_trash, mock_mkdir):
    attrs = {
        'basedir': Path.home(),
        'path': Path.home() / 'test.py',
    }
    mock_exists.side_effect = [True, True, True, False]
    mock_samefile.return_value = False
    copy = Copy(dest='~/folder/', 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, 'folder', 'test 4.py'))
def test_into_folder(mock_exists, mock_samefile, mock_copy, mock_trash, mock_mkdir):
    attrs = {
        'basedir': Path.home(),
        'path': Path.home() / 'test.py',
    }
    mock_exists.return_value = False
    mock_samefile.return_value = False
    copy = Copy(dest='~/somefolder/', 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, 'somefolder', 'test.py'))
Beispiel #23
0
def test_path(mock_exists, mock_samefile, mock_move, mock_trash, mock_mkdir):
    attrs = {"basedir": Path.home(), "path": Path.home() / "test.py"}
    mock_exists.return_value = False
    mock_samefile.return_value = False
    move = Move(dest="~/{path.stem}/{path.suffix}/{path.name}",
                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, "test", ".py", "test.py"),
    )
    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"))
Beispiel #25
0
def test_already_exists_multiple_separator(mock_exists, mock_samefile,
                                           mock_move, mock_trash, mock_mkdir):
    attrs = {"basedir": Path.home(), "path": Path.home() / "test.py"}
    mock_exists.side_effect = [True, True, True, False]
    mock_samefile.return_value = False
    move = Move(dest="~/folder/", overwrite=False, counter_separator="_")
    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, "folder", "test_4.py"),
    )
    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 test_already_exists(mock_exists, mock_samefile, mock_move, mock_trash, mock_mkdir):
    attrs = {
        'basedir': Path.home(),
        'path': Path.home() / 'test.py',
    }
    mock_exists.side_effect = [True, False]
    mock_samefile.return_value = False
    move = Move(dest='~/folder/', 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, 'folder', 'test 2.py'))
    assert new_path is not None
def test_tilde_expansion(mock_exists, mock_samefile, mock_move, mock_trash,
                         mock_mkdir):
    attrs = {
        'basedir': Path.home(),
        'path': Path.home() / 'test.py',
    }
    mock_exists.return_value = False
    mock_samefile.return_value = False
    move = Move(dest='~/newname.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, 'newname.py'))
    assert new_path == Path('~/newname.py').expanduser()
def test_path(mock_exists, mock_samefile, mock_move, mock_trash, mock_mkdir):
    attrs = {
        'basedir': Path.home(),
        'path': Path.home() / 'test.py',
    }
    mock_exists.return_value = False
    mock_samefile.return_value = False
    move = Move(dest='~/{path.stem}/{path.suffix}/{path.name}',
                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, 'test', '.py',
                                                  'test.py'))
    assert new_path is not None
Beispiel #30
0
def test_splitglob():
    assert splitglob("~/Downloads") == (Path.home() / "Downloads", "")
    assert splitglob(r"/Test/\* tmp\*/*[!H]/**/*.*") == (
        Path(r"/Test/\* tmp\*"),
        "*[!H]/**/*.*",
    )
    assert splitglob("~/Downloads/Program 0.1*.exe") == (
        Path.home() / "Downloads",
        "Program 0.1*.exe",
    )
    assert splitglob("~/Downloads/Program[ms].exe") == (
        Path.home() / "Downloads",
        "Program[ms].exe",
    )
    assert splitglob("~/Downloads/Program.exe") == (
        Path.home() / "Downloads" / "Program.exe",
        "",
    )