def test_get_dt_arrays__hour_after_midnight(self): ''' test to check hour following midnight does not get replaced if 0 and less than 1 hour in length ''' duration = 1740 # 29 minutes year = P('Year', array=np.ma.array([2016]*duration)) month = P('Month', array=np.ma.array([8]*duration)) day = P('Day', array=np.ma.array([5]*duration)) hour = P('Hour', array=np.ma.array([0]*duration)) minute = P('Minute', array=np.ma.repeat(np.ma.arange(duration/60), 60)) second = P('Second', array=np.ma.array(np.tile(np.arange(60), duration/60))) values = {'Year': year, 'Month': month, 'Day': day, 'Hour': hour, 'Minute': minute, 'Second': second} def hdf_get(arg): return values[arg] hdf = mock.Mock() hdf.duration = duration hdf.get.side_effect = hdf_get dt_arrays = get_dt_arrays(hdf, datetime(2016, 8, 4, 23, 59, 59), datetime(2016, 8, 5, 1, 59, 59)) self.assertEqual(dt_arrays, [year.array, month.array, day.array, hour.array, minute.array, second.array])
def test_get_dt_arrays__valid_slices(self): duration = 3599 year = P('Year', array=np.ma.array([2019]*duration)) month = P('Month', array=np.ma.array([2]*duration)) day = P('Day', array=np.ma.array([1]*duration)) hour = P('Hour', array=np.ma.array([0]*duration)) minute = P('Minute', array=np.ma.repeat(np.ma.arange(duration//60), 61)[:duration]) second = P('Second', array=np.ma.array(np.tile(np.arange(60), duration//59))[:duration]) values = {'Year': year, 'Month': month, 'Day': day, 'Hour': hour, 'Minute': minute, 'Second': second} def hdf_get(arg): return values[arg] hdf = mock.Mock() hdf.duration = duration hdf.get.side_effect = hdf_get dt_arrays, precise_timestamp, dt_param_state = get_dt_arrays(hdf, datetime(2019, 1, 31, 13, 50, 40), datetime(2019, 2, 1, 1, 59, 59), valid_slices=[slice(150, 1000), slice(1500, 3000)]) self.assertTrue(len(dt_arrays[0]) == len(dt_arrays[1]) == len(dt_arrays[2]) == \ len(dt_arrays[3]) == len(dt_arrays[4]) == len(dt_arrays[5]) == duration)
def test_get_dt_arrays__valid_slices(self): duration = 3599 year = P('Year', array=np.ma.array([2019]*duration)) month = P('Month', array=np.ma.array([2]*duration)) day = P('Day', array=np.ma.array([1]*duration)) hour = P('Hour', array=np.ma.array([0]*duration)) minute = P('Minute', array=np.ma.repeat(np.ma.arange(duration//60), 60)) second = P('Second', array=np.ma.array(np.tile(np.arange(60), duration//60))) values = {'Year': year, 'Month': month, 'Day': day, 'Hour': hour, 'Minute': minute, 'Second': second} def hdf_get(arg): return values[arg] hdf = mock.Mock() hdf.duration = duration hdf.get.side_effect = hdf_get dt_arrays, precise_timestamp, dt_param_state = get_dt_arrays(hdf, datetime(2019, 1, 31, 13, 50, 40), datetime(2019, 2, 1, 1, 59, 59), valid_slices=[slice(150, 1000), slice(1500, 3000)]) self.assertTrue(len(dt_arrays[0]) == len(dt_arrays[1]) == len(dt_arrays[2]) == \ len(dt_arrays[3]) == len(dt_arrays[4]) == len(dt_arrays[5] == 2350))