コード例 #1
0
ファイル: test_utils.py プロジェクト: dstathis/charmcraft
def test_usefulfilepath_inaccessible(tmp_path):
    """The indicated path is not readable."""
    test_file = tmp_path / "testfile.bin"
    test_file.touch(mode=0o000)
    with pytest.raises(CommandError) as cm:
        useful_filepath(str(test_file))
    assert str(cm.value) == "Cannot access {!r}.".format(str(test_file))
コード例 #2
0
ファイル: test_utils.py プロジェクト: dstathis/charmcraft
def test_usefulfilepath_pathlib(tmp_path):
    """Convert the string to Path."""
    test_file = tmp_path / "testfile.bin"
    test_file.touch()
    path = useful_filepath(str(test_file))
    assert path == test_file
    assert isinstance(path, pathlib.Path)
コード例 #3
0
ファイル: test_utils.py プロジェクト: dstathis/charmcraft
def test_usefulfilepath_home_expanded(tmp_path, monkeypatch):
    """Home-expand the indicated path."""
    fake_home = tmp_path / "homedir"
    fake_home.mkdir()
    test_file = fake_home / "testfile.bin"
    test_file.touch()

    monkeypatch.setitem(os.environ, "HOME", str(fake_home))
    path = useful_filepath("~/testfile.bin")
    assert path == test_file
コード例 #4
0
ファイル: test_utils.py プロジェクト: dstathis/charmcraft
def test_usefulfilepath_not_a_file(tmp_path):
    """The indicated path is not a file."""
    with pytest.raises(CommandError) as cm:
        useful_filepath(str(tmp_path))
    assert str(cm.value) == "{!r} is not a file.".format(str(tmp_path))
コード例 #5
0
ファイル: test_utils.py プロジェクト: dstathis/charmcraft
def test_usefulfilepath_missing():
    """The indicated path is not there."""
    with pytest.raises(CommandError) as cm:
        useful_filepath("not_really_there.txt")
    assert str(cm.value) == "Cannot access 'not_really_there.txt'."