def test_csv_reader_malformed_data_contents(city_list_location_malformed): """ Sad Path Test """ with pytest.raises(ValueError) as exp: data_processor.csv_reader(city_list_location_malformed) assert str( exp.value) == "could not convert string to float: 'not_an_altitude'"
def test_csv_reader_malformed_data_contents(city_list_location_malformed): """ Sad Path Test We will need to wrap the following line in the exceptions context manager: """ with pytest.raises(ValueError) as exp: data_processor.csv_reader(city_list_location_malformed) print(str(exp.value))
def test_csv_reader_malformed_data_contents(city_list_location_malformed): """ Sad Path Test We will need to wrap the following line in the exceptions context manager: """ with pytest.raises(ValueError) as exp: data_processor.csv_reader(city_list_location_malformed) assert str(exp.value) == "could not convert string to float: 'not_an_altitude'"
def test_data_population_no_update(): """ Sad Path test: We don't want the data transformed twice """ map_data_location = 'tests/resources/cities/clean_map.csv' data = data_processor.csv_reader(map_data_location) data_to_transform = map_population_update.MapData(data, False) population_dict = { 'Andorra': 77142, 'Argentina': 44780677, 'Cape Verde': 546388, 'Germany': 83670653, 'Greece': 10473455, 'India': 1366417754, 'Japan': 128860301, 'Morocco': 36471769, 'Senegal': 16296364, 'United States': 329064917 } data_to_transform.add_population( population_dict) # transform object in place # Try calling the function again with pytest.raises(Exception) as e: data_to_transform.add_population(population_dict) assert str(e.value) == 'You cannot transform the data twice'
def test_data_population_update(): """ Happy Path test """ map_data_location = 'tests/resources/cities/clean_map.csv' data = data_processor.csv_reader(map_data_location) data_to_transform = map_population_update.MapData(data, False) population_dict = { 'Andorra': 77142, 'Argentina': 44780677, 'Cape Verde': 546388, 'Germany': 83670653, 'Greece': 10473455, 'India': 1366417754, 'Japan': 128860301, 'Morocco': 36471769, 'Senegal': 16296364, 'United States': 329064917 } data_to_transform.add_population( population_dict) # transform object in place for row in data_to_transform.get_data(): assert 'Population' in row assert 'Updated' in row
def _specify_type(file_name_or_type): for f in files: if file_name_or_type != '.json': data = data_processor.csv_reader(city_list_location + f) else: data = data_processor.json_reader(city_list_location + f) return data
def _specify_type(filename): for f in files: if filename == f: if filename.endswith('.json'): data = data_processor.json_reader(city_list_location + f) elif filename.endswith('.csv'): data = data_processor.csv_reader(city_list_location + f) return data
def prep_transform_data(map_data_location): population_dict = { 'Andorra': 77142, 'Argentina': 44780677, 'Cape Verde': 546388, 'Germany': 83670653, 'Greece': 10473455, 'India': 1366417754, 'Japan': 128860301, 'Morocco': 36471769, 'Senegal': 16296364, 'United States': 329064917 } data = data_processor.csv_reader(map_data_location) data_to_transform = map_population_update.MapData(data, False) yield data_to_transform, population_dict
def process_data(city_list_location): yield data_processor.csv_reader(city_list_location)