コード例 #1
0
ファイル: test_events.py プロジェクト: noralsydmp/icetea
 def test_observer(self):  # pylint: disable=no-self-use
     obs = Observer()
     callback = mock.MagicMock()
     obs.observe(EventTypes.DUT_LINE_RECEIVED, callback)
     callback.assert_not_called()
     event = Event(2, "data")
     callback.assert_not_called()
     event = Event(EventTypes.DUT_LINE_RECEIVED, "data")
     callback.assert_called_once_with("data")
コード例 #2
0
ファイル: test_events.py プロジェクト: noralsydmp/icetea
 def test_resolve_data_decodefail(self):
     event_object = mock.MagicMock()
     event_callback = mock.MagicMock()
     event_flag = EventFlag()
     if IS_PYTHON3:
         event_matcher = EventMatcher(EventTypes.DUT_LINE_RECEIVED,
                                      "\x00\x00\x00\x00\x00\x00\x01\xc8", event_object,
                                      flag=event_flag, callback=event_callback)
     else:
         event_matcher = EventMatcher(EventTypes.DUT_LINE_RECEIVED,
                                      repr("\x00\x00\x00\x00\x00\x00\x01\xc8"), event_object,
                                      flag=event_flag, callback=event_callback)
     event = Event(EventTypes.DUT_LINE_RECEIVED, event_object,
                   "\x00\x00\x00\x00\x00\x00\x01\xc8")
     event_callback.assert_called_once()
     obj, = event_callback.call_args[0]
     self.assertEqual(obj.ref, event_object)
     self.assertEqual(obj.event_data, "\x00\x00\x00\x00\x00\x00\x01\xc8")
     if IS_PYTHON3:
         match_equal = "\x00\x00\x00\x00\x00\x00\x01\xc8"
     else:
         match_equal = repr("\x00\x00\x00\x00\x00\x00\x01\xc8")
     self.assertEqual(obj.match, match_equal)
     self.assertTrue(event_flag.isSet())
     event_flag.clear()
コード例 #3
0
ファイル: test_events.py プロジェクト: vijayshukla80/icetea
 def test_resolve_data_no_caller(self):
     test_object = mock.MagicMock()
     callback = mock.MagicMock()
     event_flag = EventFlag()
     eventmatcher = EventMatcher(EventTypes.DUT_LINE_RECEIVED,
                                 "test",
                                 caller=None,
                                 flag=event_flag,
                                 callback=callback)
     event = Event(EventTypes.DUT_LINE_RECEIVED, test_object, "test")
     callback.assert_called_once_with(test_object, "test")
     self.assertTrue(event_flag.isSet())
コード例 #4
0
ファイル: test_events.py プロジェクト: noralsydmp/icetea
 def test_resolve_match_data(self):
     event_object = mock.MagicMock()
     callback = mock.MagicMock()
     event_flag = EventFlag()
     event_matcher = EventMatcher(EventTypes.DUT_LINE_RECEIVED, "test", event_object,
                                  flag=event_flag, callback=callback)
     event = Event(EventTypes.DUT_LINE_RECEIVED, event_object, "test")
     callback.assert_called_once()
     obj, = callback.call_args[0]
     self.assertEqual(obj.ref, event_object)
     self.assertEqual(obj.event_data, "test")
     self.assertEqual(obj.match, "test")
     self.assertTrue(event_flag.isSet())
     event_flag.clear()
     callback.reset_mock()
     # Recreate matcher because it forgets itself once it has matched once.
     event_matcher = EventMatcher(EventTypes.DUT_LINE_RECEIVED, "regex:test*", event_object,
                                  flag=event_flag, callback=callback)
     event = Event(EventTypes.DUT_LINE_RECEIVED, event_object, "nothing")
     self.assertFalse(event_flag.isSet())
     event = Event(EventTypes.DUT_LINE_RECEIVED, event_object, "test1")
     callback.assert_called_once()
     obj, = callback.call_args[0]
     self.assertEqual(obj.ref, event_object)
     self.assertEqual(obj.event_data, "test1")
     self.assertIsInstance(obj.match, MATCH_TYPE)
     self.assertTrue(event_flag.isSet())
     event_flag.clear()
     callback.reset_mock()
     event_matcher = EventMatcher(EventTypes.DUT_LINE_RECEIVED, "regex:test:[0-9]",
                                  event_object, flag=event_flag, callback=callback)
     event = Event(EventTypes.DUT_LINE_RECEIVED, event_object, "test")
     self.assertFalse(event_flag.isSet())
     event = Event(EventTypes.DUT_LINE_RECEIVED, event_object, "test:1")
     callback.assert_called_once()
     obj, = callback.call_args[0]
     self.assertEqual(obj.ref, event_object)
     self.assertEqual(obj.event_data, "test:1")
     self.assertIsInstance(obj.match, MATCH_TYPE)
     self.assertTrue(event_flag.isSet())
コード例 #5
0
ファイル: test_events.py プロジェクト: noralsydmp/icetea
 def test_resolve_data_no_caller(self):
     event_object = mock.MagicMock()
     event_callback = mock.MagicMock()
     event_flag = EventFlag()
     event_matcher = EventMatcher(EventTypes.DUT_LINE_RECEIVED, "test",
                                  caller=None, flag=event_flag, callback=event_callback)
     event = Event(EventTypes.DUT_LINE_RECEIVED, event_object, "test")
     event_callback.assert_called_once()
     obj, = event_callback.call_args[0]
     self.assertEqual(obj.ref, event_object)
     self.assertEqual(obj.event_data, "test")
     self.assertEqual(obj.match, "test")
     self.assertTrue(event_flag.isSet())
コード例 #6
0
ファイル: test_events.py プロジェクト: vijayshukla80/icetea
 def test_resolve_match_data(self):
     test_object = mock.MagicMock()
     callback = mock.MagicMock()
     event_flag = EventFlag()
     event_matcher = EventMatcher(EventTypes.DUT_LINE_RECEIVED,
                                  "test",
                                  test_object,
                                  flag=event_flag,
                                  callback=callback)
     event = Event(EventTypes.DUT_LINE_RECEIVED, test_object, "test")
     callback.assert_called_once_with(test_object, "test")
     self.assertTrue(event_flag.isSet())
     event_flag.clear()
     callback.reset_mock()
     # Recreate matcher because it forgets itself once it has matched once.
     event_matcher = EventMatcher(EventTypes.DUT_LINE_RECEIVED,
                                  "regex:test*",
                                  test_object,
                                  flag=event_flag,
                                  callback=callback)
     event = Event(EventTypes.DUT_LINE_RECEIVED, test_object, "nothing")
     self.assertFalse(event_flag.isSet())
     event = Event(EventTypes.DUT_LINE_RECEIVED, test_object, "test1")
     callback.assert_called_once_with(test_object, "test1")
     self.assertTrue(event_flag.isSet())
     event_flag.clear()
     callback.reset_mock()
     event_matcher = EventMatcher(EventTypes.DUT_LINE_RECEIVED,
                                  "regex:test:[0-9]",
                                  test_object,
                                  flag=event_flag,
                                  callback=callback)
     event = Event(EventTypes.DUT_LINE_RECEIVED, test_object, "test")
     self.assertFalse(event_flag.isSet())
     event = Event(EventTypes.DUT_LINE_RECEIVED, test_object, "test:1")
     callback.assert_called_once_with(test_object, "test:1")
     self.assertTrue(event_flag.isSet())
コード例 #7
0
ファイル: test_events.py プロジェクト: vijayshukla80/icetea
 def test_resolve_data_decodefail(self):
     test_object = mock.MagicMock()
     callback = mock.MagicMock()
     event_flag = EventFlag()
     if IS_PYTHON3:
         event_matcher = EventMatcher(EventTypes.DUT_LINE_RECEIVED,
                                      "\x00\x00\x00\x00\x00\x00\x01\xc8",
                                      test_object,
                                      flag=event_flag,
                                      callback=callback)
     else:
         event_matcher = EventMatcher(
             EventTypes.DUT_LINE_RECEIVED,
             repr("\x00\x00\x00\x00\x00\x00\x01\xc8"),
             test_object,
             flag=event_flag,
             callback=callback)
     event = Event(EventTypes.DUT_LINE_RECEIVED, test_object,
                   "\x00\x00\x00\x00\x00\x00\x01\xc8")
     callback.assert_called_once_with(test_object,
                                      "\x00\x00\x00\x00\x00\x00\x01\xc8")
     self.assertTrue(event_flag.isSet())
     event_flag.clear()