def get_translations(self, address): """ If there exists the configuration file 'highway_types.csv', read it, else write one with default values. If don't exists the translations file 'highway_names.csv', creates one parsing current OSM highways data, else reads and returns it as a dictionary. * 'highway_types.csv' List of osm elements in json format located in the application path that contains translations from abbreviations to full types of highways. * 'highway_names.csv' is located in the outputh folder and contains corrections for original highway names. """ highway_types_path = os.path.join(setup.app_path, 'highway_types.csv') if not os.path.exists(highway_types_path): csvtools.dict2csv(highway_types_path, setup.highway_types) else: csvtools.csv2dict(highway_types_path, setup.highway_types) highway_names_path = os.path.join(self.path, 'highway_names.csv') if not os.path.exists(highway_names_path): if self.options.manual: highway = None else: highway = self.get_highway() highway.reproject(address.crs()) highway_names = address.get_highway_names(highway) csvtools.dict2csv(highway_names_path, highway_names, sort=1) is_new = True else: highway_names = csvtools.csv2dict(highway_names_path, {}) is_new = False for key, value in list(highway_names.items()): highway_names[key] = value.strip() return (highway_names, is_new)
def test_csv2dict_bad_delimiter(self): _, tmp_path = mkstemp() with io.open(tmp_path, 'w', encoding=encoding) as csv_file: csv_file.write('a;1\nb;2') with self.assertRaises(IOError): a_dict = csv2dict(tmp_path, {})
def test_csv2dict(self): _, tmp_path = mkstemp() with io.open(tmp_path, 'w', encoding=encoding) as csv_file: csv_file.write("á%sx\né%sy\n" % (delimiter, delimiter)) a_dict = csv2dict(tmp_path, {}) self.assertEqual(a_dict, {"á": "x", "é": "y"})
def test_csv2dict(self): _, tmp_path = mkstemp() with codecs.open(tmp_path, 'w', encoding) as csv_file: csv_file.write(u'á%sx%sé%sy%s' % (delimiter, eol, delimiter, eol)) a_dict = csv2dict(tmp_path, {}) self.assertEquals(a_dict, {u'á': u'x', u'é': u'y'})