Skip to content

Commit

Permalink
Make tests use unique output names
Browse files Browse the repository at this point in the history
  • Loading branch information
kratman committed Sep 28, 2023
1 parent d2cc3cc commit c5aa3ce
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
10 changes: 7 additions & 3 deletions tests/unit/test_batch_study.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,18 @@ def test_create_gif(self):
bs = pybamm.BatchStudy({"spm": pybamm.lithium_ion.SPM()})
bs.solve([0, 10])

# Create a temporary file name
test_stub = "batch_study_test"
test_file = f"{test_stub}.gif"

# create a GIF before calling the plot method
bs.create_gif(number_of_images=3, duration=1)
bs.create_gif(number_of_images=3, duration=1, output_filename=test_file)

# create a GIF after calling the plot method
bs.plot(testing=True)
bs.create_gif(number_of_images=3, duration=1)
bs.create_gif(number_of_images=3, duration=1, output_filename=test_file)

os.remove("plot.gif")
os.remove(test_file)


if __name__ == "__main__":
Expand Down
11 changes: 6 additions & 5 deletions tests/unit/test_plotting/test_quick_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,12 @@ def test_spm_simulation(self):
quick_plot.plot(0)

# test creating a GIF
quick_plot.create_gif(number_of_images=3, duration=3)
assert not os.path.exists("plot*.png")
assert os.path.exists("plot.gif")
os.remove("plot.gif")

test_stub = "spm_sim_test"
test_file = f"{test_stub}.gif"
quick_plot.create_gif(number_of_images=3, duration=3, output_filename=test_file)
assert not os.path.exists(f"{test_stub}*.png")
assert os.path.exists(test_file)
os.remove(test_file)
pybamm.close_plots()

def test_loqs_spme(self):
Expand Down
10 changes: 7 additions & 3 deletions tests/unit/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,18 @@ def test_create_gif(self):
sim = pybamm.Simulation(pybamm.lithium_ion.SPM())
sim.solve(t_eval=[0, 10])

# Create a temporary file name
test_stub = "test_sim"
test_file = f"{test_stub}.gif"

# create a GIF without calling the plot method
sim.create_gif(number_of_images=3, duration=1)
sim.create_gif(number_of_images=3, duration=1, output_filename=test_file)

# call the plot method before creating the GIF
sim.plot(testing=True)
sim.create_gif(number_of_images=3, duration=1)
sim.create_gif(number_of_images=3, duration=1, output_filename=test_file)

os.remove("plot.gif")
os.remove(test_file)

def test_drive_cycle_interpolant(self):
model = pybamm.lithium_ion.SPM()
Expand Down

0 comments on commit c5aa3ce

Please sign in to comment.