コード例 #1
0
def test_pathtype_write_not_exist_but_directory_not_writeable(fake_repository):
    """Cannot get Path of file that does not exist but directory isn't
    writeable.
    """
    os.chmod("src", 0o000)

    with pytest.raises(ArgumentTypeError):
        _util.PathType("w")("src/foo.py")
コード例 #2
0
ファイル: test_util.py プロジェクト: rscohn2/reuse-tool
def test_pathtype_write_exists_but_not_writeable(fake_repository):
    """Cannot get Path of file that exists but isn't writeable."""
    os.chmod("src/source_code.py", 0o000)

    with pytest.raises(ArgumentTypeError):
        _util.PathType("w")("src/source_code.py")

    os.chmod("src/source_code.py", 0o777)
コード例 #3
0
ファイル: test_util.py プロジェクト: rscohn2/reuse-tool
def test_pathtype_read_not_readable(fake_repository):
    """Cannot read a nonreadable file."""
    os.chmod("src/source_code.py", 0o000)

    with pytest.raises(ArgumentTypeError):
        _util.PathType("r")("src/source_code.py")

    os.chmod("src/source_code.py", 0o777)
コード例 #4
0
ファイル: test_util.py プロジェクト: fsfe/reuse-tool
def test_pathtype_read_write_only_read(empty_directory):
    """A read-only file loaded with read/write needs both permissions."""
    path = Path("foo.py")
    path.touch()

    try:
        path.chmod(0o444)

        with pytest.raises(ArgumentTypeError):
            _util.PathType("r+")("foo.py")
    finally:
        path.chmod(0o777)
コード例 #5
0
def test_pathtype_read_simple(fake_repository):
    """Get a Path to a readable file."""
    result = _util.PathType("r")("src/source_code.py")

    assert result == Path("src/source_code.py")
コード例 #6
0
def test_pathtype_invalid_mode(empty_directory):
    """Only valid modes are 'r' and 'w'."""
    with pytest.raises(ValueError):
        _util.PathType("o")
コード例 #7
0
def test_pathtype_write_directory(fake_repository):
    """Cannot write to directory."""
    with pytest.raises(ArgumentTypeError):
        _util.PathType("w")("src")
コード例 #8
0
def test_pathtype_write_exists(fake_repository):
    """Get a Path for a file that exists."""
    result = _util.PathType("w")("src/source_code.py")

    assert result == Path("src/source_code.py")
コード例 #9
0
def test_pathtype_write_not_exists(empty_directory):
    """Get a Path for a file that does not exist."""
    result = _util.PathType("w")("foo.py")

    assert result == Path("foo.py")
コード例 #10
0
def test_pathtype_read_not_exists(empty_directory):
    """Cannot read a file that does not exist."""
    with pytest.raises(ArgumentTypeError):
        _util.PathType("r")("foo.py")
コード例 #11
0
def test_pathtype_read_directory_force_file(fake_repository):
    """Cannot read a directory when a file is forced."""
    with pytest.raises(ArgumentTypeError):
        _util.PathType("r", force_file=True)("src")
コード例 #12
0
def test_pathtype_read_directory(fake_repository):
    """Get a Path to a readable directory."""
    result = _util.PathType("r")("src")

    assert result == Path("src")