Exemplo n.º 1
0
    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
Exemplo n.º 2
0
    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)