コード例 #1
0
ファイル: test_utils.py プロジェクト: jaywalker76/organize
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')
コード例 #2
0
def test_filename_multiple():
    filename = Filename(startswith='begin', contains='con', endswith='end')
    assert filename.matches(Path('~/here/begin_somethgin_con_end.pdf'))
    assert not filename.matches(Path('~/here/beginend.pdf'))
    assert not filename.matches(Path('~/here/begincon.begin'))
    assert not filename.matches(Path('~/here/conend.begin'))
    assert filename.matches(Path('~/here/beginconend.begin'))
コード例 #3
0
def test_filename_multiple():
    filename = Filename(startswith="begin", contains="con", endswith="end")
    assert filename.matches(Path("~/here/begin_somethgin_con_end.pdf"))
    assert not filename.matches(Path("~/here/beginend.pdf"))
    assert not filename.matches(Path("~/here/begincon.begin"))
    assert not filename.matches(Path("~/here/conend.begin"))
    assert filename.matches(Path("~/here/beginconend.begin"))
コード例 #4
0
def test_increment_filename_version_separator():
    assert increment_filename_version(Path("test_123.7z"), separator="_") == Path(
        "test_124.7z"
    )
    assert increment_filename_version(Path("test_123_2.7z"), separator="_") == Path(
        "test_123_3.7z"
    )
コード例 #5
0
ファイル: test_utils.py プロジェクト: win0err/organize
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")
コード例 #6
0
def test_min():
    now = datetime.now()
    last_modified = LastModified(days=10, hours=12, mode='older')
    with patch.object(last_modified, '_last_modified') as mock_lm:
        mock_lm.return_value = now - timedelta(days=10, hours=0)
        assert not last_modified.matches(Path('~'))
        mock_lm.return_value = now - timedelta(days=10, hours=13)
        assert last_modified.matches(Path('~'))
コード例 #7
0
def test_filename_case():
    filename = Filename(startswith='star',
                        contains='con',
                        endswith='end',
                        case_sensitive=False)
    assert filename.matches(Path('~/STAR_conEnD.dpf'))
    assert not filename.matches(Path('~/here/STAREND.pdf'))
    assert not filename.matches(Path('~/here/STARCON.begin'))
    assert not filename.matches(Path('~/here/CONEND.begin'))
    assert filename.matches(Path('~/here/STARCONEND.begin'))
コード例 #8
0
def test_makedirs(mock_parent, mock_copy, mock_trash):
    basedir = Path('~')
    path = Path('~') / 'test.py'
    copy = Copy(dest='~/some/new/folder/', overwrite=False)
    copy.run(basedir, path, {}, 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'))
コード例 #9
0
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
コード例 #10
0
def test_filename_case():
    filename = Filename(startswith="star",
                        contains="con",
                        endswith="end",
                        case_sensitive=False)
    assert filename.matches(Path("~/STAR_conEnD.dpf"))
    assert not filename.matches(Path("~/here/STAREND.pdf"))
    assert not filename.matches(Path("~/here/STARCON.begin"))
    assert not filename.matches(Path("~/here/CONEND.begin"))
    assert filename.matches(Path("~/here/STARCONEND.begin"))
コード例 #11
0
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"),
    )
コード例 #12
0
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
コード例 #13
0
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
コード例 #14
0
def test_extension():
    extension = Extension("JPG", ".gif", "pdf")
    testpathes = [
        (Path("~/somefile.pdf"), True),
        (Path("/home/test/somefile.pdf.jpeg"), False),
        (Path("/home/test/gif.TXT"), False),
        (Path("/home/test/txt.GIF"), True),
        (Path("~/somefile.pdf"), True),
    ]
    for path, match in testpathes:
        assert extension.matches(path) == match
コード例 #15
0
def test_overwrite(mock_exists, mock_samefile, mock_rename, mock_trash):
    basedir = Path('~')
    path = Path('~') / '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(basedir, path, {}, 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
コード例 #16
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
コード例 #17
0
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
コード例 #18
0
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
コード例 #19
0
def test_keep_name(mock_exists, mock_samefile, mock_rename, mock_trash):
    basedir = Path('~')
    path = Path('~') / 'test.pdf'
    mock_exists.return_value = True
    mock_samefile.return_value = True
    rename = Rename(name='{path.stem}.pdf', overwrite=False)
    new_path = rename.run(basedir, path, {}, False)
    mock_exists.assert_called()
    mock_trash.assert_not_called()
    mock_rename.assert_not_called()
    assert new_path is not None
コード例 #20
0
def test_extension():
    extension = Extension('JPG', '.gif', 'pdf')
    testpathes = [
        (Path('~/somefile.pdf'), True),
        (Path('/home/test/somefile.pdf.jpeg'), False),
        (Path('/home/test/gif.TXT'), False),
        (Path('/home/test/txt.GIF'), True),
        (Path('~/somefile.pdf'), True)
    ]
    for path, match in testpathes:
        assert extension.matches(path) == match
コード例 #21
0
def test_already_exists_multiple(mock_exists, mock_samefile, mock_rename, mock_trash):
    basedir = Path('~')
    path = Path('~') / '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(basedir, path, {}, 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
コード例 #22
0
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'))
コード例 #23
0
def test_tilde_expansion(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='newname.py', overwrite=False)
    new_path = rename.run(basedir, path, {}, False)
    mock_exists.assert_called()
    mock_trash.assert_not_called()
    expected_path = (Path('~') / 'newname.py').expanduser()
    mock_rename.assert_called_with(expected_path)
    assert new_path == expected_path
コード例 #24
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
コード例 #25
0
ファイル: test_utils.py プロジェクト: jaywalker76/organize
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', ''))
コード例 #26
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'))
コード例 #27
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()
コード例 #28
0
def test_already_exists_multiple(mock_exists, mock_samefile, mock_copy, mock_trash, mock_mkdir):
    basedir = Path('~')
    path = Path('~') / 'test.py'
    mock_exists.side_effect = [True, True, True, False]
    mock_samefile.return_value = False
    copy = Copy(dest='~/folder/', overwrite=False)
    copy.run(basedir, path, {}, 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'))
コード例 #29
0
def test_into_folder(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='~/somefolder/', overwrite=False)
    copy.run(basedir, path, {}, 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'))
コード例 #30
0
def test_dont_keep_case_sensitive(mock_exists, mock_samefile, mock_move,
                                  mock_trash, mock_mkdir):
    basedir = Path('~')
    path = Path('~') / 'test.py'
    mock_exists.return_value = True
    mock_samefile.return_value = True
    move = Move(dest='~/TEST.PY')
    new_path = move.run(basedir, path, {}, 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