Skip to content

Commit

Permalink
Add subprocess in test
Browse files Browse the repository at this point in the history
  • Loading branch information
priyanshuone6 committed May 3, 2021
1 parent 9c43c3d commit 59a2fdf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Binary file removed tests/unit/test_parameters/data/test_load_param.p
Binary file not shown.
20 changes: 14 additions & 6 deletions tests/unit/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import numpy as np
import pandas as pd
import os
import subprocess
import sys
import unittest
import uuid


class TestSimulation(unittest.TestCase):
Expand Down Expand Up @@ -267,17 +270,23 @@ def test_save_load(self):

def test_load_param(self):
# Test load_sim for parameters imports
pkl_obj = pybamm.load_sim(
os.path.join(
"tests", "unit", "test_parameters", "data", "test_load_param.p"
)
)
filename = f"{uuid.uuid4()}.p"
save_sim = f"import pybamm; model = pybamm.lithium_ion.SPM(); params = pybamm.ParameterValues(chemistry=pybamm.parameter_sets.Chen2020); sim = pybamm.Simulation(model, parameter_values=params); sim.solve([0, 3600]); sim.save('{filename}')" # noqa
subprocess.run([sys.executable, "-c", save_sim])

try:
pkl_obj = pybamm.load_sim(os.path.join(filename))
except Exception as excep:
os.remove(filename)
raise excep

self.assertEqual(
"graphite_LGM50_electrolyte_exchange_current_density_Chen2020",
pkl_obj.parameter_values[
"Negative electrode exchange-current density [A.m-2]"
].__name__,
)
os.remove(filename)

def test_save_load_dae(self):
model = pybamm.lead_acid.LOQS({"surface form": "algebraic"})
Expand Down Expand Up @@ -424,7 +433,6 @@ def test_battery_model_with_input_height(self):

if __name__ == "__main__":
print("Add -v for more debug output")
import sys

if "-v" in sys.argv:
debug = True
Expand Down

0 comments on commit 59a2fdf

Please sign in to comment.