def test_add(self): obj1 = Count(contents=[np.array((10, 20))]) obj2 = Count(contents=[np.array((30, 40))]) obj3 = obj1 + obj2 np.testing.assert_equal([np.array([40, 60])], obj3.contents) self.assertIsNot(obj1, obj3) self.assertIsNot(obj1.contents, obj3.contents) self.assertIsNot(obj2, obj3) self.assertIsNot(obj2.contents, obj3.contents)
def test_add(): obj1 = Count(contents=[np.array((10, 20))]) obj2 = Count(contents=[np.array((30, 40))]) obj3 = obj1 + obj2 np.testing.assert_equal([np.array([40, 60])], obj3.contents) assert obj1 is not obj3 assert obj1.contents is not obj3.contents assert obj2 is not obj3 assert obj2.contents is not obj3.contents
def test_copy(self): obj1 = Count(contents=[np.array((10, 20))]) copy1 = copy.copy(obj1) self.assertEqual(obj1, copy1) self.assertIsNot(obj1, copy1) self.assertIsNot(obj1.contents, copy1.contents) self.assertIsNot(obj1.contents[0], copy1.contents[0])
def test_copy(): obj1 = Count(contents=[np.array((10, 20))]) copy1 = copy.copy(obj1) assert obj1 == copy1 assert obj1 is not copy1 assert obj1.contents is not copy1.contents assert obj1.contents[0] is not copy1.contents[0]
def test_radd_raise(): obj1 = Count(contents=[np.array((10, 20))]) with pytest.raises(TypeError): 1 + obj1
def test_radd(): obj1 = Count(contents=[np.array((10, 20))]) assert obj1 is not sum([obj1]) # will call 0 + obj1 assert obj1 == sum([obj1])
def test_repr(): obj = Count() repr(obj)
def test_init(kwargs, expected_contents): obj = Count(**kwargs) np.testing.assert_equal(expected_contents, obj.contents)
def test_init_val(self): obj = Count(val=()) np.testing.assert_equal([np.array([1, 1])], obj.contents)
def test_radd(self): obj1 = Count(contents=[np.array((10, 20))]) self.assertIsNot(obj1, sum([obj1])) # will call 0 + obj1 self.assertEqual(obj1, sum([obj1]))
def test_repr(self): obj = Count() repr(obj)
def test_init_contents_not_same_object(self): contents = [np.array([1, 3])] obj = Count(contents=contents) np.testing.assert_equal(contents, obj.contents) self.assertIsNot(contents, obj.contents) self.assertIsNot(contents[0], obj.contents[0])
def test_init_contents(self): obj = Count(contents=[np.array([1, 3])]) np.testing.assert_equal([np.array([1, 3])], obj.contents)
def test_init_weight(self): obj = Count(val=(), weight=10) np.testing.assert_equal([np.array([10, 100])], obj.contents)
def test_radd_raise(self): obj1 = Count(contents=[np.array((10, 20))]) self.assertRaises(TypeError, obj1.__radd__, 1)
def test_two(self): """ 1:composite |- 3:composite | |- 4:counter | |- 5:counter | |- 7:counter |- 8:counter """ keyComposer4 = KeyValueComposer(('var4', ), (Echo(), )) counts4 = Count() reader4 = Reader(keyComposer4, counts4) collector4 = Collector(MockResultsCombinationMethod()) keyComposer5 = KeyValueComposer(('var5', ), (Echo(), )) counts5 = Count() reader5 = Reader(keyComposer5, counts5) collector5 = Collector(MockResultsCombinationMethod()) keyComposer7 = KeyValueComposer(('var7', ), (Echo(), )) counts7 = Count() reader7 = Reader(keyComposer7, counts7) collector7 = Collector(MockResultsCombinationMethod()) keyComposer8 = KeyValueComposer(('var8', ), (Echo(), )) counts8 = Count() reader8 = Reader(keyComposer8, counts8) collector8 = Collector(MockResultsCombinationMethod()) reader3 = ReaderComposite() reader3.add(reader4) reader3.add(reader5) collector3 = CollectorComposite() collector3.add(collector4) collector3.add(collector5) reader1 = ReaderComposite() reader1.add(reader3) reader1.add(reader7) reader1.add(reader8) collector1 = CollectorComposite() collector1.add(collector3) collector1.add(collector7) collector1.add(collector8) reader1_ds1 = copy.deepcopy(reader1) reader1_ds2 = copy.deepcopy(reader1) reader3_ds1 = reader1_ds1.readers[0] reader4_ds1 = reader3_ds1.readers[0] reader5_ds1 = reader3_ds1.readers[1] reader7_ds1 = reader1_ds1.readers[1] reader8_ds1 = reader1_ds1.readers[2] self.assertIsInstance(reader1_ds1, ReaderComposite) self.assertIsInstance(reader3_ds1, ReaderComposite) self.assertIsInstance(reader4_ds1, Reader) self.assertIsInstance(reader5_ds1, Reader) self.assertIsInstance(reader7_ds1, Reader) self.assertIsInstance(reader8_ds1, Reader) self.assertIsNot(reader1, reader1_ds1) self.assertIsNot(reader3, reader3_ds1) self.assertIsNot(reader4, reader4_ds1) self.assertIsNot(reader5, reader5_ds1) self.assertIsNot(reader7, reader7_ds1) self.assertIsNot(reader8, reader8_ds1) reader3_ds2 = reader1_ds2.readers[0] reader4_ds2 = reader3_ds2.readers[0] reader5_ds2 = reader3_ds2.readers[1] reader7_ds2 = reader1_ds2.readers[1] reader8_ds2 = reader1_ds2.readers[2] self.assertIsInstance(reader1_ds2, ReaderComposite) self.assertIsInstance(reader3_ds2, ReaderComposite) self.assertIsInstance(reader4_ds2, Reader) self.assertIsInstance(reader5_ds2, Reader) self.assertIsInstance(reader7_ds2, Reader) self.assertIsInstance(reader8_ds2, Reader) self.assertIsNot(reader1, reader1_ds2) self.assertIsNot(reader3, reader3_ds2) self.assertIsNot(reader4, reader4_ds2) self.assertIsNot(reader5, reader5_ds2) self.assertIsNot(reader7, reader7_ds2) self.assertIsNot(reader8, reader8_ds2)
def test_init(self): obj = Count() np.testing.assert_equal([np.array([0, 0])], obj.contents)