def test_empty(self): obj = AnywCount() event = MockEvent() obj.begin(event) event = MockEvent() self.assertFalse(obj(event)) count = obj.results() self.assertEqual([ ], count._results)
def mk_tree(): # all0 - all1 --- all2 --- sel1 # | +- sel2 # +- not1 --- any1 --- all3 --- sel3 # | +- sel4 # +- sel5 sel1 = mock.Mock(spec=MockEventSelection) sel1.name ='sel1' sel2 = mock.Mock(spec=MockEventSelection) sel2.name ='sel2' sel3 = mock.Mock(spec=MockEventSelection) sel3.name ='sel3' sel4 = mock.Mock(spec=MockEventSelection) sel4.name ='sel4' sel5 = mock.Mock(spec=MockEventSelection) sel5.name ='sel5' all0 = AllwCount(name='all0') all1 = AllwCount(name='all1') all2 = AllwCount(name='all2') all3 = AllwCount(name='all3') any1 = AnywCount(name='any1') all3.add(sel3) all3.add(sel4) any1.add(all3) any1.add(sel5) not1 = NotwCount(any1, name='not1') all2.add(sel1) all2.add(sel2) all1.add(all2) all1.add(not1) all0.add(all1) return dict( alls=(all0, all1, all2, all3), anys=(any1, ), nots=(not1, ), sels=(sel1, sel2, sel3, sel4, sel5) )
def test_any_empty(): obj = AnywCount() event = mock.Mock() obj.begin(event) assert not obj(event) obj.end() count = obj.results() assert [] == count._results
def mk_tree(): # all0 - all1 --- all2 --- sel1 # | +- sel2 # +- not1 --- any1 --- all3 --- sel3 # | +- sel4 # +- sel5 sel1 = mock.Mock(spec=MockEventSelection) sel1.name = 'sel1' sel2 = mock.Mock(spec=MockEventSelection) sel2.name = 'sel2' sel3 = mock.Mock(spec=MockEventSelection) sel3.name = 'sel3' sel4 = mock.Mock(spec=MockEventSelection) sel4.name = 'sel4' sel5 = mock.Mock(spec=MockEventSelection) sel5.name = 'sel5' all0 = AllwCount(name='all0') all1 = AllwCount(name='all1') all2 = AllwCount(name='all2') all3 = AllwCount(name='all3') any1 = AnywCount(name='any1') all3.add(sel3) all3.add(sel4) any1.add(all3) any1.add(sel5) not1 = NotwCount(any1, name='not1') all2.add(sel1) all2.add(sel2) all1.add(all2) all1.add(not1) all0.add(all1) return dict(alls=(all0, all1, all2, all3), anys=(any1, ), nots=(not1, ), sels=(sel1, sel2, sel3, sel4, sel5))
def test_any_empty(): obj = AnywCount() event = mock.Mock() obj.begin(event) assert not obj(event) obj.end() count = obj.results() assert [ ] == count._results
def test_any(method): sel1 = mock.Mock(spec=MockEventSelection) sel2 = mock.Mock(spec=MockEventSelection) sel1.name = 'sel1' sel2.name = '' if method == 1: obj = AnywCount() obj.add(sel1) obj.add(sel2) elif method == 2: obj = AnywCount(selections=[sel1, sel2]) elif method == 3: obj = AnywCount(selections=[sel1]) obj.add(sel2) event = mock.Mock() obj.begin(event) # need to set return_value each time because a selection is not # guaranteed to be called sel1.return_value = True sel2.return_value = True assert obj(event) sel1.return_value = True sel2.return_value = False assert obj(event) sel1.return_value = False sel2.return_value = True assert obj(event) sel1.return_value = False sel2.return_value = False assert not obj(event) sel1.return_value = False sel2.return_value = False assert not obj(event) obj.end() count = obj.results() assert [ [1, 'MockEventSelection', 'sel1', 2, 5], [1, 'MockEventSelection', '', 1, 3], ] == count._results
def test_any(method): sel1 = mock.Mock(spec=MockEventSelection) sel2 = mock.Mock(spec=MockEventSelection) sel1.name ='sel1' sel2.name ='' if method == 1: obj = AnywCount() obj.add(sel1) obj.add(sel2) elif method == 2: obj = AnywCount(selections=[sel1, sel2]) elif method == 3: obj = AnywCount(selections=[sel1]) obj.add(sel2) event = mock.Mock() obj.begin(event) # need to set return_value each time because a selection is not # guaranteed to be called sel1.return_value = True sel2.return_value = True assert obj(event) sel1.return_value = True sel2.return_value = False assert obj(event) sel1.return_value = False sel2.return_value = True assert obj(event) sel1.return_value = False sel2.return_value = False assert not obj(event) sel1.return_value = False sel2.return_value = False assert not obj(event) obj.end() count = obj.results() assert [ [1, 'MockEventSelection', 'sel1', 2, 5], [1, 'MockEventSelection', '', 1, 3], ] == count._results
def test_nested(self): # # any (obj) --- any (obj1) --- sel (sel11) # | +- sel (sel12) # +- any (obj2) --- sel (sel21) # | +- sel (sel22) # +- sel (sel3) # obj = AnywCount() obj1 = AnywCount('all1') obj2 = AnywCount('all2') sel3 = MockEventSelection('sel3') sel11 = MockEventSelection('sel11') sel12 = MockEventSelection('sel12') sel21 = MockEventSelection('sel21') sel22 = MockEventSelection('sel22') obj.add(obj1) obj.add(obj2) obj.add(sel3) obj1.add(sel11) obj1.add(sel12) obj2.add(sel21) obj2.add(sel22) self.assertFalse(sel11.is_begin_called) self.assertFalse(sel12.is_begin_called) self.assertFalse(sel21.is_begin_called) self.assertFalse(sel22.is_begin_called) self.assertFalse(sel3.is_begin_called) self.assertFalse(sel11.is_end_called) self.assertFalse(sel12.is_end_called) self.assertFalse(sel21.is_end_called) self.assertFalse(sel22.is_end_called) self.assertFalse(sel3.is_end_called) event = MockEvent() obj.begin(event) self.assertTrue(sel11.is_begin_called) self.assertTrue(sel12.is_begin_called) self.assertTrue(sel21.is_begin_called) self.assertTrue(sel22.is_begin_called) self.assertTrue(sel3.is_begin_called) event = MockEvent() sel11.ret = True # 1/1 sel12.ret = True # 1/1 sel21.ret = True # 1/1 sel22.ret = True # 1/1 sel3.ret = True # 1/1 self.assertTrue(obj(event)) obj.end() self.assertTrue(sel11.is_end_called) self.assertTrue(sel12.is_end_called) self.assertTrue(sel21.is_end_called) self.assertTrue(sel22.is_end_called) self.assertTrue(sel3.is_end_called) count = obj.results() self.assertEqual( [ [1, 'AnywCount', 'all1', 1, 1], [2, 'MockEventSelection', 'sel11', 1, 1], [2, 'MockEventSelection', 'sel12', 0, 0], [1, 'AnywCount', 'all2', 0, 0], [2, 'MockEventSelection', 'sel21', 0, 0], [2, 'MockEventSelection', 'sel22', 0, 0], [1, 'MockEventSelection', 'sel3', 0, 0], ], count._results )
def test_standard(self): obj = AnywCount() sel1 = MockEventSelection(name = 'sel1') sel2 = MockEventSelection() obj.add(sel1) obj.add(sel2) self.assertFalse(sel1.is_begin_called) self.assertFalse(sel2.is_begin_called) self.assertFalse(sel1.is_end_called) self.assertFalse(sel2.is_end_called) event = MockEvent() obj.begin(event) self.assertTrue(sel1.is_begin_called) self.assertTrue(sel2.is_begin_called) event = MockEvent() sel1.ret = True # 1/1 sel2.ret = True # 0/0 self.assertTrue(obj(event)) event = MockEvent() sel1.ret = True # 2/2 sel2.ret = False # 0/0 self.assertTrue(obj(event)) event = MockEvent() sel1.ret = False # 2/3 sel2.ret = True # 1/1 self.assertTrue(obj.event(event)) event = MockEvent() sel1.ret = False # 2/4 sel2.ret = False # 1/2 self.assertFalse(obj.event(event)) obj.end() self.assertTrue(sel1.is_end_called) self.assertTrue(sel2.is_end_called) count = obj.results() self.assertEqual( [ [1, 'MockEventSelection', 'sel1', 2, 4], [1, 'MockEventSelection', '', 1, 2], ], count._results )