From: philipp Date: Mon, 26 Aug 2013 20:58:07 +0000 (+0000) Subject: Updated parse_googlemap but the test doesn't pass yet. X-Git-Url: https://git.toastfreeware.priv.at/philipp/winterrodeln/wrpylib.git/commitdiff_plain/4dffa89e57d37435a09e1ec62889cb3670dc23ee?hp=ebe9dee556cbc010e4125a0835b041972cf20879 Updated parse_googlemap but the test doesn't pass yet. git-svn-id: http://www.winterrodeln.org/svn/wrpylib/trunk@1528 7aebc617-e5e2-0310-91dc-80fb5f6d2477 --- diff --git a/tests/test_wrmwmarkup.py b/tests/test_wrmwmarkup.py index 5ebfe1f..189c7c1 100644 --- a/tests/test_wrmwmarkup.py +++ b/tests/test_wrmwmarkup.py @@ -72,17 +72,17 @@ def test_parse_googlemap(): 47.112408,11.271119 ''' - attributes, json = wrpylib.wrmwmarkup.parse_googlemap(wikitext) - assert attributes['lon'] == 11.272337 - assert attributes['lat'] == 47.113291 - assert attributes['zoom'] == 15 - assert json['features'][0]['properties']['type'] == 'carpark' + json = wrpylib.wrmwmarkup.parse_googlemap(wikitext) + assert json['properties']['lon'] == 11.272337 + assert json['properties']['lat'] == 47.113291 + assert json['properties']['zoom'] == 15 + assert json['features'][0]['properties']['type'] == 'parkplatz' assert json['features'][0]['properties']['name'] == 'Erster Parkplatz' assert json['features'][0]['geometry']['coordinates'] == [11.266026, 47.114958] - assert json['features'][1]['properties']['type'] == 'inn' + assert json['features'][1]['properties']['type'] == 'gasthaus' assert json['features'][1]['properties']['name'] == u'Alt Bärnbad (Gasthaus)' assert json['features'][1]['geometry']['coordinates'] == [11.266262, 47.114715] - assert json['features'][2]['properties']['type'] == 'sledrun' + assert json['features'][2]['properties']['type'] == 'rodelbahn' assert json['features'][2]['geometry']['coordinates'] == [ [11.266262, 47.114715], [11.268381, 47.114135], diff --git a/wrpylib/wrmwmarkup.py b/wrpylib/wrmwmarkup.py index a27525b..1e9127b 100644 --- a/wrpylib/wrmwmarkup.py +++ b/wrpylib/wrmwmarkup.py @@ -327,7 +327,7 @@ def find_all_templates(wikitext, find_func): def parse_googlemap(wikitext): """Parses the (unicode) u'content' of the googlemap extension out of a page. If wikitext does not contain the googlemaps extension text None is returned. - If the googlemap contains invalid formatted lines, a RuntimeError is raised. + If the googlemap contains invalid formatted lines, a ParseError is raised. :param wikitext: wikitext containing the template. Example: @@ -345,7 +345,7 @@ def parse_googlemap(wikitext): 47.112408,11.271119 ''' - :returns: (attributes, GeoJSON as Python datatypes) + :returns: (GeoJSON as nested Python datatypes) """ center, zoom, coords, paths = wrpylib.mwmarkup.parse_googlemap(wikitext) json_features = [] @@ -353,10 +353,10 @@ def parse_googlemap(wikitext): # point for point in coords: lon, lat, symbol, title = point - properties = {'type': symbol} + properties = {'type': symbol.lower()} if title: properties['name'] = title json_features.append({ - 'type': 'feature', + 'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [lon, lat]}, 'properties': properties}) @@ -365,14 +365,17 @@ def parse_googlemap(wikitext): style, entries = path properties = {'type': 'line'} json_features.append({ - 'type': 'feature', + 'type': 'Feature', 'geometry': { 'type': 'LineString', 'coordinates': [[lon, lat] for lon, lat, symbol, title in entries]}, 'properties': properties}) - geojson = {'type': 'FeatureCollection', 'features': json_features} - return {'lon': center[0], 'lat': center[1], 'zoom': zoom}, geojson + geojson = { + 'type': 'FeatureCollection', + 'features': json_features, + 'properties': {'lon': center[0], 'lat': center[1], 'zoom': zoom}} + return geojson def parse_wrmap_coordinates(coords):