Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close regression data files #2843

Merged
merged 5 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions tardis/spectrum/tests/test_spectrum_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ def simulation(
simulation.run_final()

request.cls.regression_data = RegressionData(request)
request.cls.regression_data.sync_hdf_store(simulation)
data = request.cls.regression_data.sync_hdf_store(simulation)

return simulation
yield simulation
data.close()

def get_expected_data(self, key: str):
return pd.read_hdf(self.regression_data.fpath, key)
Expand Down
12 changes: 9 additions & 3 deletions tardis/tests/fixtures/regression_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(self, request) -> None:
"--generate-reference"
)
self.fname = f"{self.fname_prefix}.UNKNOWN_FORMAT"
self.hdf_store_object = None

@property
def module_name(self):
Expand Down Expand Up @@ -161,9 +162,14 @@ def sync_hdf_store(self, tardis_module, update_fname=True):
f"Skipping test to generate regression data: {self.fpath}"
)
else:
return pd.HDFStore(self.fpath, mode="r")

# since each test function has its own regression data instance
# each test function will only have one HDFStore object
self.hdf_store_object = pd.HDFStore(self.fpath, mode="r")
return self.hdf_store_object
atharva-2001 marked this conversation as resolved.
Show resolved Hide resolved

@pytest.fixture(scope="function")
def regression_data(request):
return RegressionData(request)
regression_data_instance = RegressionData(request)
yield regression_data_instance
if regression_data_instance.hdf_store_object is not None and regression_data_instance.hdf_store_object.is_open:
regression_data_instance.hdf_store_object.close()
5 changes: 3 additions & 2 deletions tardis/tests/test_tardis_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ def simulation(
simulation.run_final()

request.cls.regression_data = RegressionData(request)
request.cls.regression_data.sync_hdf_store(simulation)
data = request.cls.regression_data.sync_hdf_store(simulation)

return simulation
yield simulation
data.close()

def get_expected_data(self, key: str):
return pd.read_hdf(self.regression_data.fpath, key)
Expand Down
3 changes: 2 additions & 1 deletion tardis/tests/test_tardis_full_formal_integral.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ def simulation(self, config, atomic_data_fname):
def test_simulation(self, simulation, request):
regression_data = RegressionData(request)
container = SimulationContainer(simulation)
regression_data.sync_hdf_store(container)
data = regression_data.sync_hdf_store(container)
data.close()

def test_j_blue_estimators(self, simulation, request):
regression_data = RegressionData(request)
Expand Down
2 changes: 2 additions & 0 deletions tardis/visualization/tools/tests/test_liv_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ def test_generate_plot_mpl(
+ str(index2)
),
)
expected.close()

def test_mpl_image(self, plotter_generate_plot_mpl, tmp_path, request):
"""
Expand Down Expand Up @@ -520,3 +521,4 @@ def test_generate_plot_ply(
rtol=0.3,
atol=3,
)
expected.close()
4 changes: 4 additions & 0 deletions tardis/visualization/tools/tests/test_sdec_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@
pd.testing.assert_frame_equal(
plot_object, expected.get(group + attribute_name)
)
expected.close()

@pytest.fixture(scope="class", params=combinations)
def plotter_generate_plot_mpl(self, request, observed_spectrum, plotter):
Expand Down Expand Up @@ -331,6 +332,7 @@
+ str(index2)
),
)
expected.close()

Check warning on line 335 in tardis/visualization/tools/tests/test_sdec_plot.py

View check run for this annotation

Codecov / codecov/patch

tardis/visualization/tools/tests/test_sdec_plot.py#L335

Added line #L335 was not covered by tests

@pytest.fixture(scope="class", params=combinations)
def plotter_generate_plot_ply(self, request, observed_spectrum, plotter):
Expand Down Expand Up @@ -416,6 +418,8 @@
data.y, expected.get(group + "y").values.flatten()
)

expected.close()

def test_mpl_image(self, plotter_generate_plot_mpl, tmp_path, request):
regression_data = RegressionData(request)
fig, _ = plotter_generate_plot_mpl
Expand Down
Loading