def test_timestamps_in_past(self, hdf_file_patch, sha_hash_file_patch, logger_patch): # No longer raising exception, using epoch instead with exception logging, # allows segment to be created. # example where it goes fast #seg = append_segment_info('old timestamps', 'START_AND_STOP', # slice(10,1000), 4, # fallback_dt=datetime(2012,12,12,0,0,0)) #self.assertEqual(seg.start_dt, datetime(2012,12,12,0,0,0)) #self.assertEqual(seg.go_fast_dt, datetime(2012,12,12,0,6,52)) #self.assertEqual(seg.stop_dt, datetime(2012,12,12,11,29,56)) append_segment_info('invalid timestamps', 'START_AND_STOP', slice(10, 1000), 4, fallback_dt=datetime(2009, 12, 12, 0, 0, 0, tzinfo=pytz.utc)) self.assertTrue(logger_patch.exception.called) self.assertEqual(logger_patch.exception.call_args[0], ( 'Unable to calculate timebase, using 1970-01-01 00:00:00+0000!', ))
def test_timestamps_in_past(self, hdf_file_patch, sha_hash_file_patch, logger_patch): # No longer raising exception, using epoch instead with exception logging, # allows segment to be created. # example where it goes fast #seg = append_segment_info('old timestamps', 'START_AND_STOP', # slice(10,1000), 4, # fallback_dt=datetime(2012,12,12,0,0,0)) #self.assertEqual(seg.start_dt, datetime(2012,12,12,0,0,0)) #self.assertEqual(seg.go_fast_dt, datetime(2012,12,12,0,6,52)) #self.assertEqual(seg.stop_dt, datetime(2012,12,12,11,29,56)) append_segment_info( 'invalid timestamps', 'START_AND_STOP', slice(10, 1000), 4, fallback_dt=datetime(2009, 12, 12, 0, 0, 0, tzinfo=pytz.utc)) self.assertTrue(logger_patch.exception.called) self.assertEqual(logger_patch.exception.call_args[0], ('Unable to calculate timebase, using 1970-01-01 00:00:00+0000!',))
def test_timestamps_in_future_use_fallback_year(self, hdf_file_patch, sha_hash_file_patch): # Using fallback time is no longer recommended example where it goes fast seg = append_segment_info('future timestamps', 'START_AND_STOP', slice(10, 1000), 4, fallback_dt=datetime(2012, 12, 12, 0, 0, 0, tzinfo=pytz.utc)) self.assertEqual(seg.start_dt, datetime(2012, 12, 25, 0, 0, 0, tzinfo=pytz.utc)) self.assertEqual(seg.go_fast_dt, datetime(2012, 12, 25, 0, 6, 52, tzinfo=pytz.utc)) self.assertEqual(seg.stop_dt, datetime(2012, 12, 25, 11, 29, 56, tzinfo=pytz.utc))
def test_invalid_datetimes(self, hdf_file_patch, sha_hash_file_patch, logger_patch): # No longer raising exception, using epoch instead #seg = append_segment_info('invalid timestamps', 'START_AND_STOP', slice(10,110), 2) seg = append_segment_info('invalid timestamps', 'START_AND_STOP', slice(28000, 34000), 6) self.assertEqual(seg.start_dt, datetime(1970, 1, 1, 0, 0, tzinfo=pytz.utc)) # start of time! self.assertEqual(seg.go_fast_dt, datetime(1970, 1, 1, 0, 6, 52, tzinfo=pytz.utc)) # went fast self.assertTrue(logger_patch.exception.called) self.assertEqual(logger_patch.exception.call_args[0], ('Unable to calculate timebase, using 1970-01-01 00:00:00+0000!',))
def test_timestamps_in_future_use_fallback_year(self, hdf_file_patch, sha_hash_file_patch): # Using fallback time is no longer recommended # example where it goes fast seg = append_segment_info('future timestamps', 'START_AND_STOP', slice(10, 1000), 4, fallback_dt=datetime(2012, 12, 12, 0, 0, 0, tzinfo=pytz.utc)) self.assertEqual(seg.start_dt, datetime(2012, 12, 25, 0, 0, 0, tzinfo=pytz.utc)) self.assertEqual(seg.go_fast_dt, datetime(2012, 12, 25, 0, 6, 52, tzinfo=pytz.utc)) self.assertEqual(seg.stop_dt, datetime(2012, 12, 25, 11, 29, 56, tzinfo=pytz.utc))
def test_append_segment_info(self, hdf_file_patch, sha_hash_file_patch): # example where it goes fast # TODO: Increase slice to be realitic for duration of data seg = append_segment_info('fast', 'START_AND_STOP', slice(10, 1000), 4) self.assertEqual(seg.path, 'fast') self.assertEqual(seg.part, 4) self.assertEqual(seg.type, 'START_AND_STOP') self.assertEqual(seg.start_dt, datetime(2012, 12, 25, 0, 0, 0, tzinfo=pytz.utc)) self.assertEqual(seg.go_fast_dt, datetime(2012, 12, 25, 0, 6, 52, tzinfo=pytz.utc)) self.assertEqual(seg.stop_dt, datetime(2012, 12, 25, 11, 29, 56, tzinfo=pytz.utc))
def test_append_segment_info(self, hdf_file_patch, sha_hash_file_patch): # example where it goes fast # TODO: Increase slice to be realitic for duration of data seg = append_segment_info('fast', 'START_AND_STOP', slice(10,1000), 4) self.assertEqual(seg.path, 'fast') self.assertEqual(seg.part, 4) self.assertEqual(seg.type, 'START_AND_STOP') self.assertEqual(seg.start_dt, datetime(2012,12,25,0,0,0)) self.assertEqual(seg.go_fast_dt, datetime(2012,12,25,0,6,52)) self.assertEqual(seg.stop_dt, datetime(2012,12,25,11,29,56))
def test_append_segment_info_no_gofast(self, hdf_file_patch, sha_hash_file_patch): sha_hash_file_patch.return_value = 'ABCDEFG' # example where it does not go fast seg = append_segment_info('slow', 'GROUND_ONLY', slice(10, 110), 1) self.assertEqual(seg.path, 'slow') self.assertEqual(seg.go_fast_dt, None) # didn't go fast self.assertEqual(seg.start_dt, datetime(2012, 12, 25, 0, 0, 0, tzinfo=pytz.utc)) # still has a start self.assertEqual(seg.part, 1) self.assertEqual(seg.type, 'GROUND_ONLY') self.assertEqual(seg.hash, 'ABCDEFG') # taken from the "file" self.assertEqual(seg.stop_dt, datetime(2012, 12, 25, 0, 0, 50, tzinfo=pytz.utc)) # +50 seconds of airspeed
def test_append_segment_info_no_gofast(self, hdf_file_patch, sha_hash_file_patch): sha_hash_file_patch.return_value = 'ABCDEFG' # example where it does not go fast seg = append_segment_info('slow', 'GROUND_ONLY', slice(10,110), 1) self.assertEqual(seg.path, 'slow') self.assertEqual(seg.go_fast_dt, None) # didn't go fast self.assertEqual(seg.start_dt, datetime(2012,12,25,0,0,0)) # still has a start self.assertEqual(seg.part, 1) self.assertEqual(seg.type, 'GROUND_ONLY') self.assertEqual(seg.hash, 'ABCDEFG') # taken from the "file" self.assertEqual(seg.stop_dt, datetime(2012,12,25,0,0,50)) # +50 seconds of airspeed