Beispiel #1
0
def test_safe_path_dir(tmp_path):
    test_dir = tmp_path / "test"
    expected_dir = tmp_path / "test" / "test1" / "test2"

    safe_path = SafePath(str(test_dir))
    result_dir = safe_path.get("test1", "test2")

    assert expected_dir.is_dir()
    assert result_dir == str(expected_dir)
def test_safe_path_dir_existing_overwrite(tmp_path):
    test_dir = tmp_path / "test"

    existing_dir = tmp_path / "test" / "test1" / "test2"
    existing_dir.mkdir(parents=True)

    safe_path = SafePath(test_dir, overwrite=True)
    result_dir = safe_path.get("test1", "test2")

    assert result_dir == existing_dir
def test_safe_path_dir_existing(tmp_path):
    test_dir = tmp_path / "test"

    existing_dir = tmp_path / "test" / "test1" / "test2"
    existing_dir.mkdir(parents=True)

    expected_dir = tmp_path / "test" / "test1" / "test2 (1)"

    safe_path = SafePath(test_dir)
    result_dir = safe_path.get("test1", "test2")

    assert expected_dir.is_dir()
    assert result_dir == expected_dir
Beispiel #4
0
def test_safe_path_bad_names(tmp_path):
    test_dir = tmp_path / "test"

    expected_dir1 = tmp_path / "test" / "test1" / "test2_"
    expected_dir2 = tmp_path / "test" / "test1" / "test2_ (1)"

    safe_path = SafePath(str(test_dir))
    result_path1 = safe_path.get("test1", "test2|")
    result_path2 = safe_path.get("test1", "test2?")

    assert expected_dir1.is_dir()
    assert result_path1 == str(expected_dir1)
    assert expected_dir2.is_dir()
    assert result_path2 == str(expected_dir2)
def test_safe_path_bad_names(tmp_path):
    test_dir = tmp_path / "test"

    expected_dir1 = tmp_path / "test" / "test1" / "test2_________"
    expected_dir2 = tmp_path / "test" / "test1" / "test2_________ (1)"

    safe_path = SafePath(test_dir)
    result_path1 = safe_path.get("test1", r'test2<>:"/\|?*')
    result_path2 = safe_path.get("test1", r'test2/\|?*<>:"')

    assert expected_dir1.is_dir()
    assert result_path1 == expected_dir1
    assert expected_dir2.is_dir()
    assert result_path2 == expected_dir2