Exemple #1
0
def test_not_init_collector():
    sel = mock.Mock()
    obj = NotwCount(selection=sel)
    assert obj.collector is None
    col = mock.sentinel.col
    obj = NotwCount(selection=sel, collector=col)
    assert obj.collector is col
Exemple #2
0
def test_not_collector():
    sel = mock.Mock()
    obj = NotwCount(selection=sel)
    obj.collect()

    collector = mock.Mock()
    obj = NotwCount(selection=sel, collector=collector)
    result = obj.collect()
    assert [mock.call(obj)] == collector.call_args_list
    assert result is collector()
Exemple #3
0
    def test_standard(self):

        sel1 = MockEventSelection(name='sel1')
        obj = NotwCount(selection=sel1)

        self.assertFalse(sel1.is_begin_called)

        self.assertFalse(sel1.is_end_called)

        event = MockEvent()
        obj.begin(event)
        self.assertTrue(sel1.is_begin_called)

        event = MockEvent()
        sel1.ret = False  # 1/1
        self.assertTrue(obj(event))

        event = MockEvent()
        sel1.ret = True  # 1/2
        self.assertFalse(obj.event(event))

        obj.end()
        self.assertTrue(sel1.is_end_called)

        count = obj.results()
        self.assertEqual([
            [1, 'MockEventSelection', 'sel1', 1, 2],
        ], count._results)
Exemple #4
0
def test_not():
    sel1 = mock.Mock(spec=MockEventSelection)
    sel1.name = 'sel1'

    obj = NotwCount(sel1)

    event = mock.Mock()

    obj.begin(event)

    sel1.return_value = True
    assert not obj(event)

    sel1.return_value = False
    assert obj(event)

    sel1.return_value = False
    assert obj(event)

    obj.end()

    count = obj.results()
    assert [
        [1, 'MockEventSelection', 'sel1', 1, 3],
    ] == count._results
Exemple #5
0
def test_not_collector():
    sel = mock.Mock()
    obj = NotwCount(selection=sel)
    obj.collect()

    collector = mock.Mock()
    obj = NotwCount(selection=sel, collector=collector)
    result = obj.collect()
    assert [mock.call(obj)] == collector.call_args_list
    assert result is collector()
Exemple #6
0
def test_not():
    sel1 = mock.Mock(spec=MockEventSelection)
    sel1.name ='sel1'

    obj = NotwCount(sel1)

    event = mock.Mock()

    obj.begin(event)

    sel1.return_value = True
    assert not obj(event)

    sel1.return_value = False
    assert obj(event)

    sel1.return_value = False
    assert obj(event)

    obj.end()

    count = obj.results()
    assert [
        [1, 'MockEventSelection', 'sel1', 1, 3],
    ] == 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))