def test_log_only(self): """ Test with a file that only contains dcl logs, no data, and confirm no particles are returned """ with open(os.path.join(RESOURCE_PATH, 'log_only.hyd1.log'), 'rU') as file_handle: parser = HydODclParser(file_handle, self.exception_callback, is_telemetered=True) particles = parser.get_records(10) self.assertEquals(len(particles), 0) self.assertEqual(self.exception_callback_value, [])
def test_simple_recov(self): """ Test a simple recovered case """ with open(os.path.join(RESOURCE_PATH, 'first.hyd1.log'), 'rU') as file_handle: parser = HydODclParser(file_handle, self.exception_callback, is_telemetered=False) particles = parser.get_records(8) self.assert_particles(particles, "first_recov.yml", RESOURCE_PATH) self.assertEqual(self.exception_callback_value, [])
def test_long_telem(self): """ Test with the full file and confirm the correct number of particles occurs """ with open(os.path.join(RESOURCE_PATH, '20140904.hyd1.log'), 'rU') as file_handle: parser = HydODclParser(file_handle, self.exception_callback, is_telemetered=True) # there are 813 lines in the file, but 70 are ignored so we should get 743 particles particles = parser.get_records(813) self.assertEquals(len(particles), 743) self.assertEqual(self.exception_callback_value, [])
def _build_parser(self, stream_handle): """ Build the parser for the input stream handle, no parser config is passed in :param stream_handle: The stream handle of the file to parse :return: The instantiation of the HydODclParser class """ return HydODclParser(stream_handle, self._exception_callback, is_telemetered=False)
def test_bad_format_telem(self): """ Test a file with two lines not formatted properly """ with open(os.path.join(RESOURCE_PATH, 'bad_format.hyd1.log'), 'rU') as file_handle: parser = HydODclParser(file_handle, self.exception_callback, is_telemetered=True) particles = parser.get_records(10) self.assertEquals(len(particles), 8) # particles in the file should still match the good data in first.hyd1.log, just skipping the bad lines self.assert_particles(particles, "first_telem.yml", RESOURCE_PATH) # confirm we get two exceptions, one for each bad line self.assertEqual(len(self.exception_callback_value), 2) self.assertIsInstance(self.exception_callback_value[0], SampleException) self.assertIsInstance(self.exception_callback_value[1], SampleException)