Skip to content

Commit

Permalink
#871 coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer committed Mar 21, 2020
1 parent 76d5ad7 commit 2e225bd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pybamm/quick_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def __init__(
if len(variable_tuple) == 1:
variable = variable_tuple[0]
else:
variable = list(variable_tuple)
variable = variable_tuple
try:
self.variable_limits[variable_tuple] = variable_limits[variable]
except KeyError:
Expand Down Expand Up @@ -684,7 +684,7 @@ def slider_update(self, t):
plot[i][j].set_ydata(var)
var_min = min(var_min, np.nanmin(var))
var_max = max(var_max, np.nanmax(var))
# add dashed lines for boundaries between subdomains
# update boundaries between subdomains
y_min, y_max = self.axis_limits[key][2:]
if y_min is None and y_max is None:
y_min, y_max = ax_min(var_min), ax_max(var_max)
Expand Down
8 changes: 4 additions & 4 deletions pybamm/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
def is_notebook():
try:
shell = get_ipython().__class__.__name__
if shell == "ZMQInteractiveShell":
if shell == "ZMQInteractiveShell": # pragma: no cover
# Jupyter notebook or qtconsole
cfg = get_ipython().config
nb = len(cfg['InteractiveShell'].keys()) == 0
nb = len(cfg["InteractiveShell"].keys()) == 0
return nb
elif shell == "TerminalInteractiveShell":
elif shell == "TerminalInteractiveShell": # pragma: no cover
return False # Terminal running IPython
else:
return False # Other type (?)
Expand Down Expand Up @@ -104,7 +104,7 @@ def __init__(
self.reset(update_model=False)

# ignore runtime warnings in notebooks
if is_notebook():
if is_notebook(): # pragma: no cover
import warnings

warnings.filterwarnings("ignore")
Expand Down
23 changes: 21 additions & 2 deletions tests/unit/test_quick_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,13 @@ def test_simple_ode_model(self):
pybamm.QuickPlot([solution, solution], ["2D variable"])

# Test different variable limits
quick_plot = pybamm.QuickPlot(solution, ["a"], variable_limits="tight")
quick_plot = pybamm.QuickPlot(
solution, ["a", ["c broadcasted", "c broadcasted"]], variable_limits="tight"
)
self.assertEqual(quick_plot.axis_limits[("a",)][2:], [None, None])
self.assertEqual(
quick_plot.axis_limits[("c broadcasted", "c broadcasted")][2:], [None, None]
)
quick_plot.plot(0)
quick_plot.slider_update(1)

Expand All @@ -192,8 +197,15 @@ def test_simple_ode_model(self):
quick_plot.plot(0)
quick_plot.slider_update(1)

quick_plot = pybamm.QuickPlot(solution, ["a"], variable_limits={"a": [1, 2]})
quick_plot = pybamm.QuickPlot(
solution,
["a", ["c broadcasted", "c broadcasted"]],
variable_limits={"a": [1, 2], ("c broadcasted", "c broadcasted"): [3, 4]},
)
self.assertEqual(quick_plot.axis_limits[("a",)][2:], [1, 2])
self.assertEqual(
quick_plot.axis_limits[("c broadcasted", "c broadcasted")][2:], [3, 4]
)
quick_plot.plot(0)
quick_plot.slider_update(1)

Expand All @@ -207,6 +219,13 @@ def test_simple_ode_model(self):
quick_plot.plot(0)
quick_plot.slider_update(1)

with self.assertRaisesRegex(
TypeError, "variable_limits must be 'fixed', 'tight', or a dict"
):
pybamm.QuickPlot(
solution, ["a", "b broadcasted"], variable_limits="bad variable limits"
)

# Test errors
with self.assertRaisesRegex(ValueError, "Mismatching variable domains"):
pybamm.QuickPlot(solution, [["a", "b broadcasted"]])
Expand Down

0 comments on commit 2e225bd

Please sign in to comment.