Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timmysilv committed Dec 6, 2024
1 parent bf5d99a commit c0fc9ac
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/test_lab_dev/test_circuit_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions tests/test_physics/test_ansatz/test_array_ansatz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
10 changes: 10 additions & 0 deletions tests/test_physics/test_ansatz/test_polyexp_ansatz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_physics/test_wires.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit c0fc9ac

Please sign in to comment.