Skip to content

fix: Relative paths to config files. #544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion openapi_python_client/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Config(BaseModel):
@staticmethod
def load_from_path(path: Path) -> "Config":
"""Creates a Config from provided JSON or YAML file and sets a bunch of globals from it"""
mime = mimetypes.guess_type(path.as_uri(), strict=True)[0]
mime = mimetypes.guess_type(path.absolute().as_uri(), strict=True)[0]
if mime == "application/json":
config_data = json.loads(path.read_text())
else:
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ isort .\
&& poetry export -f requirements.txt | poetry run safety check --bare --stdin\
&& mypy openapi_python_client\
&& pylint openapi_python_client\
&& pytest --cov openapi_python_client tests --cov-report=term-missing\
&& TASKIPY=true pytest --cov openapi_python_client tests --cov-report=term-missing --basetemp=tests/tmp\
&& rm -r tests/tmp\
"""
regen = "python -m end_to_end_tests.regen_golden_record"
e2e = "pytest openapi_python_client end_to_end_tests/test_end_to_end.py"
Expand Down
10 changes: 9 additions & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import json
import os
from pathlib import Path

import pytest
import yaml
Expand All @@ -19,8 +21,14 @@ def json_with_tabs(d):
("example.json", json_with_tabs),
],
)
def test_load_from_path(tmp_path, filename, dump):
@pytest.mark.parametrize("relative", (True, False), ids=("relative", "absolute"))
def test_load_from_path(tmp_path: Path, filename, dump, relative):
yml_file = tmp_path.joinpath(filename)
if relative:
if not os.getenv("TASKIPY"):
pytest.skip("Only test relative paths when running with `task check`")
return
yml_file = yml_file.relative_to(Path.cwd())
override1 = {"class_name": "ExampleClass", "module_name": "example_module"}
override2 = {"class_name": "DifferentClass", "module_name": "different_module"}
data = {
Expand Down