def test_iteration(self): buf = Buffer(station_id=self.station_id) buf.append(self.m1) buf.append(self.m2) buf.append(self.m3) for item in buf: self.assertTrue(isinstance(item, Measurement)) self.assertTrue(item in [self.m1, self.m2, self.m3])
def test_iteration(self): buf = Buffer(station_id=self.station_id) buf.append(self.m1) buf.append(self.m2) buf.append(self.m3) for item in buf: self.assertTrue(isinstance(item, Measurement)) self.assertTrue(item in [self.m1, self.m2, self.m3])
def test_add(self): buf1 = Buffer(station_id=self.station_id) buf1.append(self.m1) buf2 = Buffer(station_id=self.station_id) buf2.append(self.m2) buf2.append(self.m3) result = buf1 + buf2 self.assertEquals(3, len(result))
def test_add(self): buf1 = Buffer(station_id=self.station_id) buf1.append(self.m1) buf2 = Buffer(station_id=self.station_id) buf2.append(self.m2) buf2.append(self.m3) result = buf1 + buf2 self.assertEqual(3, len(result))
def test_sort_reverse_chronologically(self): ordered_reverse_chrono = [self.m2, self.m1, self.m3] buf = Buffer(station_id=self.station_id) buf.append(self.m1) buf.append(self.m2) buf.append(self.m3) self.assertNotEqual(buf.measurements, ordered_reverse_chrono) buf.sort_reverse_chronologically() self.assertEqual(buf.measurements, ordered_reverse_chrono)
def test_sort_reverse_chronologically(self): ordered_reverse_chrono = [self.m2, self.m1, self.m3] buf = Buffer(station_id=self.station_id) buf.append(self.m1) buf.append(self.m2) buf.append(self.m3) self.assertNotEqual(buf.measurements, ordered_reverse_chrono) buf.sort_reverse_chronologically() self.assertEqual(buf.measurements, ordered_reverse_chrono)
def test_empty(self): buf = Buffer(self.station_id) self.assertEqual(0, len(buf)) buf.append(self.m1) buf.append(self.m2) buf.append(self.m3) self.assertEqual(3, len(buf)) self.assertTrue(self.m1 in buf) self.assertTrue(self.m2 in buf) self.assertTrue(self.m3 in buf) buf.empty() self.assertEqual(0, len(buf))
def test_empty(self): buf = Buffer(self.station_id) self.assertEqual(0, len(buf)) buf.append(self.m1) buf.append(self.m2) buf.append(self.m3) self.assertEqual(3, len(buf)) self.assertTrue(self.m1 in buf) self.assertTrue(self.m2 in buf) self.assertTrue(self.m3 in buf) buf.empty() self.assertEqual(0, len(buf))
def test_json_persistence_backend_writes(self): with tempfile.NamedTemporaryFile() as tmp: # write file target_file = os.path.abspath(tmp.name) be = JSONPersistenceBackend(target_file, 'mytest') buffer = Buffer('mytest') buffer.append(self.measurement) be.persist_buffer(buffer) # check data with open(target_file, 'r') as f: data = f.read() items = json.loads(data) self.assertEqual(1, len(items)) msmt = items[0] self.assertTrue(all(item in msmt.items() for item in self.data_dict.items()))
def test_json_persistence_backend_writes(self): with tempfile.NamedTemporaryFile() as tmp: # write file target_file = os.path.abspath(tmp.name) be = JSONPersistenceBackend(target_file, 'mytest') buffer = Buffer('mytest') buffer.append(self.measurement) be.persist_buffer(buffer) # check data with open(target_file, 'r') as f: data = f.read() items = json.loads(data) self.assertEqual(1, len(items)) msmt = items[0] self.assertTrue(all(item in msmt.items() for item in self.data_dict.items()))
def test_append(self): buf = Buffer(self.station_id) self.assertEqual(0, len(buf)) buf.append(self.m1) self.assertEqual(1, len(buf)) self.assertTrue(self.m1 in buf) buf = Buffer(self.station_id) with self.assertRaises(AssertionError): buf.append('not_a_measurement') msmt = deepcopy(self.m1) msmt.station_id = 'another_id' with self.assertRaises(AssertionError): buf.append(msmt)
def test_append(self): buf = Buffer(self.station_id) self.assertEqual(0, len(buf)) buf.append(self.m1) self.assertEqual(1, len(buf)) self.assertTrue(self.m1 in buf) buf = Buffer(self.station_id) with self.assertRaises(AssertionError): buf.append('not_a_measurement') msmt = deepcopy(self.m1) msmt.station_id = 'another_id' with self.assertRaises(AssertionError): buf.append(msmt)
def test_send_buffer(self): instance = self.factory(MockHttpClientMeasurements) buffer = Buffer(MockHttpClientMeasurements.msmt1.station_id) buffer.append(MockHttpClientMeasurements.msmt1) instance.send_buffer(buffer)
def test_repr(self): buf = Buffer(self.station_id) buf.append(self.m2) str(buf)
def test_contains(self): buf = Buffer(station_id=self.station_id) buf.append(self.m1) self.assertFalse(self.m3 in buf) self.assertTrue(self.m1 in buf) self.assertFalse(self.m2 in buf)
def test_contains(self): buf = Buffer(station_id=self.station_id) buf.append(self.m1) self.assertFalse(self.m3 in buf) self.assertTrue(self.m1 in buf) self.assertFalse(self.m2 in buf)
def test_repr(self): buf = Buffer(self.station_id) buf.append(self.m2) str(buf)
def test_send_buffer(self): instance = self.factory(MockHttpClientMeasurements) buffer = Buffer(MockHttpClientMeasurements.msmt1.station_id) buffer.append(MockHttpClientMeasurements.msmt1) instance.send_buffer(buffer)