Skip to content
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

Fix test expectation #166

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"jsonschema",
"pyyaml",
"typing-extensions",
"importlib-resources",
]


Expand Down
14 changes: 11 additions & 3 deletions swagger_spec_validator/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@
from urllib.request import urlopen

import yaml
import importlib.resources

try:
from importlib.resources import files # type: ignore
from importlib.resources import as_file # type: ignore
except ImportError: # pragma: cover
from importlib_resources import files
from importlib_resources import as_file


from typing_extensions import ParamSpec

try:
Expand Down Expand Up @@ -55,8 +63,8 @@ def read_file(file_path: str) -> dict[str, Any]:

@lru_cache()
def read_resource_file(resource_path: str) -> tuple[dict[str, Any], str]:
ref = importlib.resources.files('swagger_spec_validator') / resource_path
with importlib.resources.as_file(ref) as path:
ref = files("swagger_spec_validator") / resource_path
with as_file(ref) as path:
return read_file(path), path


Expand Down
10 changes: 6 additions & 4 deletions tests/common_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import importlib.resources
import uuid
from unittest import mock

import importlib.resources
try:
from importlib.resources import files # ignore: type
except ImportError: # pragma: cover
from importlib_resources import files # ignore: type

from swagger_spec_validator.common import read_file
from swagger_spec_validator.common import read_resource_file
Expand All @@ -18,6 +22,4 @@ def test_read_resource_file(monkeypatch):
read_resource_file(resource_path)
read_resource_file(resource_path)

m.assert_called_once_with(
importlib.resources.files("swagger_spec_validator")
)
m.assert_called_once_with(files("swagger_spec_validator") / resource_path)
Loading