2 # -*- coding: iso-8859-15 -*-
4 import wrpylib.wrmwmarkup
5 import wrpylib.mwmarkup
10 def test_rodelbahnbox_to_sledrun():
11 wikitext = u'''== Allgemeines ==
13 | Position = 47.309820 N 9.986508 E
20 | Lawinen = gelegentlich
22 | Öffentliche Anreise = Ja
24 | Aufstieg getrennt = Nein
25 | Aufstiegshilfe = Nein
26 | Beleuchtungsanlage = Nein
31 | Telefonauskunft = +43-664-1808482 (Bergkristallhütte)
32 | Bild = Rodelbahn Bergkristallhütte 2009-03-03.jpg
33 | In Übersichtskarte = Ja
36 Die Rodelbahn zur Bergkristallhütte ist durchaus abwechslungsreich.'''
37 start, end, sledrun = wrpylib.wrmwmarkup.rodelbahnbox_to_sledrun(wikitext)
38 wrpylib.wrmwmarkup.sledrun_to_rodelbahnbox(sledrun, '1.3')
41 def test_RodelbahnboxDictConverter():
42 v = wrpylib.wrmwmarkup.RodelbahnboxDictConverter()
43 other = collections.OrderedDict([
44 (u'Position', (47.30982, 9.986508)),
45 (u'Position oben', (None, None)),
47 (u'Position unten', (None, None)),
50 (u'Schwierigkeit', None),
53 (u'Öffentliche Anreise', 6),
54 (u'Aufstieg möglich', True),
55 (u'Aufstieg getrennt', (0.0, None)),
57 (u'Aufstiegshilfe', (False, None)),
58 (u'Beleuchtungsanlage', (0.0, None)),
59 (u'Beleuchtungstage', (None, None)),
60 (u'Rodelverleih', (True, u'Ja')),
61 (u'Gütesiegel', None),
62 (u'Webauskunft', None),
63 (u'Telefonauskunft', u'+43-664-1808482 (Bergkristallhütte)'),
64 (u'Bild', u'Rodelbahn Bergkristallhütte 2009-03-03.jpg'),
65 (u'In Übersichtskarte', True),
67 sledrun = v.to_python(other)
68 assert sledrun.forum_id == 72
69 other2 = v.from_python(sledrun)
70 assert other == other2
73 def test_RodelbahnboxValidator():
74 v = wrpylib.wrmwmarkup.RodelbahnboxValidator()
75 wikitext = textwrap.dedent(u'''\
77 | Position = 47.309820 N 9.986508 E
84 | Lawinen = gelegentlich
86 | Öffentliche Anreise = Ja
87 | Aufstieg möglich = Nein
88 | Aufstieg getrennt = Nein
90 | Aufstiegshilfe = Nein
91 | Beleuchtungsanlage = Nein
96 | Telefonauskunft = +43-664-1808482 (Bergkristallhütte)
97 | Bild = Rodelbahn Bergkristallhütte 2009-03-03.jpg
98 | In Übersichtskarte = Ja
101 sledrun = v.to_python(wikitext)
102 wikitext2 = v.from_python(sledrun)
103 assert wikitext == wikitext2
104 wikitext = textwrap.dedent(u'''\
115 | Öffentliche Anreise =
117 | Aufstieg getrennt =
120 | Beleuchtungsanlage =
127 | In Übersichtskarte =
130 sledrun = v.to_python(wikitext)
131 wikitext2 = v.from_python(sledrun)
132 assert wikitext == wikitext2
135 def test_gasthausbox_to_inn():
136 wikitext = u'''{{Gasthausbox
137 | Position = 47.295549 N 9.986970 E
144 | Handyempfang = A1; T-Mobile/Telering
145 | Homepage = http://www.bergkristallhuette.com/
146 | E-Mail = bergkristallhuette@gmx.at
147 | Telefon = +43-664-1808482
148 | Bild = Bergkritsallhütte 2009-02-07.JPG
149 | Rodelbahnen = [[Bergkristallhütte]]
151 Die Bergkristallhütte ist Teil des Boden-Vorsäß.'''
152 start, end, inn = wrpylib.wrmwmarkup.gasthausbox_to_inn(wikitext)
153 wrpylib.wrmwmarkup.inn_to_gasthausbox(inn)
156 def test_googlemap_to_wrmap():
158 <googlemap version="0.9" lat="47.113291" lon="11.272337" zoom="15" height="450">
159 (Parkplatz)47.114958,11.266026
162 (Gasthaus) 47.114715, 11.266262, Alt Bärnbad (Gasthaus)
171 attributes, coords, paths = wrpylib.mwmarkup.parse_googlemap(wikitext)
172 json = wrpylib.wrmwmarkup.googlemap_to_wrmap(attributes, coords, paths)
173 assert json['properties']['lon'] == 11.272337
174 assert json['properties']['lat'] == 47.113291
175 assert json['properties']['zoom'] == 15
176 assert json['properties']['height'] == 450
177 assert json['features'][0]['properties']['type'] == 'parkplatz'
178 assert json['features'][0]['properties']['name'] == 'Erster Parkplatz'
179 assert json['features'][0]['geometry']['coordinates'] == [11.266026, 47.114958]
180 assert json['features'][1]['properties']['type'] == 'gasthaus'
181 assert json['features'][1]['properties']['name'] == u'Alt Bärnbad (Gasthaus)'
182 assert json['features'][1]['geometry']['coordinates'] == [11.266262, 47.114715]
183 assert json['features'][2]['properties']['type'] == 'rodelbahn'
184 assert json['features'][2]['geometry']['coordinates'] == [
185 [11.266262, 47.114715],
186 [11.268381, 47.114135],
187 [11.269322, 47.113421],
188 [11.269979, 47.11277],
189 [11.271119, 47.112408]]
192 def test_parse_wrmap():
194 <wrmap lat="47.2417134" lon="11.21408895" zoom="14" width="700" height="400">
195 <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 11.190454</gasthaus>
196 <parkplatz>47.245789 11.238971</parkplatz>
197 <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 11.238283</haltestelle>
205 json = wrpylib.wrmwmarkup.parse_wrmap(wikitext)
206 assert json['properties']['lon'] == 11.21408895
207 assert json['properties']['lat'] == 47.2417134
208 assert json['properties']['zoom'] == 14
209 assert json['properties']['width'] == 700
210 assert json['properties']['height'] == 400
211 assert json['features'][0]['properties']['type'] == 'gasthaus'
212 assert json['features'][0]['properties']['name'] == u'Rosskogelhütte'
213 assert json['features'][0]['properties']['wiki'] == u'Rosskogelhütte'
214 assert json['features'][0]['geometry']['coordinates'] == [11.190454, 47.240689]
215 assert json['features'][1]['properties']['type'] == 'parkplatz'
216 assert json['features'][1]['geometry']['coordinates'] == [11.238971, 47.245789]
217 assert json['features'][2]['properties']['type'] == 'haltestelle'
218 assert json['features'][2]['properties']['name'] == u'Oberperfuss Rangger Köpfl Lift'
219 assert json['features'][2]['geometry']['coordinates'] == [11.238283, 47.245711]
220 assert json['features'][3]['properties']['type'] == 'rodelbahn'
221 assert json['features'][3]['geometry']['coordinates'] == [
222 [11.203360, 47.238587],
223 [11.230868, 47.244951],
224 [11.237853, 47.245470]]
227 def test_create_wrmap():
229 'type': 'FeatureCollection',
235 'coordinates': [11.190454, 47.240689]},
236 'properties': {'type': 'gasthaus', 'name': u'Rosskogelhütte', 'wiki': u'Rosskogelhütte'}
241 'coordinates': [11.238971, 47.245789]},
242 'properties': {'type': 'parkplatz'}
247 'coordinates': [11.238283, 47.245711]},
248 'properties': {'type': 'haltestelle', 'name': u'Oberperfuss Rangger Köpfl Lift'}
252 'type': 'LineString',
254 [11.203360, 47.238587],
255 [11.230868, 47.244951],
256 [11.237853, 47.245470]]},
257 'properties': {'type': 'rodelbahn'}
267 wikitext = wrpylib.wrmwmarkup.create_wrmap(geojson)
268 assert wikitext == textwrap.dedent(u'''\
269 <wrmap height="400" lat="47.241713" lon="11.214089" width="700" zoom="14">
271 <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 N 11.190454 E</gasthaus>
272 <parkplatz>47.245789 N 11.238971 E</parkplatz>
273 <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 N 11.238283 E</haltestelle>
276 47.238587 N 11.203360 E
277 47.244951 N 11.230868 E
278 47.245470 N 11.237853 E