def test_load(self): cbd = CitiBikeData(load_on_init=False) self.assert_data_not_loaded(cbd) with open(self.test_data_filename) as f: cbd.load(f) self.assert_data_loaded(cbd)
def test_dump(self): cbd1 = CitiBikeData(source_url=self.test_data_url) self.assert_data_loaded(cbd1) js = StringIO() cbd1.dump(js) self.assert_data_loaded(cbd1) self.assertGreater(len(js.getvalue()), 0) js.reset() cbd2 = CitiBikeData(load_on_init=False) self.assert_data_not_loaded(cbd2) cbd2.load(js) self.assert_data_loaded(cbd2) self.assertDictEqual(cbd1.json, cbd2.json) ntf = NamedTemporaryFile(delete=False) cbd1.dump(ntf) self.assert_data_loaded(cbd1) self.assertGreater(len(js.getvalue()), 0) ntf.close() cbd3 = CitiBikeData(source_url="file:"+ntf.name) self.assert_data_loaded(cbd3) self.assertDictEqual(cbd1.json, cbd3.json) ntf.unlink(ntf.name) # delete file
def test_data(self): cbd = CitiBikeData(source_url=self.test_data_url) d = datetime.datetime(2013, 8, 6, 4, 17, 2, 0, pytz.utc) self.assertEqual(d, cbd.timestamp()) self.assertEqual("2013-08-06T04:17:02+00:00", cbd.point_in_time_id())