Ejemplo n.º 1
0
    def test_happy_path(self):
        """
        Test the happy path of operations where the parser takes the input
        and spits out a valid data particle given the stream.
        """
        self.stream_handle = StringIO(CtdpfkParserUnitTestCase.TEST_DATA)
        self.parser = CtdpfkParser(self.config, self.position, self.stream_handle,
                                  self.pos_callback, self.pub_callback) # last one is the link to the data source

        result = self.parser.get_records(1)

        self.assert_result(result, 147, self.base_timestamp, self.particle_a)
        result = self.parser.get_records(1)
        self.assert_result(result, 175, self.base_timestamp+1, self.particle_b)
        result = self.parser.get_records(1)
        self.assert_result(result, 203, self.base_timestamp+2, self.particle_c)
        result = self.parser.get_records(1)
        self.assert_result(result, 231, self.base_timestamp+3, self.particle_d)

        # no data left, dont move the position
        result = self.parser.get_records(1)
        self.assertEqual(result, [])
        self.assertEqual(self.parser._state[StateKey.POSITION], 231)
        self.assertEqual(self.position_callback_value[StateKey.POSITION], 231)
        self.assertEqual(self.position_callback_value[StateKey.TIMESTAMP],
                         self.base_timestamp+3)
        self.assert_(isinstance(self.publish_callback_value, list))
        self.assertEqual(self.publish_callback_value[0], self.particle_d)
Ejemplo n.º 2
0
 def test_mid_state_start(self):
     new_state = {StateKey.POSITION:203, StateKey.TIMESTAMP:self.base_timestamp+2}
     self.stream_handle = StringIO(CtdpfkParserUnitTestCase.TEST_DATA)
     self.parser = CtdpfkParser(self.config, new_state, self.stream_handle,
                               self.pos_callback, self.pub_callback) # last one is the link to the data source
     result = self.parser.get_records(1)
     self.assert_result(result, 231, self.base_timestamp+3, self.particle_d)
Ejemplo n.º 3
0
    def test_no_timestamp(self):
        """ There's no timestamp in the data! Ack! """
        self.stream_handle = StringIO(CtdpfkParserUnitTestCase.NO_TIME_TEST_DATA)
        self.parser = CtdpfkParser(self.config, self.position, self.stream_handle,
                                  self.pos_callback, self.pub_callback) # last one is the link to the data source

        with self.assertRaises(SampleException):
            self.parser.get_records(1)
Ejemplo n.º 4
0
    def test_bad_data(self):
        """ There's a bad sample in the data! Ack! Skip it! """
        self.stream_handle = StringIO(CtdpfkParserUnitTestCase.BAD_TEST_DATA)
        self.parser = CtdpfkParser(self.config, self.position, self.stream_handle,
                                  self.pos_callback, self.pub_callback) # last one is the link to the data source

        result = self.parser.get_records(1)
        self.assert_result(result, 205, self.base_timestamp, self.particle_a)
Ejemplo n.º 5
0
    def test_long_stream(self):
        self.stream_handle = StringIO(CtdpfkParserUnitTestCase.LONG_DATA)
        self.parser = CtdpfkParser(self.config, self.position, self.stream_handle,
                                  self.pos_callback, self.pub_callback) # last one is the link to the data source

        result = self.parser.get_records(44)
        self.assertEqual(result[-1], self.particle_z)
        self.assertEqual(self.parser._state[StateKey.POSITION], 1352)
        self.assertEqual(self.position_callback_value[StateKey.POSITION], 1352)
        self.assertEqual(self.position_callback_value[StateKey.TIMESTAMP],
                         self.base_timestamp+43)
        self.assertEqual(self.publish_callback_value[-1], self.particle_z)
Ejemplo n.º 6
0
    def _build_parser(self, parser_state, infile):
        config = self._parser_config
        config.update({
            'particle_module': 'mi.dataset.parser.ctdpfk',
            'particle_class': 'CtdpfkParserDataParticle'
        })

        self._parser = CtdpfkParser(config, parser_state, infile,
                                    self._save_parser_state,
                                    self._data_callback)

        return self._parser
Ejemplo n.º 7
0
    def test_set_state(self):
        new_state = {StateKey.POSITION:174, StateKey.TIMESTAMP:self.base_timestamp+1}
        self.stream_handle = StringIO(CtdpfkParserUnitTestCase.TEST_DATA)
        self.parser = CtdpfkParser(self.config, self.position, self.stream_handle,
                                  self.pos_callback, self.pub_callback) # last one is the link to the data source
        result = self.parser.get_records(1)
        self.assert_result(result, 147, self.base_timestamp, self.particle_a)

        self.parser.set_state(new_state)
        result = self.parser.get_records(1)
        self.assert_result(result, 218, self.base_timestamp+2, self.particle_c)
        result = self.parser.get_records(1)
        self.assert_result(result, 246, self.base_timestamp+3, self.particle_d)
Ejemplo n.º 8
0
    def test_get_many(self):
        self.stream_handle = StringIO(CtdpfkParserUnitTestCase.TEST_DATA)
        self.parser = CtdpfkParser(self.config, self.position, self.stream_handle,
                                  self.pos_callback, self.pub_callback) # last one is the link to the data source

        result = self.parser.get_records(2)
        self.assertEqual(result, [self.particle_a, self.particle_b])
        self.assertEqual(self.parser._state[StateKey.POSITION], 175)
        self.assertEqual(self.position_callback_value[StateKey.POSITION], 175)
        self.assertEqual(self.position_callback_value[StateKey.TIMESTAMP],
                         self.base_timestamp+1)
        self.assertEqual(self.publish_callback_value[0], self.particle_a)
        self.assertEqual(self.publish_callback_value[1], self.particle_b)