Exemple #1
0
def test_read_bytes():
    local = Local("usr")

    with pytest.raises(AttributeError):
        local.read_bytes("usr1")

    pth = Mock()
    pth.read_bytes.return_value = b"data"
    assert local.read_bytes(pth) == b"data"
Exemple #2
0
def test_ensure_target_root_is_cwd(path):
    path.return_value = path
    path.absolute.return_value = path
    path.is_dir.side_effect = [True]

    local = Local(".")
    path.assert_called_once()

    local.ensure_target_root()
Exemple #3
0
def test_ensure_target_root(path):
    path.return_value = path
    path.absolute.return_value = path
    path.is_dir.side_effect = [True]

    local = Local("usr")
    path.assert_called_once()

    with pytest.raises(errors.Abort):
        local.ensure_target_root()
Exemple #4
0
def test_iter_filenames(walk):
    walker = Local.iter_filenames(pathlib.Path("src"))
    assert (1, "", None) == next(walker)
    assert (1, "en", None) == next(walker)
    assert (2, "en", "to") == next(walker)
    assert (2, "en", "tre") == next(walker)
    with pytest.raises(StopIteration):
        next(walker)
Exemple #5
0
def test_write_bytes():
    local = Local("usr")

    with pytest.raises(AttributeError):
        local.write_bytes("usr1", b"data")

    pth = Mock()
    local.write_bytes(pth, b"data")
    pth.write_bytes.assert_called_once_with(b"data")
Exemple #6
0
def test_write_text():
    local = Local("usr")

    with pytest.raises(AttributeError):
        local.write_text("usr1", "data")

    pth = Mock()
    local.write_text(pth, "data")
    pth.write_text.assert_called_once_with("data")
Exemple #7
0
def test_mkdir():
    local = Local("usr")

    with pytest.raises(AttributeError):
        local.mkdir("usr1")

    pth = Mock()
    local.mkdir(pth)
    pth.mkdir.assert_called_once_with(parents=True)
Exemple #8
0
def test_joinpath():
    local = Local("usr")

    with pytest.raises(AttributeError):
        local.joinpath("usr1", "usr2", "usr3")

    pth = Mock()
    local.joinpath(pth, "usr2", "usr3")
    pth.joinpath.assert_called_once_with("usr2", "usr3")
Exemple #9
0
def test_exists():
    local = Local("usr")

    with pytest.raises(AttributeError):
        local.exists("")

    pth = Mock()
    local.exists(pth)
    pth.exists.assert_called_once()
Exemple #10
0
def test_local():
    local = Local("usr")
    assert isinstance(local.root, pathlib.Path)
Exemple #11
0
def test_ensure_target_not_exists():
    path = Mock()
    path.exists.side_effect = [False]
    local = Local("usr")
    local.ensure_target(path)
Exemple #12
0
def test_ensure_target_exists():
    path = Mock()
    path.exists.side_effect = [True]
    local = Local("usr")
    with pytest.raises(errors.Abort):
        local.ensure_target(path)