def obj2(): ret = Summarizer(Summary=Sum) ret._results.update({ (2, ): Sum(contents=np.array((3.2, ))), (4, ): Sum(contents=np.array((2, ))), }) return ret
def setUp(self): self.obj1 = Summarizer(Summary=Sum) self.obj2 = Summarizer(Summary=Sum) self.obj1._results.update({ (1, ): Sum(contents=np.array((4, ))), (2, ): Sum(contents=np.array((3, ))), (3, ): Sum(contents=np.array((2, ))), }) self.obj2._results.update({ (2, ): Sum(contents=np.array((3.2, ))), (4, ): Sum(contents=np.array((2, ))), }) self.expected = { (1, ): Sum(contents=np.array((4, ))), (2, ): Sum(contents=np.array((6.2, ))), (3, ): Sum(contents=np.array((2, ))), (4, ): Sum(contents=np.array((2, ))), }
def test_add_key(self): obj = Summarizer(Summary=Sum) obj.add_key('A') expected = {'A': Sum(contents=np.array((0, )))} self.assertEqual(expected, obj.results()) obj.add_key('B') obj.add_key('C') expected = { 'A': Sum(contents=np.array((0, ))), 'B': Sum(contents=np.array((0, ))), 'C': Sum(contents=np.array((0, ))), } self.assertEqual(expected, obj.results())
def test_to_tuple_list_key_not_tuple(self): obj = Summarizer(Summary=Sum) obj.add('A', (12, )) # the keys are not a tuple obj.add(2, (20, )) # self.assertEqual([(2, 20), ('A', 12)], obj.to_tuple_list())
def test_to_tuple_list(self): obj = Summarizer(Summary=Sum) obj.add(('A', ), (12, )) obj.add(('B', ), (20, )) self.assertEqual([('A', 12), ('B', 20)], obj.to_tuple_list())
def test_key(self): obj = Summarizer(Summary=Sum) obj.add_key('A') self.assertEqual(['A'], list(obj.keys()))
def test_add(self): obj = Summarizer(Summary=Sum) obj.add('A', (12, )) expected = {'A': Sum(contents=np.array((12, )))} self.assertEqual(expected, obj.results()) obj.add('A', (23, )) expected = {'A': Sum(contents=np.array((35, )))} self.assertEqual(expected, obj.results()) obj.add('A', (10, ), weight=2) expected = {'A': Sum(contents=np.array((55, )))} self.assertEqual(expected, obj.results()) obj.add('B', (20, ), weight=3.2) expected = { 'A': Sum(contents=np.array((55, ))), 'B': Sum(contents=np.array((64.0, ))), } self.assertEqual(expected, obj.results()) return
def test_init_repr(self): obj = Summarizer(Summary=Sum) repr(obj)
def obj(): return Summarizer(Summary=Sum)