def test_get_many(self): """ Read test data from the file and pull out multiple data particles at one time. Assert that the results are those we expected. """ with open(os.path.join(RESOURCE_PATH, 'node59p1_1.ctdmo.dat'), 'rb') as stream_handle: parser = CtdmoGhqrSioTelemeteredParser(self.config, stream_handle, self.exception_callback) particles = parser.get_records(10) particles2 = parser.get_records(10) self.assertEquals(len(particles2), 10) particles.extend(particles2) particles3 = parser.get_records(10) # 24 records total, should only have 4 remaining at this point self.assertEquals(len(particles3), 4) particles.extend(particles3) self.assert_particles(particles, 'node59p1_1.ctdmo.yml', RESOURCE_PATH) self.assertEqual(self.exception_callback_value, [])
def test_simple(self): """ Read test data from the file and assert that the results are those we expected. """ with open(os.path.join(RESOURCE_PATH, 'node59p1_2.ctdmo.dat'), 'rb') as stream_handle: parser = CtdmoGhqrSioTelemeteredParser(self.config, stream_handle, self.exception_callback) particles = parser.get_records(12) self.assertEqual(len(particles), 12) self.assert_particles(particles, 'node59p1_2.ctdmo.yml', RESOURCE_PATH) self.assertEqual(self.exception_callback_value, [])
def test_co_and_ct(self): """ Test with both co and ct particle types verified """ with open(os.path.join(RESOURCE_PATH, 'node59p1_3.ctdmo.dat'), 'rb') as stream_handle: parser = CtdmoGhqrSioTelemeteredParser(self.config, stream_handle, self.exception_callback) particles = parser.get_records(24) self.assertEqual(len(particles), 24) self.assert_particles(particles, 'node59p1_3.ctdmo.yml', RESOURCE_PATH) self.assertEqual(self.exception_callback_value, [])
def test_long_stream(self): """ Test a long file and confirm the number of particles is correct """ with open(os.path.join(RESOURCE_PATH, 'node59p1_0.ctdmo.dat'), 'rb') as stream_handle: parser = CtdmoGhqrSioTelemeteredParser(self.config, stream_handle, self.exception_callback) # require more records than are available in the file result = parser.get_records(2000) # confirm we only get the number in the file (10 CO * 12/block = 120, 129 CT blocks * 12/block = 1548) self.assertEqual(len(result), 1668) self.assertEqual(self.exception_callback_value, [])
def test_get_many(self): """ Read test data from the file and pull out multiple data particles at one time. Assert that the results are those we expected. """ with open(os.path.join(RESOURCE_PATH, 'node59p1_1.ctdmo.dat'), 'rb') as stream_handle: parser = CtdmoGhqrSioTelemeteredParser(self.config, stream_handle, self.exception_callback) particles = parser.get_records(10) particles2 = parser.get_records(10) self.assertEquals(len(particles2), 10) particles.extend(particles2) particles3 = parser.get_records(10) # 24 records total, should only have 4 remaining at this point self.assertEquals(len(particles3), 4) particles.extend(particles3) self.assert_particles(particles, 'node59p1_1.ctdmo.yml', RESOURCE_PATH) self.assertEqual(self.exception_callback_value, [])
def test_unexpected_data(self): """ Read test data from the file including unexpected data. Assert that the results are those we expected and an exception occurs. """ with open(os.path.join(RESOURCE_PATH, 'node59p1_1.bad.ctdmo.dat'), 'rb') as stream_handle: parser = CtdmoGhqrSioTelemeteredParser(self.config, stream_handle, self.exception_callback) particles = parser.get_records(24) self.assertEqual(len(particles), 24) self.assert_particles(particles, 'node59p1_1.ctdmo.yml', RESOURCE_PATH) self.assertEqual(len(self.exception_callback_value), 1) self.assert_(isinstance(self.exception_callback_value[0], UnexpectedDataException))
def test_simple(self): """ Read test data from the file and assert that the results are those we expected. """ with open(os.path.join(RESOURCE_PATH, 'node59p1_2.ctdmo.dat'), 'rb') as stream_handle: parser = CtdmoGhqrSioTelemeteredParser(self.config, stream_handle, self.exception_callback) particles = parser.get_records(12) self.assertEqual(len(particles), 12) self.assert_particles(particles, 'node59p1_2.ctdmo.yml', RESOURCE_PATH) self.assertEqual(self.exception_callback_value, [])
def test_long_stream(self): """ Test a long file and confirm the number of particles is correct """ with open(os.path.join(RESOURCE_PATH, 'node59p1_0.ctdmo.dat'), 'rb') as stream_handle: parser = CtdmoGhqrSioTelemeteredParser(self.config, stream_handle, self.exception_callback) # require more records than are available in the file result = parser.get_records(2000) # confirm we only get the number in the file (10 CO * 12/block = 120, 129 CT blocks * 12/block = 1548) self.assertEqual(len(result), 1668) self.assertEqual(self.exception_callback_value, [])
def test_co_and_ct(self): """ Test with both co and ct particle types verified """ with open(os.path.join(RESOURCE_PATH, 'node59p1_3.ctdmo.dat'), 'rb') as stream_handle: parser = CtdmoGhqrSioTelemeteredParser(self.config, stream_handle, self.exception_callback) particles = parser.get_records(24) self.assertEqual(len(particles), 24) self.assert_particles(particles, 'node59p1_3.ctdmo.yml', RESOURCE_PATH) self.assertEqual(self.exception_callback_value, [])
def test_unexpected_data(self): """ Read test data from the file including unexpected data. Assert that the results are those we expected and an exception occurs. """ with open(os.path.join(RESOURCE_PATH, 'node59p1_1.bad.ctdmo.dat'), 'rb') as stream_handle: parser = CtdmoGhqrSioTelemeteredParser(self.config, stream_handle, self.exception_callback) particles = parser.get_records(24) self.assertEqual(len(particles), 24) self.assert_particles(particles, 'node59p1_1.ctdmo.yml', RESOURCE_PATH) self.assertEqual(len(self.exception_callback_value), 1) self.assert_( isinstance(self.exception_callback_value[0], UnexpectedDataException))