def test_read_csv_types(self): path = str(test.get_data_path("vehicles.csv")) types = {"hwy": int, "cty": int} data = ListOfDicts.read_csv(path, types=types) assert isinstance(data[0].hwy, int) assert isinstance(data[0].cty, int) assert isinstance(data[100].hwy, int) assert isinstance(data[100].cty, int)
def test_write_csv(self): orig = test.list_of_dicts("vehicles.csv") handle, path = tempfile.mkstemp(".csv") orig.write_csv(path) data = ListOfDicts.read_csv(path) assert data == orig
def test_read_json_path(self): ListOfDicts.read_csv(test.get_data_path("vehicles.json"))
def test_read_csv_path(self): ListOfDicts.read_csv(test.get_data_path("vehicles.csv"))
def test_read_csv_keys(self): path = str(test.get_data_path("vehicles.csv")) data = ListOfDicts.read_csv(path, keys=["make", "model"]) assert list(data[0].keys()) == ["make", "model"] assert list(data[100].keys()) == ["make", "model"]
def test_read_csv(self): path = str(test.get_data_path("vehicles.csv")) data = ListOfDicts.read_csv(path) assert len(data) == 33442 assert all(len(x) == 12 for x in data)