Skip to content

Commit d06ab55

Browse files
committed
tests: remove use of the deprecated pkg_resources
1 parent f66d923 commit d06ab55

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

tests/util.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
1+
import atexit
12
import os
23
import shutil
4+
from contextlib import ExitStack
5+
from importlib.resources import as_file, files
36
from pathlib import Path
47

58
import pytest
6-
from pkg_resources import Requirement, ResolutionError, resource_filename
79

810

911
def get_path(filename: str) -> Path:
12+
"""Get the filepath for a given test file."""
1013
# normalizing path depending on OS or else it will cause problem when joining path
1114
filename = os.path.normpath(filename)
1215
filepath = None
1316
try:
14-
filepath = resource_filename(Requirement.parse("cwl-utils"), filename)
15-
except ResolutionError:
17+
file_manager = ExitStack()
18+
atexit.register(file_manager.close)
19+
traversable = files("cwl-utils") / filename
20+
filepath = file_manager.enter_context(as_file(traversable))
21+
except ModuleNotFoundError:
1622
pass
17-
if not filepath or not os.path.isfile(filepath):
18-
filepath = os.path.join(os.path.dirname(__file__), os.pardir, filename)
19-
return Path(filepath).resolve()
23+
if not filepath or not filepath.is_file():
24+
filepath = Path(os.path.dirname(__file__), os.pardir, filename)
25+
return filepath.resolve()
2026

2127

2228
def get_data(filename: str) -> str:

0 commit comments

Comments
 (0)