def test_init_w_keys(self): series = DataSeries(keys=set(["timestamp", "v1"])) series.add({"timestamp": self.t1, "v1": 1, "v2": 1}) result = series.get_data() self.assertEqual(1, len(result)) self.assertTrue("timestamp" in result[0]) self.assertTrue("v1" in result[0]) self.assertFalse("v2" in result[0])
def test_init_w_data(self): data_list = [{"timestamp": self.t1, "v1": 1}, {"timestamp": self.t2, "v1": 2}] series = DataSeries(keys=set(["timestamp", "v1"]), data_list=data_list) self.assertEqual(2, series.size()) result = series.get_data() self.assertEqual(2, len(result)) self.assertEqual(1, result[0]["v1"]) self.assertEqual(2, result[1]["v1"])
def test_add(self): series = DataSeries() self.assertTrue(len(series.get_data()) == 0) series.add({"timestamp": self.t1, "v1": 1, "v2": 1}) series.add({"timestamp": self.t2, "v1": 2, "v2": 2}) self.assertEqual([{'name': "'None'", "timestamp": self.t1, "v1": 1, "v2": 1}, {'name': "'None'", "timestamp": self.t2, "v1": 2, "v2": 2}], series.get_data()) series.add({"timestamp": self.t2, "v1": 3, "v2": 3}) self.assertEqual([{'name': "'None'", "timestamp": self.t1, "v1": 1, "v2": 1}, {'name': "'None'", "timestamp": self.t2, "v1": 3, "v2": 3}], series.get_data()) series.add({"timestamp": self.t3, "v1": 4, "v2": 4}) self.assertEqual([{'name': "'None'", "timestamp": self.t1, "v1": 1, "v2": 1}, {'name': "'None'", "timestamp": self.t2, "v1": 3, "v2": 3}, {'name': "'None'", "timestamp": self.t3, "v1": 4, "v2": 4}], series.get_data())
def test_get_data(self): series = DataSeries() series.add({"timestamp": self.t1, "v1": 1, "v2": 1}) series.add({"timestamp": self.t2, "v1": 2, "v2": 2}) self.assertEqual([{'name': "'None'", "timestamp": self.t1, "v1": 1, "v2": 1}, {'name': "'None'", "timestamp": self.t2, "v1": 2, "v2": 2}], series.get_data())