graphrag/tests/unit/config/test_resolve_path.py
Derek Worthen 2d45ece9b6
fix setting base_dir to full paths when not using file system. (#1096)
* fix setting base_dir to full paths when not using file system.

* add general resolve_path
2024-09-04 11:33:44 -07:00

43 lines
1.3 KiB
Python

# Copyright (c) 2024 Microsoft Corporation.
# Licensed under the MIT License
from pathlib import Path
from graphrag.config.resolve_path import resolve_path
def test_resolve_path_no_timestamp_with_run_id():
path = Path("path/to/data")
result = resolve_path(path, pattern_or_timestamp_value="20240812-121000")
assert result == path
def test_resolve_path_no_timestamp_without_run_id():
path = Path("path/to/data")
result = resolve_path(path)
assert result == path
def test_resolve_path_with_timestamp_and_run_id():
path = Path("some/path/${timestamp}/data")
expected = Path("some/path/20240812/data")
result = resolve_path(path, pattern_or_timestamp_value="20240812")
assert result == expected
def test_resolve_path_with_timestamp_and_inferred_directory():
cwd = Path(__file__).parent
path = cwd / "fixtures/timestamp_dirs/${timestamp}/data"
expected = cwd / "fixtures/timestamp_dirs/20240812-120000/data"
result = resolve_path(path)
assert result == expected
def test_resolve_path_absolute():
cwd = Path(__file__).parent
path = "fixtures/timestamp_dirs/${timestamp}/data"
expected = cwd / "fixtures/timestamp_dirs/20240812-120000/data"
result = resolve_path(path, cwd)
assert result == expected
assert result.is_absolute()