Skip to content

Commit

Permalink
Using tempfile for standard_model_test (#4270)
Browse files Browse the repository at this point in the history
* Using tempfile for standard_model_test

Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>

* style: pre-commit fixes

---------

Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
prady0t and pre-commit-ci[bot] committed Jul 16, 2024
1 parent 4796ba9 commit 9afe45e
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions tests/integration/test_models/standard_model_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
#
import pybamm
import tests
import uuid
import tempfile

import numpy as np
import os


class StandardModelTest:
Expand Down Expand Up @@ -141,9 +140,8 @@ def test_sensitivities(self, param_name, param_value, output_name="Voltage [V]")
)

def test_serialisation(self, solver=None, t_eval=None):
# Generating unique file names to avoid race conditions when run in parallel.
unique_id = uuid.uuid4()
file_name = f"test_model_{unique_id}"
temp = tempfile.NamedTemporaryFile(prefix="test_model")
file_name = temp.name
self.model.save_model(
file_name, variables=self.model.variables, mesh=self.disc.mesh
)
Expand Down Expand Up @@ -178,8 +176,7 @@ def test_serialisation(self, solver=None, t_eval=None):
np.testing.assert_array_almost_equal(
new_solution.all_ys[x], self.solution.all_ys[x], decimal=accuracy
)

os.remove(file_name + ".json")
temp.close()

def test_all(
self, param=None, disc=None, solver=None, t_eval=None, skip_output_tests=False
Expand Down

0 comments on commit 9afe45e

Please sign in to comment.