Skip to content

Commit 5fa736a

Browse files
authored
fix: Relative paths to config files [#538 & #544]. Thanks to @motybz, @MalteBecker, & @abhinav-cashify!
Fixes #538
1 parent 206d2f7 commit 5fa736a

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

openapi_python_client/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Config(BaseModel):
3737
@staticmethod
3838
def load_from_path(path: Path) -> "Config":
3939
"""Creates a Config from provided JSON or YAML file and sets a bunch of globals from it"""
40-
mime = mimetypes.guess_type(path.as_uri(), strict=True)[0]
40+
mime = mimetypes.guess_type(path.absolute().as_uri(), strict=True)[0]
4141
if mime == "application/json":
4242
config_data = json.loads(path.read_text())
4343
else:

pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ isort .\
6262
&& poetry export -f requirements.txt | poetry run safety check --bare --stdin\
6363
&& mypy openapi_python_client\
6464
&& pylint openapi_python_client\
65-
&& pytest --cov openapi_python_client tests --cov-report=term-missing\
65+
&& TASKIPY=true pytest --cov openapi_python_client tests --cov-report=term-missing --basetemp=tests/tmp\
66+
&& rm -r tests/tmp\
6667
"""
6768
regen = "python -m end_to_end_tests.regen_golden_record"
6869
e2e = "pytest openapi_python_client end_to_end_tests/test_end_to_end.py"

tests/test_config.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import json
2+
import os
3+
from pathlib import Path
24

35
import pytest
46
import yaml
@@ -19,8 +21,14 @@ def json_with_tabs(d):
1921
("example.json", json_with_tabs),
2022
],
2123
)
22-
def test_load_from_path(tmp_path, filename, dump):
24+
@pytest.mark.parametrize("relative", (True, False), ids=("relative", "absolute"))
25+
def test_load_from_path(tmp_path: Path, filename, dump, relative):
2326
yml_file = tmp_path.joinpath(filename)
27+
if relative:
28+
if not os.getenv("TASKIPY"):
29+
pytest.skip("Only test relative paths when running with `task check`")
30+
return
31+
yml_file = yml_file.relative_to(Path.cwd())
2432
override1 = {"class_name": "ExampleClass", "module_name": "example_module"}
2533
override2 = {"class_name": "DifferentClass", "module_name": "different_module"}
2634
data = {

0 commit comments

Comments
 (0)