Пример #1
0
def test_makedirs(mock_parent, mock_move, mock_trash):
    move = Move(dest="~/some/new/folder/", overwrite=False)
    updates = move.run(**ARGS)
    mock_parent.mkdir.assert_called_with(parents=True, exist_ok=True)
    mock_trash.assert_not_called()
    mock_move.assert_called_with(
        src=os.path.join(USER_DIR, "test.py"),
        dst=os.path.join(USER_DIR, "some", "new", "folder", "test.py"),
    )
    assert updates is not None
Пример #2
0
def test_makedirs(mock_parent, mock_move, mock_trash):
    basedir = Path('~')
    path = Path('~') / 'test.py'
    move = Move(dest='~/some/new/folder/', overwrite=False)
    new_path = move.run(basedir, path, {}, False)
    mock_parent.mkdir.assert_called_with(parents=True, exist_ok=True)
    mock_trash.assert_not_called()
    mock_move.assert_called_with(src=os.path.join(USER_DIR, 'test.py'),
                                 dst=os.path.join(USER_DIR, 'some', 'new',
                                                  'folder', 'test.py'))
    assert new_path is not None
Пример #3
0
def test_makedirs(mock_parent, mock_move, mock_trash):
    attrs = {"basedir": Path.home(), "path": Path.home() / "test.py"}
    move = Move(dest="~/some/new/folder/", overwrite=False)
    new_path = move.run(attrs, False)
    mock_parent.mkdir.assert_called_with(parents=True, exist_ok=True)
    mock_trash.assert_not_called()
    mock_move.assert_called_with(
        src=os.path.join(USER_DIR, "test.py"),
        dst=os.path.join(USER_DIR, "some", "new", "folder", "test.py"),
    )
    assert new_path is not None
Пример #4
0
def test_keep_location(mock_exists, mock_samefile, mock_move, mock_trash,
                       mock_mkdir):
    mock_exists.return_value = True
    mock_samefile.return_value = True
    move = Move(dest="~/test.py")
    updates = move.run(**ARGS)
    mock_mkdir.assert_not_called()
    mock_exists.assert_called_with()
    mock_trash.assert_not_called()
    mock_move.assert_not_called()
    assert updates is not None
Пример #5
0
def test_dont_keep_case_sensitive(mock_exists, mock_samefile, mock_move,
                                  mock_trash, mock_mkdir):
    mock_exists.return_value = True
    mock_samefile.return_value = True
    move = Move(dest="~/TEST.PY")
    updates = move.run(**ARGS)
    assert mock_mkdir.call_count > 0
    mock_exists.assert_called_with()
    mock_trash.assert_not_called()
    assert mock_move.call_count > 0
    assert updates is not None
Пример #6
0
def test_args(mock_exists, mock_samefile, mock_move, mock_trash, mock_mkdir):
    args = ARGS.merge({"nr": {"upper": 1}})
    mock_exists.return_value = False
    mock_samefile.return_value = False
    move = Move(dest="~/{nr.upper}-name.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, "1-name.py"))
    assert updates is not None
Пример #7
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
Пример #8
0
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()}
Пример #9
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
Пример #10
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()
Пример #11
0
def test_makedirs(mock_parent, mock_move, mock_trash):
    attrs = {
        'basedir': Path.home(),
        'path': Path.home() / 'test.py',
    }
    move = Move(dest='~/some/new/folder/', overwrite=False)
    new_path = move.run(attrs, False)
    mock_parent.mkdir.assert_called_with(parents=True, exist_ok=True)
    mock_trash.assert_not_called()
    mock_move.assert_called_with(src=os.path.join(USER_DIR, 'test.py'),
                                 dst=os.path.join(USER_DIR, 'some', 'new',
                                                  'folder', 'test.py'))
    assert new_path is not None
Пример #12
0
def test_attrs(mock_exists, mock_samefile, mock_move, mock_trash, mock_mkdir):
    basedir = Path('~')
    path = Path('~') / 'test.py'
    mock_exists.return_value = False
    mock_samefile.return_value = False
    move = Move(dest='~/{nr.upper}-name.py', overwrite=False)
    new_path = move.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_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
Пример #13
0
def test_tilde_expansion(mock_exists, mock_samefile, mock_move, mock_trash,
                         mock_mkdir):
    basedir = Path('~')
    path = Path('~') / 'test.py'
    mock_exists.return_value = False
    mock_samefile.return_value = False
    move = Move(dest='~/newname.py', overwrite=False)
    new_path = move.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_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()
Пример #14
0
def test_already_exists_multiple_separator(mock_exists, mock_samefile,
                                           mock_move, mock_trash, mock_mkdir):
    mock_exists.side_effect = [True, True, True, False]
    mock_samefile.return_value = False
    move = Move(dest="~/folder/", overwrite=False, counter_separator="_")
    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, "folder", "test_4.py"),
    )
    assert updates is not None
Пример #15
0
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
Пример #16
0
def test_path(mock_exists, mock_samefile, mock_move, mock_trash, mock_mkdir):
    mock_exists.return_value = False
    mock_samefile.return_value = False
    move = Move(dest="~/{path.stem}/{path.suffix}/{path.name}",
                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, "test", ".py", "test.py"),
    )
    assert updates is not None
Пример #17
0
def test_into_folder(mock_exists, mock_samefile, mock_move, mock_trash,
                     mock_mkdir):
    mock_exists.return_value = False
    mock_samefile.return_value = False
    move = Move(dest="~/somefolder/", 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, "somefolder", "test.py"),
    )
    assert updates == {"path": Path(USER_DIR) / "somefolder" / "test.py"}
Пример #18
0
def test_into_folder(mock_exists, mock_samefile, mock_move, mock_trash,
                     mock_mkdir):
    basedir = Path('~')
    path = Path('~') / 'test.py'
    mock_exists.return_value = False
    mock_samefile.return_value = False
    move = Move(dest='~/somefolder/', overwrite=False)
    new_path = move.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_move.assert_called_with(src=os.path.join(USER_DIR, 'test.py'),
                                 dst=os.path.join(USER_DIR, 'somefolder',
                                                  'test.py'))
    assert new_path is not None
Пример #19
0
def test_already_exists_multiple(mock_exists, mock_samefile, mock_move,
                                 mock_trash, mock_mkdir):
    basedir = Path('~')
    path = Path('~') / 'test.py'
    mock_exists.side_effect = [True, True, True, False]
    mock_samefile.return_value = False
    move = Move(dest='~/folder/', overwrite=False)
    new_path = move.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_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
Пример #20
0
def test_into_folder(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="~/somefolder/", 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, "somefolder", "test.py"),
    )
    assert new_path is not None
Пример #21
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
Пример #22
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
Пример #23
0
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
Пример #24
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