def test_asMicroseconds(self): secTs = data.Timestamp(5, data.TimeUnit.SECONDS) msecTs = data.Timestamp(5, data.TimeUnit.MILLISECONDS) usecTs = data.Timestamp(5, data.TimeUnit.MICROSECONDS) self.assertEqual(5000000, secTs.asMicroseconds()) self.assertEqual(5000, msecTs.asMicroseconds()) self.assertEqual(5, usecTs.asMicroseconds())
def test_fullConstructorWithTimestamps(self): ts = data.Timestamp(5, data.TimeUnit.MICROSECONDS) dp = data.DataPoint(5, timestamp=ts) self.assertEqual(5, dp._value) self.assertEqual(data.Timestamp(5, data.TimeUnit.MICROSECONDS), dp._timestamp) self.assertEqual("DataPoint{timestamp: 5, value: 5}", str(dp)) dp = data.DataPoint(5, timestamp=1443664367594000) self.assertEqual(5, dp._value) self.assertEqual( data.Timestamp(1443664367594000, data.TimeUnit.MILLISECONDS), dp._timestamp)
def test_fullConstructorWithAllTypes(self): dp = data.DataPoint(5, timestamp=10) self.assertEqual(5, dp._value) self.assertEqual(data.Timestamp(10, data.TimeUnit.MILLISECONDS), dp._timestamp) self.assertEqual("DataPoint{timestamp: 10000, value: 5}", str(dp)) dp = data.DataPoint(1443664367594000, timestamp=10) self.assertEqual(1443664367594000, dp._value) self.assertEqual(data.Timestamp(10, data.TimeUnit.MILLISECONDS), dp._timestamp) dp = data.DataPoint(5.0, timestamp=11) self.assertEqual(5.0, dp._value) self.assertEqual(data.Timestamp(11, data.TimeUnit.MILLISECONDS), dp._timestamp)
def fromTime(self, time): """Sets the from time limit for results.""" msg = "time must be an int ({} from epoch)".format( self._timeUnit.value) if Query._validIntOrRaise(time, msg): ts = data.Timestamp(time, unit=self._timeUnit) self._params["from"] = ts.asMilliseconds() return self
def test_convertDataSetToBatches(self): dummy = DummyBackend() backend = request.DummyRequester(dummy) client = self._makeTempClient(backend=backend, deviceId="fake") series = "test" vals = [0, 11, 28] ts = data.Timestamp(1) dp = iobeam.DataPoint(vals[0], timestamp=ts) client.addDataPoint(series, dp) ts = data.Timestamp(2) dp = iobeam.DataPoint(vals[1], timestamp=ts) client.addDataPoint(series, dp) self.assertEqual(1, len(client._dataset)) self.assertEqual(0, len(client._batches)) batches = client._convertDataSetToBatches() self.assertEqual(0, len(client._dataset)) self.assertEqual(1, len(batches)) for b in batches: self.assertEqual(1, len(b.columns())) self.assertEqual(series, b.columns()[0]) self.assertEqual(2, len(b))
def verify(val): try: ts = data.Timestamp(val) self.assertTrue(False) except ValueError: pass
def test_constructorRealTime(self): ts = data.Timestamp(1443664367594) # should be a long in 2.7 self.assertEqual(ts._type, data.TimeUnit.MILLISECONDS) self.assertEqual(ts.asMicroseconds(), 1443664367594000)
def test_impliedConstructor(self): ts = data.Timestamp(5) self.assertEqual(ts._type, data.TimeUnit.MILLISECONDS) self.assertEqual(ts.asMicroseconds(), 5000)
def test_explicitConstructor(self): ts = data.Timestamp(5, unit=data.TimeUnit.SECONDS) self.assertEqual(ts._type, data.TimeUnit.SECONDS) self.assertEqual(5000000, ts.asMicroseconds())