diff --git a/idaes/apps/grid_integration/examples/utils.py b/idaes/apps/grid_integration/examples/utils.py index 9aeb8f1fba..b3afe3d74f 100644 --- a/idaes/apps/grid_integration/examples/utils.py +++ b/idaes/apps/grid_integration/examples/utils.py @@ -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") diff --git a/idaes/apps/grid_integration/tests/test_integration.py b/idaes/apps/grid_integration/tests/test_integration.py index 808d50c5fa..57c964a24c 100644 --- a/idaes/apps/grid_integration/tests/test_integration.py +++ b/idaes/apps/grid_integration/tests/test_integration.py @@ -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): @@ -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 diff --git a/idaes/tests/prescient/test_prescient.py b/idaes/tests/prescient/test_prescient.py index 881ecc717c..1cde47e3fb 100644 --- a/idaes/tests/prescient/test_prescient.py +++ b/idaes/tests/prescient/test_prescient.py @@ -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):