예제 #1
0
    def test_When_all_events_are_matched_The_runner_is_removed(self):
        inst = RuleInstances('rule2', rule2, 1, self.context)
        self.assertEqual(len(inst.runners), 0)

        inst.onEvent(Event(service='tellstick', key='switch-1'))
        inst.wait()
        self.assertEqual(len(inst.runners), 1)

        inst.onEvent(Event(service='tellstick', key='switch-2'))
        inst.wait()
        self.assertEqual(len(inst.runners), 0)
예제 #2
0
    def test_When_all_events_are_matched_The_runner_is_removed(self):
        inst = RuleInstances('rule2', rule2, 1, self.context)
        self.assertEqual(len(inst.runners), 0)

        inst.onEvent(Event(service='tellstick', key='switch-1'))
        inst.wait()
        self.assertEqual(len(inst.runners), 1)

        inst.onEvent(Event(service='tellstick', key='switch-2'))
        inst.wait()
        self.assertEqual(len(inst.runners), 0)
예제 #3
0
    def test_When_event_occurs_They_are_passed_to_runner(self):
        inst = RuleInstances('rule2', rule2, 1, self.context)
        self.assertFalse( self.context.test.has_key('event-2.1-seen') )
        self.assertFalse( self.context.test.has_key('event-2.2-seen') )

        inst.onEvent(Event(service='tellstick', key='switch-1'))
        if len(inst.runners) > 0:
            inst.runners[0].wait()
        self.assertTrue( self.context.test.has_key('event-2.1-seen') )
        self.assertFalse( self.context.test.has_key('event-2.2-seen') )

        inst.onEvent(Event(service='tellstick', key='switch-2'))
        if len(inst.runners) > 0:
            inst.runners[0].wait()
        self.assertTrue( self.context.test.has_key('event-2.1-seen') )
        self.assertTrue( self.context.test.has_key('event-2.2-seen') )
예제 #4
0
    def test_When_event_occurs_They_are_passed_to_runner(self):
        inst = RuleInstances('rule2', rule2, 1, self.context)
        self.assertFalse(self.context.test.has_key('event-2.1-seen'))
        self.assertFalse(self.context.test.has_key('event-2.2-seen'))

        inst.onEvent(Event(service='tellstick', key='switch-1'))
        if len(inst.runners) > 0:
            inst.runners[0].wait()
        self.assertTrue(self.context.test.has_key('event-2.1-seen'))
        self.assertFalse(self.context.test.has_key('event-2.2-seen'))

        inst.onEvent(Event(service='tellstick', key='switch-2'))
        if len(inst.runners) > 0:
            inst.runners[0].wait()
        self.assertTrue(self.context.test.has_key('event-2.1-seen'))
        self.assertTrue(self.context.test.has_key('event-2.2-seen'))
예제 #5
0
 def test_When_maxcount_is_two_Two_and_only_two_runners_are_spawned(self):
     inst = RuleInstances('rule2', rule2, 2, self.context)
     self.assertEqual(len(inst.runners), 0)
     inst.onEvent(Event(service='tellstick', key='switch-1'))
     self.assertEqual(len(inst.runners), 1)
     inst.onEvent(Event(service='tellstick', key='switch-1'))
     self.assertEqual(len(inst.runners), 2)
     inst.onEvent(Event(service='tellstick', key='switch-1'))
     self.assertEqual(len(inst.runners), 2)
예제 #6
0
 def test_When_maxcount_is_two_Two_and_only_two_runners_are_spawned(self):
     inst = RuleInstances('rule2', rule2, 2, self.context)
     self.assertEqual(len(inst.runners), 0)
     inst.onEvent(Event(service='tellstick', key='switch-1'))
     self.assertEqual(len(inst.runners), 1)
     inst.onEvent(Event(service='tellstick', key='switch-1'))
     self.assertEqual(len(inst.runners), 2)
     inst.onEvent(Event(service='tellstick', key='switch-1'))
     self.assertEqual(len(inst.runners), 2)
예제 #7
0
 def test_When_event_not_matching_first_occur_A_new_runner_is_not_spawned(self):
     inst = RuleInstances('rule2', rule2, 1, self.context)
     self.assertEqual(len(inst.runners), 0)
     inst.onEvent(Event(service='tellstick', key='foo'))
     self.assertEqual(len(inst.runners), 0)
예제 #8
0
 def test_When_event_not_matching_first_occur_A_new_runner_is_not_spawned(
         self):
     inst = RuleInstances('rule2', rule2, 1, self.context)
     self.assertEqual(len(inst.runners), 0)
     inst.onEvent(Event(service='tellstick', key='foo'))
     self.assertEqual(len(inst.runners), 0)