Skip to content

Commit

Permalink
depr: 3.11: fix importlib.resources
Browse files Browse the repository at this point in the history
  • Loading branch information
kerberizer committed Sep 13, 2024
1 parent 3239da1 commit 7e013cc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/rcapi/config/app_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ def load_config():
config_dict = {}
yaml_config = os.environ.get("RAMANCHADA_API_CONFIG")
if yaml_config is None:
with resources.path('rcapi.config', 'config.yaml') as config_path:
with open(config_path, 'r') as config_file:
config_dict = yaml.safe_load(config_file)
config_path = resources.as_file(
resources.files('rcapi.config').joinpath('config.yaml')
)
with config_path as p:
with p.open() as f:
config_dict = yaml.safe_load(f)
else:
with open(yaml_config, "r") as config_file:
config_dict = yaml.safe_load(config_file)
Expand Down
11 changes: 7 additions & 4 deletions tests/test_api_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@
@pytest.fixture(scope="module")
def config_dict():
print("\nModule-level setup: Loading config or other resources")
with resources.path('rcapi.config', 'config.yaml') as config_path:
with open(config_path, 'r') as config_file:
CONFIG_DICT = yaml.safe_load(config_file)
config_path = resources.as_file(
resources.files('rcapi.config').joinpath('config.yaml')
)
with config_path as p:
with p.open() as f:
CONFIG_DICT = yaml.safe_load(f)
assert "upload_dir" in CONFIG_DICT,CONFIG_DICT
return CONFIG_DICT

Expand Down Expand Up @@ -251,4 +254,4 @@ def test_delete_noname(setup_template_dir):

def test_getmaterials():
materials = fetch_materials("nanoreg")
assert len(materials)>0
assert len(materials)>0

0 comments on commit 7e013cc

Please sign in to comment.