def test_chain(self): trafos = TransformationStub(), TransformationStub() trafo = TransformationStub() chained = ChainedTransformation(*trafos) with mock.patch( 'qupulse._program.transformation.chain_transformations', return_value='asd') as chain_transformations: self.assertEqual(chained.chain(trafo), 'asd') chain_transformations.assert_called_once_with(*trafos, trafo)
def test_denesting(self): trafo = TransformationStub() chained = ChainedTransformation(TransformationStub(), TransformationStub()) expected = ChainedTransformation(trafo, *chained.transformations, trafo) result = chain_transformations(trafo, chained, trafo) self.assertEqual(expected, result)
def test_get_output_channels(self): trafos = TransformationStub(), TransformationStub( ), TransformationStub() chained = ChainedTransformation(*trafos) chans = {1}, {2}, {3} with mock.patch.object(trafos[0], 'get_output_channels', return_value=chans[0]) as get_output_channels_0,\ mock.patch.object(trafos[1], 'get_output_channels', return_value=chans[1]) as get_output_channels_1,\ mock.patch.object(trafos[2], 'get_output_channels', return_value=chans[2]) as get_output_channels_2: outs = chained.get_output_channels({0}) self.assertIs(outs, chans[2]) get_output_channels_0.assert_called_once_with({0}) get_output_channels_1.assert_called_once_with({1}) get_output_channels_2.assert_called_once_with({2})
def test_call(self): trafos = TransformationStub(), TransformationStub( ), TransformationStub() chained = ChainedTransformation(*trafos) time = np.arange(12) data = (np.arange(12.) + 1).reshape((3, 4)) data_in = dict(zip('abc', data)) data_0 = dict(zip('abc', data + 42)) data_1 = dict(zip('abc', data + 2 * 42)) data_2 = dict(zip('abc', data + 3 * 42)) with mock.patch( 'tests._program.transformation_tests.TransformationStub.__call__', side_effect=[data_0, data_1, data_2]) as call: outs = chained(time, data_in) self.assertIs(outs, data_2) self.assertEqual(call.call_count, 3) for ((time_arg, data_arg), kwargs), expected_data in zip(call.call_args_list, [data_in, data_0, data_1]): self.assertEqual(kwargs, {}) self.assertIs(time, time_arg) self.assertIs(expected_data, data_arg)
def test_init_and_properties(self): trafos = TransformationStub(), TransformationStub( ), TransformationStub() chained = ChainedTransformation(*trafos) self.assertEqual(chained.transformations, trafos) self.assertIs(chained.transformations, chained.compare_key)
def test_chaining(self): trafo = TransformationStub() expected = ChainedTransformation(trafo, trafo) result = chain_transformations(trafo, IdentityTransformation(), trafo) self.assertEqual(result, expected)
def test_constant_propagation(self): trafo = ChainedTransformation(ScalingTransformation({'a': 1.1}), OffsetTransformation({'b': 6.6})) self.assertTrue(trafo.is_constant_invariant()) trafo = ChainedTransformation(ScalingTransformation({'a': 1.1}), TransformationStub()) self.assertFalse(trafo.is_constant_invariant())
def test_repr(self): trafo = ChainedTransformation(ScalingTransformation({'a': 1.1}), OffsetTransformation({'b': 6.6})) self.assertEqual(trafo, eval(repr(trafo)))