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 möglich = Nein
25 | Aufstieg getrennt = Nein
26 | Aufstiegshilfe = Nein
27 | Beleuchtungsanlage = Nein
32 | Telefonauskunft = +43-664-1808482 (Bergkristallhütte)
33 | Bild = Rodelbahn Bergkristallhütte 2009-03-03.jpg
34 | In Übersichtskarte = Ja
37 Die Rodelbahn zur Bergkristallhütte ist durchaus abwechslungsreich.'''
38 start, end, sledrun = wrpylib.wrmwmarkup.rodelbahnbox_to_sledrun(wikitext)
39 wrpylib.wrmwmarkup.sledrun_to_rodelbahnbox(sledrun)
42 def test_RodelbahnboxDictConverter():
43 v = wrpylib.wrmwmarkup.RodelbahnboxDictConverter()
44 other = collections.OrderedDict([
45 (u'Position', (47.30982, 9.986508)),
46 (u'Position oben', (None, None)),
48 (u'Position unten', (None, None)),
51 (u'Schwierigkeit', None),
54 (u'Öffentliche Anreise', 6),
55 (u'Aufstieg möglich', True),
56 (u'Aufstieg getrennt', (0.0, None)),
58 (u'Aufstiegshilfe', (False, None)),
59 (u'Beleuchtungsanlage', (0.0, None)),
60 (u'Beleuchtungstage', (None, None)),
61 (u'Rodelverleih', (True, u'Ja')),
62 (u'Gütesiegel', None),
63 (u'Webauskunft', None),
64 (u'Telefonauskunft', u'+43-664-1808482 (Bergkristallhütte)'),
65 (u'Bild', u'Rodelbahn Bergkristallhütte 2009-03-03.jpg'),
66 (u'In Übersichtskarte', True),
68 sledrun = v.to_python(other)
69 assert sledrun.forum_id == 72
70 other2 = v.from_python(sledrun)
71 assert other == other2
74 def test_RodelbahnboxValidator():
75 v = wrpylib.wrmwmarkup.RodelbahnboxValidator()
76 wikitext = textwrap.dedent(u'''\
78 | Position = 47.309820 N 9.986508 E
85 | Lawinen = gelegentlich
87 | Öffentliche Anreise = Ja
88 | Aufstieg möglich = Nein
89 | Aufstieg getrennt = Nein
91 | Aufstiegshilfe = Nein
92 | Beleuchtungsanlage = Nein
97 | Telefonauskunft = +43-664-1808482 (Bergkristallhütte)
98 | Bild = Rodelbahn Bergkristallhütte 2009-03-03.jpg
99 | In Übersichtskarte = Ja
102 sledrun = v.to_python(wikitext)
103 wikitext2 = v.from_python(sledrun)
104 assert wikitext == wikitext2
105 wikitext = textwrap.dedent(u'''\
116 | Öffentliche Anreise =
118 | Aufstieg getrennt =
121 | Beleuchtungsanlage =
128 | In Übersichtskarte =
131 sledrun = v.to_python(wikitext)
132 wikitext2 = v.from_python(sledrun)
133 assert wikitext == wikitext2
136 def test_gasthausbox_to_inn():
137 wikitext = u'''{{Gasthausbox
138 | Position = 47.295549 N 9.986970 E
145 | Handyempfang = A1; T-Mobile/Telering
146 | Homepage = http://www.bergkristallhuette.com/
147 | E-Mail = bergkristallhuette@gmx.at
148 | Telefon = +43-664-1808482
149 | Bild = Bergkritsallhütte 2009-02-07.JPG
150 | Rodelbahnen = [[Bergkristallhütte]]
152 Die Bergkristallhütte ist Teil des Boden-Vorsäß.'''
153 start, end, inn = wrpylib.wrmwmarkup.gasthausbox_to_inn(wikitext)
154 wrpylib.wrmwmarkup.inn_to_gasthausbox(inn)
157 def test_GasthausboxDictConverter():
158 v = wrpylib.wrmwmarkup.GasthausboxDictConverter()
159 other = collections.OrderedDict([
160 (u'Position', (47.295549, 9.986970)),
162 (u'Betreiber', None),
163 (u'Sitzplätze', None),
164 (u'Übernachtung', (None, None)),
165 (u'Rauchfrei', (True, False)),
166 (u'Rodelverleih', (None, None)),
167 (u'Handyempfang', u'A1; T-Mobile/Telering'),
168 (u'Homepage', u'http://www.bergkristallhuette.com/'),
169 (u'E-Mail', u'bergkristallhuette@gmx.at'),
170 (u'Telefon', u'+43-664-1808482'),
171 (u'Bild', u'Bergkritsallhütte 2009-02-07.JPG'),
172 (u'Rodelbahnen', u'[[Bergkristallhütte]]')])
173 inn = v.to_python(other)
174 assert inn.homepage == u'http://www.bergkristallhuette.com/'
175 other2 = v.from_python(inn)
176 assert other == other2
179 def test_GasthausboxValidator():
180 v = wrpylib.wrmwmarkup.GasthausboxValidator()
181 wikitext = textwrap.dedent(u'''\
183 | Position = 47.295549 N 9.986970 E
190 | Handyempfang = A1; T-Mobile/Telering
191 | Homepage = http://www.bergkristallhuette.com/
192 | E-Mail = bergkristallhuette@gmx.at
193 | Telefon = +43-664-1808482
194 | Bild = Bergkritsallhütte 2009-02-07.JPG
195 | Rodelbahnen = [[Bergkristallhütte]]
197 inn = v.to_python(wikitext)
198 wikitext2 = v.from_python(inn)
199 assert wikitext == wikitext2
202 def test_googlemap_to_wrmap():
204 <googlemap version="0.9" lat="47.113291" lon="11.272337" zoom="15" height="450">
205 (Parkplatz)47.114958,11.266026
208 (Gasthaus) 47.114715, 11.266262, Alt Bärnbad (Gasthaus)
217 attributes, coords, paths = wrpylib.mwmarkup.parse_googlemap(wikitext)
218 json = wrpylib.wrmwmarkup.googlemap_to_wrmap(attributes, coords, paths)
219 assert json['properties']['lon'] == 11.272337
220 assert json['properties']['lat'] == 47.113291
221 assert json['properties']['zoom'] == 15
222 assert json['properties']['height'] == 450
223 assert json['features'][0]['properties']['type'] == 'parkplatz'
224 assert json['features'][0]['properties']['name'] == 'Erster Parkplatz'
225 assert json['features'][0]['geometry']['coordinates'] == [11.266026, 47.114958]
226 assert json['features'][1]['properties']['type'] == 'gasthaus'
227 assert json['features'][1]['properties']['name'] == u'Alt Bärnbad (Gasthaus)'
228 assert json['features'][1]['geometry']['coordinates'] == [11.266262, 47.114715]
229 assert json['features'][2]['properties']['type'] == 'rodelbahn'
230 assert json['features'][2]['geometry']['coordinates'] == [
231 [11.266262, 47.114715],
232 [11.268381, 47.114135],
233 [11.269322, 47.113421],
234 [11.269979, 47.11277],
235 [11.271119, 47.112408]]
238 def test_parse_wrmap():
240 <wrmap lat="47.2417134" lon="11.21408895" zoom="14" width="700" height="400">
241 <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 11.190454</gasthaus>
242 <parkplatz>47.245789 11.238971</parkplatz>
243 <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 11.238283</haltestelle>
251 json = wrpylib.wrmwmarkup.parse_wrmap(wikitext)
252 assert json['properties']['lon'] == 11.21408895
253 assert json['properties']['lat'] == 47.2417134
254 assert json['properties']['zoom'] == 14
255 assert json['properties']['width'] == 700
256 assert json['properties']['height'] == 400
257 assert json['features'][0]['properties']['type'] == 'gasthaus'
258 assert json['features'][0]['properties']['name'] == u'Rosskogelhütte'
259 assert json['features'][0]['properties']['wiki'] == u'Rosskogelhütte'
260 assert json['features'][0]['geometry']['coordinates'] == [11.190454, 47.240689]
261 assert json['features'][1]['properties']['type'] == 'parkplatz'
262 assert json['features'][1]['geometry']['coordinates'] == [11.238971, 47.245789]
263 assert json['features'][2]['properties']['type'] == 'haltestelle'
264 assert json['features'][2]['properties']['name'] == u'Oberperfuss Rangger Köpfl Lift'
265 assert json['features'][2]['geometry']['coordinates'] == [11.238283, 47.245711]
266 assert json['features'][3]['properties']['type'] == 'rodelbahn'
267 assert json['features'][3]['geometry']['coordinates'] == [
268 [11.203360, 47.238587],
269 [11.230868, 47.244951],
270 [11.237853, 47.245470]]
273 def test_create_wrmap():
275 'type': 'FeatureCollection',
281 'coordinates': [11.190454, 47.240689]},
282 'properties': {'type': 'gasthaus', 'name': u'Rosskogelhütte', 'wiki': u'Rosskogelhütte'}
287 'coordinates': [11.238971, 47.245789]},
288 'properties': {'type': 'parkplatz'}
293 'coordinates': [11.238283, 47.245711]},
294 'properties': {'type': 'haltestelle', 'name': u'Oberperfuss Rangger Köpfl Lift'}
298 'type': 'LineString',
300 [11.203360, 47.238587],
301 [11.230868, 47.244951],
302 [11.237853, 47.245470]]},
303 'properties': {'type': 'rodelbahn'}
313 wikitext = wrpylib.wrmwmarkup.create_wrmap(geojson)
314 assert wikitext == textwrap.dedent(u'''\
315 <wrmap height="400" lat="47.241713" lon="11.214089" width="700" zoom="14">
317 <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 N 11.190454 E</gasthaus>
318 <parkplatz>47.245789 N 11.238971 E</parkplatz>
319 <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 N 11.238283 E</haltestelle>
322 47.238587 N 11.203360 E
323 47.244951 N 11.230868 E
324 47.245470 N 11.237853 E