def testSampleFirstWithStartTime(self): values = [(datetime(2016, 1, 1, 1, 1, i * 2), i * 2) for i in range(1, 20)] engine = Engine(keep_history=True) d = DataSource(engine, values) s = d.sample(timedelta(seconds=7), method=SampleMethod.First, start_time=values[2][0]) engine.start(values[0][0], values[-1][0]) first_result = s() first_expected = [ (datetime(2016, 1, 1, 1, 1, 6, 1), 6), (datetime(2016, 1, 1, 1, 1, 13, 1), 8), (datetime(2016, 1, 1, 1, 1, 20, 1), 14), (datetime(2016, 1, 1, 1, 1, 27, 1), 22), (datetime(2016, 1, 1, 1, 1, 34, 1), 28), ] self.assertEqual(first_expected, first_result)
def testSampleFirst(self): values = [(datetime(2016, 1, 1, 1, 1, i * 2), i * 2) for i in range(1, 20)] engine = Engine(keep_history=True) d = DataSource(engine, values) s = d.sample(timedelta(seconds=7), method=SampleMethod.First) engine.start(values[0][0], values[-1][0]) first_result = s() first_expected = [ (datetime(2016, 1, 1, 1, 1, 9), 2), (datetime(2016, 1, 1, 1, 1, 16), 10), (datetime(2016, 1, 1, 1, 1, 23), 16), (datetime(2016, 1, 1, 1, 1, 30), 24), (datetime(2016, 1, 1, 1, 1, 37), 30), ] self.assertEqual(first_expected, first_result)