def test_queue_no_context(self): """Test that the queue property returns an empty list if there is no underlying context.""" qnode_mock = MagicMock() qnode_mock.queue = ["A"] rec = pu.Recorder(qnode_mock) assert rec.queue == ["A"]
def test_append_op_no_context(self): """Test that the operation is appended when no context is supplied.""" rec = pu.Recorder(None) op = qml.PauliZ(3) rec._append_op(op) assert rec._ops == [op]
def test_attribute_spoofing_error(self): """Test that the proper error is raised if attribute spoofing is attemped with no underlying QNode.""" rec = pu.Recorder(None) with pytest.raises( AttributeError, match="Attribute test of Recorder mock QNode does not exist"): rec.test
def test_append_op_calls_underlying_context(self): """Test that the underlying context is called in _append_op.""" qnode_mock = MagicMock() rec = pu.Recorder(qnode_mock) op = qml.PauliZ(3) rec._append_op(op) assert qnode_mock._append_op.call_args[0][0] == op assert rec._ops == [op]
def test_context_method_spoofing(self): """Test that unknown methods are properly relayed to the underlying context.""" class MethodMock: args = [] def construct(self, arg): self.args.append(arg) qnode_mock = MethodMock() rec = pu.Recorder(qnode_mock) rec.construct("Test") assert qnode_mock.args[0] == "Test"
def test_context_attribute_spoofing(self): """Test that unknown attributes are properly relayed to the underlying context.""" class AssignmentMock: queue = ["A"] qnode_mock = AssignmentMock() rec = pu.Recorder(qnode_mock) assert rec.queue == ["A"] assert qnode_mock.queue == ["A"] rec.queue.append("B") assert rec.queue == ["A", "B"] assert qnode_mock.queue == ["A", "B"]
def test_queue_no_context(self): """Test that the queue property returns an empty list if there is no underlying context.""" rec = pu.Recorder(None) assert rec.queue == []