1+ """Shared test functions and attributes."""
2+ import atexit
13import os
4+ from contextlib import ExitStack
5+ from pathlib import Path
26from typing import Optional
37
4- from pkg_resources import Requirement , ResolutionError , resource_filename
5-
68from schema_salad import ref_resolver
9+ from schema_salad .utils import as_file , files
710
811
912def get_data (filename : str ) -> Optional [str ]:
@@ -16,18 +19,21 @@ def get_data(filename: str) -> Optional[str]:
1619 # or else it will cause problem when joining path
1720 filepath = None
1821 try :
19- filepath = resource_filename (Requirement .parse ("schema-salad" ), filename )
20- except ResolutionError :
22+ file_manager = ExitStack ()
23+ atexit .register (file_manager .close )
24+ traversable = files ("schema-salad" ) / filename
25+ filepath = file_manager .enter_context (as_file (traversable ))
26+ except ModuleNotFoundError :
2127 pass
2228 if not filepath or not os .path .isfile (filepath ):
2329 # First try to load it from the local directory, probably ``./tests/``.
24- filepath = os . path . join (os .path .dirname (__file__ ), filename )
25- if not os . path . isfile ( filepath ):
30+ filepath = Path (os .path .dirname (__file__ )) / filename
31+ if not filepath . is_file ( ):
2632 # If that didn't work, then default to tests/../${filename},
2733 # note that we return the parent as it is expected that __file__
2834 # is a test file.
29- filepath = os . path . join (os .path .dirname (__file__ ), os . pardir , filename )
30- return filepath
35+ filepath = Path (os .path .dirname (__file__ )) / ".." / filename
36+ return str ( filepath . resolve ())
3137
3238
3339def get_data_uri (resource_path : str ) -> str :
0 commit comments