diff --git a/tests/test_lab_dev/test_circuit_components.py b/tests/test_lab_dev/test_circuit_components.py index 200479614..d8e16e417 100644 --- a/tests/test_lab_dev/test_circuit_components.py +++ b/tests/test_lab_dev/test_circuit_components.py @@ -20,6 +20,7 @@ import numpy as np import pytest +from IPython import InteractiveShell from ipywidgets import HTML, Box, HBox, VBox from mrmustard import math, settings @@ -559,6 +560,15 @@ def test_ipython_repr_invalid_obj(self, mock_display): assert isinstance(title_widget, HTML) assert isinstance(wires_widget, HTML) + @patch("mrmustard.lab_dev.circuit_components.get_ipython") + def test_ipython_repr_interactive(self, mock_ipython, capsys): + """Test the IPython repr function.""" + mock_ipython.return_value = InteractiveShell() + dgate = Dgate([1, 2], x=0.1, y=0.1).to_fock() + dgate._ipython_display_() + captured = capsys.readouterr() + assert captured.out.rstrip() == repr(dgate) + def test_serialize_default_behaviour(self): """Test the default serializer.""" name = "my_component" diff --git a/tests/test_physics/test_ansatz/test_array_ansatz.py b/tests/test_physics/test_ansatz/test_array_ansatz.py index 0879ef0fc..a9f130ec3 100644 --- a/tests/test_physics/test_ansatz/test_array_ansatz.py +++ b/tests/test_physics/test_ansatz/test_array_ansatz.py @@ -20,6 +20,7 @@ import numpy as np import pytest +from IPython import InteractiveShell from ipywidgets import HTML, HBox, Tab, VBox from plotly.graph_objs import FigureWidget @@ -261,3 +262,12 @@ def test_ipython_repr_expects_3_dims_or_less(self, mock_display): rep = ArrayAnsatz(np.random.random((1, 4, 4, 4)), batched=True) rep._ipython_display_() mock_display.assert_not_called() + + @patch("mrmustard.physics.ansatz.array_ansatz.get_ipython") + def test_ipython_repr_interactive(self, mock_ipython, capsys): + """Test the IPython repr function.""" + mock_ipython.return_value = InteractiveShell() + rep = ArrayAnsatz(np.random.random((1, 8)), batched=True) + rep._ipython_display_() + captured = capsys.readouterr() + assert captured.out.rstrip() == repr(rep) diff --git a/tests/test_physics/test_ansatz/test_polyexp_ansatz.py b/tests/test_physics/test_ansatz/test_polyexp_ansatz.py index a5a9f5f28..ed0b605e5 100644 --- a/tests/test_physics/test_ansatz/test_polyexp_ansatz.py +++ b/tests/test_physics/test_ansatz/test_polyexp_ansatz.py @@ -20,6 +20,7 @@ import numpy as np import pytest +from IPython import InteractiveShell from ipywidgets import HTML, Box, IntSlider, IntText, Stack, VBox from plotly.graph_objs import FigureWidget @@ -321,6 +322,15 @@ def test_ipython_repr_batched(self, mock_display): assert len(stack.children) == 2 assert all(box.layout.max_width == "50%" for box in stack.children) + @patch("mrmustard.physics.ansatz.polyexp_ansatz.get_ipython") + def test_ipython_repr_interactive(self, mock_ipython, capsys): + """Test the IPython repr function.""" + mock_ipython.return_value = InteractiveShell() + rep = PolyExpAnsatz(*Abc_triple(2)) + rep._ipython_display_() + captured = capsys.readouterr() + assert captured.out.rstrip() == repr(rep) + def test_matmul_barg_barg(self): triple1 = Abc_triple(3) triple2 = Abc_triple(3) diff --git a/tests/test_physics/test_wires.py b/tests/test_physics/test_wires.py index e0a537de0..e7dcab326 100644 --- a/tests/test_physics/test_wires.py +++ b/tests/test_physics/test_wires.py @@ -19,6 +19,7 @@ from unittest.mock import patch import pytest +from IPython import InteractiveShell from ipywidgets import HTML from mrmustard.physics.wires import Wires @@ -235,3 +236,12 @@ def test_ipython_repr(self, mock_display): wires._ipython_display_() [widget] = mock_display.call_args.args assert isinstance(widget, HTML) + + @patch("mrmustard.physics.wires.get_ipython") + def test_ipython_repr_interactive(self, mock_ipython, capsys): + """Test the IPython repr function.""" + mock_ipython.return_value = InteractiveShell() + wires = Wires({0}, {}, {3}, {3, 4}) + wires._ipython_display_() + captured = capsys.readouterr() + assert captured.out.rstrip() == repr(wires)