示例#1
0
def test_keep_name(mock_exists, mock_samefile, mock_rename, mock_trash):
    args = {
        "basedir": Path.home(),
        "path": Path.home() / "test.pdf",
        "simulate": False
    }
    mock_exists.return_value = True
    mock_samefile.return_value = True
    rename = Rename(name="{path.stem}.pdf", overwrite=False)
    new_path = rename.run(**args)
    assert mock_exists.call_count > 0
    mock_trash.assert_not_called()
    mock_rename.assert_not_called()
    assert new_path is not None
示例#2
0
def test_overwrite_samefile(mock_exists, mock_samefile, mock_rename,
                            mock_trash):
    args = {
        "basedir": Path.home(),
        "path": Path.home() / "test.PDF",
        "simulate": False
    }
    mock_exists.return_value = True
    mock_samefile.return_value = True
    rename = Rename(name="{path.stem}.pdf", overwrite=False)
    new_path = rename.run(**args)
    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
示例#3
0
def test_args(mock_exists, mock_samefile, mock_rename, mock_trash):
    args = {
        "basedir": Path.home(),
        "path": Path.home() / "test.py",
        "nr": {
            "upper": 1
        },
        "simulate": False,
    }

    mock_exists.return_value = False
    mock_samefile.return_value = False
    rename = Rename(name="{nr.upper}-{path.stem} Kopie.py")
    new_path = rename.run(**args)
    assert mock_exists.call_count > 0
    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_args(mock_exists, mock_samefile, mock_copy, mock_trash, mock_mkdir):
    args = {
        "basedir": Path.home(),
        "path": Path.home() / "test.py",
        "simulate": False,
        "nr": {
            "upper": 1
        },
    }
    mock_exists.return_value = False
    mock_samefile.return_value = False
    copy = Copy(dest="~/{nr.upper}-name.py", overwrite=False)
    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.py"),
                                 dst=os.path.join(USER_DIR, "1-name.py"))
示例#5
0
def test_tilde_expansion(mock_exists, mock_samefile, mock_rename, mock_trash):
    mock_exists.return_value = False
    mock_samefile.return_value = False
    rename = Rename(name="newname.py", overwrite=False)
    new_path = rename.run(**ARGS)
    assert mock_exists.call_count > 0
    mock_trash.assert_not_called()
    expected_path = (Path.home() / "newname.py").expanduser()
    mock_rename.assert_called_with(expected_path)
    assert new_path == expected_path
示例#6
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"),
    )
示例#7
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
示例#8
0
import os

from organize.actions import Rename
from organize.compat import Path

USER_DIR = os.path.expanduser("~")

ARGS = {
    "basedir": Path.home(),
    "path": Path.home() / "test.py",
    "simulate": False
}


def test_tilde_expansion(mock_exists, mock_samefile, mock_rename, mock_trash):
    mock_exists.return_value = False
    mock_samefile.return_value = False
    rename = Rename(name="newname.py", overwrite=False)
    new_path = rename.run(**ARGS)
    assert mock_exists.call_count > 0
    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(mock_exists, mock_samefile, mock_rename, mock_trash):
    mock_exists.return_value = True
    mock_samefile.return_value = False
    rename = Rename(name="{path.stem} Kopie.py", overwrite=True)
    new_path = rename.run(**ARGS)
示例#9
0
def test_print_substitution():
    with patch.object(Python, "print") as mock_print:
        python = Python("print('Hello World')")
        python.run(path=Path.home(), simulate=False)
        mock_print.assert_called_with("Hello World")
示例#10
0
def test_trash(mock_trash):
    trash = Trash()
    trash.run(path=Path.home() / "this" / "file.tar.gz", simulate=False)
    mock_trash.assert_called_with(os.path.join(USER_DIR, "this",
                                               "file.tar.gz"))
示例#11
0
def test_shell_basic():
    with patch("subprocess.call") as m:
        shell = Shell("echo 'Hello World'")
        shell.run(path=Path.home(), simulate=False)
        m.assert_called_with("echo 'Hello World'", shell=True)
示例#12
0
def test_shell_args():
    with patch("subprocess.call") as m:
        shell = Shell("echo {year}")
        shell.run(path=Path.home(), year=2017, simulate=False)
        m.assert_called_with("echo 2017", shell=True)