Skip to content

Commit

Permalink
updated importlib.resrouces functionality to now use *files* function…
Browse files Browse the repository at this point in the history
… instead of *path*
  • Loading branch information
azaidi06 committed Dec 13, 2024
1 parent 327d8f3 commit 4df4606
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
5 changes: 4 additions & 1 deletion idaes/apps/grid_integration/examples/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
import pandas as pd


with resources.path("idaes.tests.prescient.5bus", "__init__.py") as pkg_file:
# with resources.path("idaes.tests.prescient.5bus", "__init__.py") as pkg_file:
# prescient_5bus = Path(pkg_file).parent

with resources.as_file(resources.files("idaes.tests.prescient.5bus").joinpath("__init__.py")) as pkg_file:
prescient_5bus = Path(pkg_file).parent

# rts_gmlc_generator_dataframe = pd.read_csv("gen.csv")
Expand Down
20 changes: 14 additions & 6 deletions idaes/apps/grid_integration/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ def data_path(self) -> Path:
# we need to specify __init__.py as a workaround for Python 3.9,
# where importlib.resources.path() requires the resource to be a file
# directories are not supported and will raise an error if attempted
with resources.path("idaes.tests.prescient.5bus", "__init__.py") as pkg_file:
return Path(pkg_file).parent

### old version
# with resources.path("idaes.tests.prescient.5bus", "__init__.py") as pkg_file:
# return Path(pkg_file).parent

with resources.as_file(resources.files("idaes.tests.prescient.5bus").joinpath("__init__.py")) as pkg_file:
prescient_5bus = Path(pkg_file).parent


@pytest.mark.unit
def test_data_path_available(self, data_path: Path):
Expand All @@ -71,10 +77,12 @@ def self_scheduler_output_dir(self, tmp_path: Path) -> Path:

@pytest.fixture
def self_scheduler_plugin_path(self) -> Path:
with resources.path(
"idaes.apps.grid_integration.tests",
"self_scheduler_integration_test_plugin.py",
) as p:
# with resources.path(
# "idaes.apps.grid_integration.tests",
# "self_scheduler_integration_test_plugin.py",
# ) as p:
# return Path(p)
with resources.as_file(resources.files("idaes.apps.grid_integration.tests").joinpath("self_scheduler_integration_test_plugin.py")) as p:
return Path(p)

@pytest.mark.unit
Expand Down
7 changes: 5 additions & 2 deletions idaes/tests/prescient/test_prescient.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ def data_path(self) -> Path:
# we need to specify __init__.py as a workaround for Python 3.9,
# where importlib.resources.path() requires the resource to be a file
# directories are not supported and will raise an error if attempted
with resources.path("idaes.tests.prescient.5bus", "__init__.py") as pkg_file:
return Path(pkg_file).parent
#with resources.path("idaes.tests.prescient.5bus", "__init__.py") as pkg_file:
# return Path(pkg_file).parent

with resources.as_file(resources.files("idaes.tests.prescient.5bus").joinpath("__init__.py")) as pkg_file:
prescient_5bus = Path(pkg_file).parent

@pytest.mark.unit
def test_data_path_available(self, data_path: Path):
Expand Down

0 comments on commit 4df4606

Please sign in to comment.