5 import mwparserfromhell
6 import wrpylib.mwmarkup
7 from wrpylib.wrmwmarkup import *
10 class TestSledrun(unittest.TestCase):
11 def test_sledrun_from_rodelbahnbox(self):
14 rodelbahnbox = collections.OrderedDict([
15 ('Position', LonLat(9.986508, 47.30982)),
16 ('Position oben', LonLat(None, None)),
18 ('Position unten', LonLat(8.506047, 46.20210)),
23 ('Betreiber', 'SchneeFunFit'),
24 ('Öffentliche Anreise', 2),
25 ('Aufstieg möglich', True),
26 ('Aufstieg getrennt', (0.0, None)),
28 ('Aufstiegshilfe', [('Sessellift', 'gratis'), ('Bus', None)]),
29 ('Beleuchtungsanlage', (0.0, 'in Planung für 2020')),
30 ('Beleuchtungstage', (None, None)),
33 ('Webauskunft', (True, 'http://example.com/schneelage')),
34 ('Telefonauskunft', [('+43-664-1808482', 'Bergkristallhütte')]),
35 ('Bild', 'Rodelbahn Bergkristallhütte 2009-03-03.jpg'),
36 ('In Übersichtskarte', True),
39 sledrun_from_rodelbahnbox(rodelbahnbox, sledrun)
40 self.assertEqual(47.30982, sledrun.position_latitude)
41 self.assertEqual(9.986508, sledrun.position_longitude)
42 self.assertEqual(None, sledrun.top_latitude)
43 self.assertEqual(None, sledrun.top_longitude)
44 self.assertEqual(1244, sledrun.top_elevation)
45 self.assertEqual(46.20210, sledrun.bottom_latitude)
46 self.assertEqual(8.506047, sledrun.bottom_longitude)
47 self.assertEqual(None, sledrun.bottom_elevation)
48 self.assertEqual(5045, sledrun.length)
49 self.assertEqual(3, sledrun.difficulty)
50 self.assertEqual(2, sledrun.avalanches)
51 self.assertEqual('SchneeFunFit', sledrun.operator)
52 self.assertEqual(2, sledrun.public_transport)
53 self.assertEqual(True, sledrun.walkup_possible)
54 self.assertEqual(105, sledrun.walkup_time)
55 self.assertEqual(0.0, sledrun.walkup_separate)
56 self.assertEqual(None, sledrun.walkup_separate_comment)
57 self.assertEqual(True, sledrun.lift)
58 self.assertEqual('Sessellift (gratis); Bus', sledrun.lift_details)
59 self.assertEqual(0.0, sledrun.night_light)
60 self.assertEqual('in Planung für 2020', sledrun.night_light_comment)
61 self.assertEqual(None, sledrun.night_light_days)
62 self.assertEqual(None, sledrun.night_light_days_comment)
63 self.assertEqual(False, sledrun.sled_rental)
64 self.assertEqual('Nein', sledrun.sled_rental_comment)
65 self.assertEqual('Nein', sledrun.cachet)
66 self.assertEqual('http://example.com/schneelage', sledrun.information_web)
67 self.assertEqual('+43-664-1808482 (Bergkristallhütte)', sledrun.information_phone)
68 self.assertEqual('Rodelbahn Bergkristallhütte 2009-03-03.jpg', sledrun.image)
69 self.assertEqual(True, sledrun.show_in_overview)
70 self.assertEqual(72, sledrun.forum_id)
72 def test_sledrun_to_rodelbahnbox(self):
76 sledrun.position_longitude = 13.5
77 sledrun.position_latitude = 50.7
78 sledrun.top_longitude = 12.2
79 sledrun.top_latitude = 49.8
80 sledrun.top_elevation = 3456
81 sledrun.bottom_longitude = 9.89
82 sledrun.bottom_latitude = 51.2
83 sledrun.bottom_elevation = 2075
85 sledrun.difficulty = 3
86 sledrun.avalanches = 2
87 sledrun.operator = 'McRodel'
88 sledrun.public_transport = 3
89 sledrun.walkup_possible = True
90 sledrun.walkup_time = 77
91 sledrun.walkup_separate = 0.5
92 sledrun.walkup_separate_comment = 'Nur unterer Teil'
94 sledrun.lift_details = 'Sessellift'
95 sledrun.night_light = 1.0
96 sledrun.night_light_comment = 'Schlecht beleuchtet'
97 sledrun.night_light_days = 6
98 sledrun.night_light_days_comment = 'Mo-Sa'
99 sledrun.sled_rental = True
100 sledrun.sled_rental_comment = 'In der Hütte'
101 sledrun.cachet = 'Tiroler Rodelbahngütesielgel mittelschwer 2010'
102 sledrun.information_web = 'http://example.com'
103 sledrun.information_phone = '+4364412345678'
104 sledrun.image = 'Sicht_von_unten.jpg'
105 sledrun.show_in_overview = True
106 sledrun.forum_id = 65
107 rodelbahnbox = sledrun_to_rodelbahnbox(sledrun)
108 self.assertEqual(rodelbahnbox['Position'], LonLat(lon=13.5, lat=50.7))
109 self.assertEqual(rodelbahnbox['Position oben'], LonLat(12.2, 49.8))
110 self.assertEqual(rodelbahnbox['Höhe oben'], 3456)
111 self.assertEqual(rodelbahnbox['Position unten'], LonLat(9.89, 51.2))
112 self.assertEqual(rodelbahnbox['Höhe unten'], 2075)
113 self.assertEqual(rodelbahnbox['Länge'], 9644)
114 self.assertEqual(rodelbahnbox['Schwierigkeit'], 3)
115 self.assertEqual(rodelbahnbox['Lawinen'], 2)
116 self.assertEqual(rodelbahnbox['Betreiber'], 'McRodel')
117 self.assertEqual(rodelbahnbox['Öffentliche Anreise'], 3)
118 self.assertEqual(rodelbahnbox['Aufstieg möglich'], True)
119 self.assertEqual(rodelbahnbox['Aufstieg getrennt'], (0.5, 'Nur unterer Teil'))
120 self.assertEqual(rodelbahnbox['Gehzeit'], 77)
121 self.assertEqual(rodelbahnbox['Aufstiegshilfe'], [('Sessellift', None)])
122 self.assertEqual(rodelbahnbox['Beleuchtungsanlage'], (1.0, 'Schlecht beleuchtet'))
123 self.assertEqual(rodelbahnbox['Beleuchtungstage'], (6, 'Mo-Sa'))
124 self.assertEqual(rodelbahnbox['Rodelverleih'], (True, 'In der Hütte'))
125 self.assertEqual(rodelbahnbox['Gütesiegel'], 'Tiroler Rodelbahngütesielgel mittelschwer 2010')
126 self.assertEqual(rodelbahnbox['Webauskunft'], 'http://example.com')
127 self.assertEqual(rodelbahnbox['Bild'], 'Sicht_von_unten.jpg')
128 self.assertEqual(rodelbahnbox['In Übersichtskarte'], True)
129 self.assertEqual(rodelbahnbox['Forumid'], 65)
132 class TestInn(unittest.TestCase):
133 def test_inn_from_gasthausbox(self):
136 gasthausbox = collections.OrderedDict()
137 gasthausbox['Position'] = LonLat(11.015883, 9.876000)
138 gasthausbox['Höhe'] = 2145
139 gasthausbox['Betreiber'] = 'Max Mustermann'
140 gasthausbox['Sitzplätze'] = 30
141 gasthausbox['Übernachtung'] = (False, None)
142 gasthausbox['Rauchfrei'] = 0.5
143 gasthausbox['Rodelverleih'] = (True, '6 Euro')
144 gasthausbox['Handyempfang'] = []
145 gasthausbox['Homepage'] = (True, 'http://www.graf-ferdinand.at/')
146 gasthausbox['E-Mail'] = [(('max.mustermann@graf-ferdinand.at', False), None)]
147 gasthausbox['Telefon'] = [('+43-5039-21666', None), ('+43-686-4134880', 'Sommer')]
148 gasthausbox['Bild'] = 'Gasthaus_Graf_Ferdinand_Haus_01.jpg'
149 gasthausbox['Rodelbahnen'] = ['[[Finstertaler Speicher]]']
151 inn_from_gasthausbox(gasthausbox, inn)
152 self.assertEqual(inn.position_latitude, 9.876000)
153 self.assertEqual(inn.position_longitude, 11.015883)
154 self.assertEqual(inn.position_elevation, 2145)
155 self.assertEqual(inn.operator, 'Max Mustermann')
156 self.assertEqual(inn.seats, 30)
157 self.assertEqual(inn.overnight, False)
158 self.assertEqual(inn.overnight_comment, None)
159 self.assertEqual(inn.smoker_area, True)
160 self.assertEqual(inn.nonsmoker_area, True)
161 self.assertEqual(inn.sled_rental, True)
162 self.assertEqual(inn.sled_rental_comment, '6 Euro')
163 self.assertEqual(inn.mobile_provider, 'Nein')
164 self.assertEqual(inn.homepage, 'http://www.graf-ferdinand.at/')
165 self.assertEqual(inn.email_list, 'max.mustermann@graf-ferdinand.at')
166 self.assertEqual(inn.phone_list, '+43-5039-21666; +43-686-4134880 (Sommer)')
167 self.assertEqual(inn.image, 'Gasthaus_Graf_Ferdinand_Haus_01.jpg')
168 self.assertEqual(inn.sledding_list, '[[Finstertaler Speicher]]')
171 def test_inn_to_gasthausbox(self):
174 inn = Inn() # TODO: populate for test
175 gasthausbox = inn_to_gasthausbox(inn)
179 class TestLonlatEle(unittest.TestCase):
180 def test_lonlat_ele_from_template(self):
181 template = mwparserfromhell.parse('{{Position oben|46.942239 N 11.468819 E|1866}}').filter_templates()[0]
182 lonlat, ele = lonlat_ele_from_template(template)
183 self.assertEqual(LonLat(11.468819, 46.942239), lonlat)
184 self.assertEqual(1866, ele)
186 def test_latlon_ele_to_template(self):
187 template = latlon_ele_to_template((LonLat(11.468819, 46.942239), 1866), 'Position oben')
188 self.assertEqual('{{Position oben|46.942239 N 11.468819 E|1866}}', template)
191 class TestWrMwMarkup(unittest.TestCase):
192 def test_rodelbahnbox_to_sledrun(self):
193 wikitext = '''== Allgemeines ==
195 | Position = 47.309820 N 9.986508 E
202 | Lawinen = gelegentlich
204 | Öffentliche Anreise = Ja
206 | Aufstieg möglich = Nein
207 | Aufstieg getrennt = Nein
208 | Aufstiegshilfe = Nein
209 | Beleuchtungsanlage = Nein
214 | Telefonauskunft = +43-664-1808482 (Bergkristallhütte)
215 | Bild = Rodelbahn Bergkristallhütte 2009-03-03.jpg
216 | In Übersichtskarte = Ja
219 Die Rodelbahn zur Bergkristallhütte ist durchaus abwechslungsreich.'''
220 start, end, sledrun = wrpylib.wrmwmarkup.rodelbahnbox_to_sledrun(wikitext)
221 wrpylib.wrmwmarkup.sledrun_to_rodelbahnbox(sledrun)
224 def test_RodelbahnboxDictConverter(self):
225 v = wrpylib.wrmwmarkup.RodelbahnboxDictConverter()
227 sledrun = v.to_python(other)
228 assert sledrun.forum_id == 72
229 other2 = v.from_python(sledrun)
230 assert other == other2
233 def test_RodelbahnboxValidator(self):
234 v = wrpylib.wrmwmarkup.RodelbahnboxValidator()
235 wikitext = textwrap.dedent('''\
237 | Position = 47.309820 N 9.986508 E
244 | Lawinen = gelegentlich
246 | Öffentliche Anreise = Ja
247 | Aufstieg möglich = Nein
248 | Aufstieg getrennt = Nein
250 | Aufstiegshilfe = Nein
251 | Beleuchtungsanlage = Nein
256 | Telefonauskunft = +43-664-1808482 (Bergkristallhütte)
257 | Bild = Rodelbahn Bergkristallhütte 2009-03-03.jpg
258 | In Übersichtskarte = Ja
261 sledrun = v.to_python(wikitext)
262 wikitext2 = v.from_python(sledrun)
263 assert wikitext == wikitext2
264 wikitext = textwrap.dedent('''\
275 | Öffentliche Anreise =
277 | Aufstieg getrennt =
280 | Beleuchtungsanlage =
287 | In Übersichtskarte =
290 sledrun = v.to_python(wikitext)
291 wikitext2 = v.from_python(sledrun)
292 assert wikitext == wikitext2
295 def test_gasthausbox_to_inn(self):
296 wikitext = '''{{Gasthausbox
297 | Position = 47.295549 N 9.986970 E
304 | Handyempfang = A1; T-Mobile/Telering
305 | Homepage = http://www.bergkristallhuette.com/
306 | E-Mail = bergkristallhuette@gmx.at
307 | Telefon = +43-664-1808482
308 | Bild = Bergkritsallhütte 2009-02-07.JPG
309 | Rodelbahnen = [[Bergkristallhütte]]
311 Die Bergkristallhütte ist Teil des Boden-Vorsäß.'''
312 start, end, inn = wrpylib.wrmwmarkup.gasthausbox_to_inn(wikitext)
313 wrpylib.wrmwmarkup.inn_to_gasthausbox(inn)
316 def test_GasthausboxDictConverter(self):
317 v = wrpylib.wrmwmarkup.GasthausboxDictConverter()
318 other = collections.OrderedDict([
319 ('Position', (47.295549, 9.986970)),
322 ('Sitzplätze', None),
323 ('Übernachtung', (None, None)),
324 ('Rauchfrei', (True, False)),
325 ('Rodelverleih', (None, None)),
326 ('Handyempfang', 'A1; T-Mobile/Telering'),
327 ('Homepage', 'http://www.bergkristallhuette.com/'),
328 ('E-Mail', 'bergkristallhuette@gmx.at'),
329 ('Telefon', '+43-664-1808482'),
330 ('Bild', 'Bergkritsallhütte 2009-02-07.JPG'),
331 ('Rodelbahnen', '[[Bergkristallhütte]]')])
332 inn = v.to_python(other)
333 assert inn.homepage == 'http://www.bergkristallhuette.com/'
334 other2 = v.from_python(inn)
335 assert other == other2
338 def test_GasthausboxValidator(self):
339 v = wrpylib.wrmwmarkup.GasthausboxValidator()
340 wikitext = textwrap.dedent('''\
342 | Position = 47.295549 N 9.986970 E
349 | Handyempfang = A1; T-Mobile/Telering
350 | Homepage = http://www.bergkristallhuette.com/
351 | E-Mail = bergkristallhuette@gmx.at
352 | Telefon = +43-664-1808482
353 | Bild = Bergkritsallhütte 2009-02-07.JPG
354 | Rodelbahnen = [[Bergkristallhütte]]
356 inn = v.to_python(wikitext)
357 wikitext2 = v.from_python(inn)
358 assert wikitext == wikitext2
361 def test_googlemap_to_wrmap(self):
363 <googlemap version="0.9" lat="47.113291" lon="11.272337" zoom="15" height="450">
364 (Parkplatz)47.114958,11.266026
367 (Gasthaus) 47.114715, 11.266262, Alt Bärnbad (Gasthaus)
376 attributes, coords, paths = wrpylib.mwmarkup.parse_googlemap(wikitext)
377 json = wrpylib.wrmwmarkup.googlemap_to_wrmap(attributes, coords, paths)
378 assert json['properties']['lon'] == 11.272337
379 assert json['properties']['lat'] == 47.113291
380 assert json['properties']['zoom'] == 15
381 assert json['properties']['height'] == 450
382 assert json['features'][0]['properties']['type'] == 'parkplatz'
383 assert json['features'][0]['properties']['name'] == 'Erster Parkplatz'
384 assert json['features'][0]['geometry']['coordinates'] == [11.266026, 47.114958]
385 assert json['features'][1]['properties']['type'] == 'gasthaus'
386 assert json['features'][1]['properties']['name'] == 'Alt Bärnbad (Gasthaus)'
387 assert json['features'][1]['geometry']['coordinates'] == [11.266262, 47.114715]
388 assert json['features'][2]['properties']['type'] == 'rodelbahn'
389 assert json['features'][2]['geometry']['coordinates'] == [
390 [11.266262, 47.114715],
391 [11.268381, 47.114135],
392 [11.269322, 47.113421],
393 [11.269979, 47.11277],
394 [11.271119, 47.112408]]
396 def test_parse_wrmap(self):
398 <wrmap lat="47.2417134" lon="11.21408895" zoom="14" width="700" height="400">
399 <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 11.190454</gasthaus>
400 <parkplatz>47.245789 11.238971</parkplatz>
401 <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 11.238283</haltestelle>
409 json = wrpylib.wrmwmarkup.parse_wrmap(wikitext)
410 assert json['properties']['lon'] == 11.21408895
411 assert json['properties']['lat'] == 47.2417134
412 assert json['properties']['zoom'] == 14
413 assert json['properties']['width'] == 700
414 assert json['properties']['height'] == 400
415 assert json['features'][0]['properties']['type'] == 'gasthaus'
416 assert json['features'][0]['properties']['name'] == 'Rosskogelhütte'
417 assert json['features'][0]['properties']['wiki'] == 'Rosskogelhütte'
418 assert json['features'][0]['geometry']['coordinates'] == [11.190454, 47.240689]
419 assert json['features'][1]['properties']['type'] == 'parkplatz'
420 assert json['features'][1]['geometry']['coordinates'] == [11.238971, 47.245789]
421 assert json['features'][2]['properties']['type'] == 'haltestelle'
422 assert json['features'][2]['properties']['name'] == 'Oberperfuss Rangger Köpfl Lift'
423 assert json['features'][2]['geometry']['coordinates'] == [11.238283, 47.245711]
424 assert json['features'][3]['properties']['type'] == 'rodelbahn'
425 assert json['features'][3]['geometry']['coordinates'] == [
426 [11.203360, 47.238587],
427 [11.230868, 47.244951],
428 [11.237853, 47.245470]]
430 def test_create_wrmap(self):
432 'type': 'FeatureCollection',
438 'coordinates': [11.190454, 47.240689]},
439 'properties': {'type': 'gasthaus', 'name': 'Rosskogelhütte', 'wiki': 'Rosskogelhütte'}
444 'coordinates': [11.238971, 47.245789]},
445 'properties': {'type': 'parkplatz'}
450 'coordinates': [11.238283, 47.245711]},
451 'properties': {'type': 'haltestelle', 'name': 'Oberperfuss Rangger Köpfl Lift'}
455 'type': 'LineString',
457 [11.203360, 47.238587],
458 [11.230868, 47.244951],
459 [11.237853, 47.245470]]},
460 'properties': {'type': 'rodelbahn'}
470 wikitext = wrpylib.wrmwmarkup.create_wrmap(geojson)
471 assert wikitext == textwrap.dedent('''\
472 <wrmap height="400" lat="47.241713" lon="11.214089" width="700" zoom="14">
474 <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 N 11.190454 E</gasthaus>
475 <parkplatz>47.245789 N 11.238971 E</parkplatz>
476 <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 N 11.238283 E</haltestelle>
479 47.238587 N 11.203360 E
480 47.244951 N 11.230868 E
481 47.245470 N 11.237853 E