예제 #1
0
def test_makedirs(mock_parent, mock_copy, mock_trash):
    copy = Copy(dest="~/some/new/folder/", overwrite=False)
    copy.run(**DEFAULT_ARGS)
    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"),
    )
예제 #2
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'))
예제 #3
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"),
    )
예제 #4
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'))
예제 #5
0
def test_already_exists_multiple(mock_exists, mock_samefile, mock_copy,
                                 mock_trash, mock_mkdir):
    mock_exists.side_effect = [True, True, True, False]
    mock_samefile.return_value = False
    copy = Copy(dest="~/folder/", overwrite=False)
    copy.run(**DEFAULT_ARGS)
    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"),
    )
예제 #6
0
def test_into_folder(mock_exists, mock_samefile, mock_copy, mock_trash,
                     mock_mkdir):
    mock_exists.return_value = False
    mock_samefile.return_value = False
    copy = Copy(dest="~/somefolder/", overwrite=False)
    copy.run(**DEFAULT_ARGS)
    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"),
    )
예제 #7
0
def test_path(mock_exists, mock_samefile, mock_copy, mock_trash, mock_mkdir):
    mock_exists.return_value = False
    mock_samefile.return_value = False
    copy = Copy(dest="~/{path.stem}/{path.suffix}/{path.name}",
                overwrite=False)
    copy.run(**DEFAULT_ARGS)
    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, "test", ".py", "test.py"),
    )
예제 #8
0
def test_tilde_expansion(mock_exists, mock_samefile, mock_copy, mock_trash,
                         mock_mkdir):
    mock_exists.return_value = False
    mock_samefile.return_value = False
    copy = Copy(dest="~/newname.py", overwrite=False)
    updates = copy.run(**DEFAULT_ARGS)
    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 updates is None
예제 #9
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'))
예제 #10
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'))
예제 #11
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'))
예제 #12
0
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
예제 #13
0
def test_path(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="~/{path.stem}/{path.suffix}/{path.name}",
                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, "test", ".py", "test.py"),
    )
예제 #14
0
def test_already_exists(mock_exists, mock_samefile, mock_copy, mock_trash,
                        mock_mkdir):
    attrs = {"basedir": Path.home(), "path": Path.home() / "test.py"}
    mock_exists.side_effect = [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 2.py"),
    )
예제 #15
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"))
예제 #16
0
def test_tilde_expansion(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='~/newname.py', overwrite=False)
    new_path = 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, 'newname.py'))
    # keep old file path
    assert new_path == None
예제 #17
0
def test_already_exists(mock_exists, mock_samefile, mock_copy, mock_trash, mock_mkdir):
    attrs = {
        'basedir': Path.home(),
        'path': Path.home() / 'test.py',
    }
    mock_exists.side_effect = [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 2.py'))
예제 #18
0
def test_path(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='~/{path.stem}/{path.suffix}/{path.name}',
                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, 'test', '.py',
                                                  'test.py'))
예제 #19
0
def test_already_exists_multiple_with_separator(mock_exists, mock_samefile,
                                                mock_copy, mock_trash,
                                                mock_mkdir):
    args = {
        "basedir": Path.home(),
        "path": Path.home() / "test_2.py",
        "simulate": False,
    }
    mock_exists.side_effect = [True, True, True, False]
    mock_samefile.return_value = False
    copy = Copy(dest="~/folder/", overwrite=False, counter_separator="_")
    copy.run(**args)
    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_2.py"),
        dst=os.path.join(USER_DIR, "folder", "test_5.py"),
    )