1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
import sys
from pathlib import Path
import pytest
from strawberry.exceptions.exception_source import ExceptionSource
pytestmark = pytest.mark.skipif(
sys.platform == "win32", reason="Test is meant to run on Unix systems"
)
def test_returns_relative_path(mocker):
mocker.patch.object(Path, "cwd", return_value="/home/user/project/")
source = ExceptionSource(
path=Path("/home/user/project/src/main.py"),
code="",
start_line=1,
end_line=1,
error_line=1,
error_column=1,
error_column_end=1,
)
assert source.path_relative_to_cwd == Path("src/main.py")
def test_returns_relative_path_when_is_already_relative():
source = ExceptionSource(
path=Path("src/main.py"),
code="",
start_line=1,
end_line=1,
error_line=1,
error_column=1,
error_column_end=1,
)
assert source.path_relative_to_cwd == Path("src/main.py")
|