def test_full(self): """ Read the entire original file, confirm the number of particles and exceptions that occur is correct """ with open(os.path.join(RESOURCE_PATH, 'nl181437.bin'), 'rb') as file_handle: parser = NutnrMParser(file_handle, self.exception_callback) # request more particles than are available particles = parser.get_records(50) # confirm we get the expected 29 particles, the last particles's header was corrupted self.assertEquals(len(particles), 29) self.assertEquals(len(self.exception_callback_value), 1) self.assertIsInstance(self.exception_callback_value[0], SampleException) # clear the exception callback for the new file self.exception_callback_value = [] with open(os.path.join(RESOURCE_PATH, 'nl181450.bin'), 'rb') as file_handle: parser = NutnrMParser(file_handle, self.exception_callback) # request more particles than are available particles = parser.get_records(100) self.assertEquals(len(particles), 88) self.assertEqual(self.exception_callback_value, [])
def test_long(self): """ Longer simple test to confirm particles can be read and compared to those in the .yml """ with open(os.path.join(RESOURCE_PATH, 'nl_long.bin'), 'rb') as file_handle: parser = NutnrMParser(file_handle, self.exception_callback) particles = parser.get_records(10) self.assert_particles(particles, "nl_long.yml", RESOURCE_PATH) self.assertEqual(self.exception_callback_value, [])
def test_simple(self): """ Simple test to confirm particles can be read and compared to those in the .yml """ with open(os.path.join(RESOURCE_PATH, "nl_short.bin"), "rb") as file_handle: parser = NutnrMParser(file_handle, self.exception_callback) particles = parser.get_records(3) self.assert_particles(particles, "nl_short.yml", RESOURCE_PATH) self.assertEqual(self.exception_callback_value, [])
def test_bad_checksum(self): """ Test a file with a bad checksum and confirm the correct particles are returned and the exception occurs """ with open(os.path.join(RESOURCE_PATH, 'nl_bad_checksum.bin'), 'rb') as file_handle: parser = NutnrMParser(file_handle, self.exception_callback) particles = parser.get_records(3) # first one has the checksum error self.assertEquals(len(particles), 2) # make sure we get the rest of the particles as expected self.assert_particles(particles, "nl_bad_checksum.yml", RESOURCE_PATH) self.assertEquals(len(self.exception_callback_value), 1) self.assertIsInstance(self.exception_callback_value[0], SampleException)
def _build_parser(self, stream_handle): return NutnrMParser(stream_handle, self._exception_callback)