5 import mwparserfromhell
6 import wrpylib.wrvalidators
7 import wrpylib.wrmwmarkup
8 from wrpylib.wrvalidators import LonLat
9 from wrpylib.wrmwmarkup import sledrun_from_rodelbahnbox, sledrun_to_rodelbahnbox, \
10 inn_from_gasthausbox, inn_to_gasthausbox, lonlat_ele_from_template, latlon_ele_to_template
13 class TestSledrun(unittest.TestCase):
14 def test_sledrun_from_rodelbahnbox(self):
17 rodelbahnbox = collections.OrderedDict([
18 ('Position', LonLat(9.986508, 47.30982)),
19 ('Position oben', LonLat(None, None)),
21 ('Position unten', LonLat(8.506047, 46.20210)),
26 ('Betreiber', 'SchneeFunFit'),
27 ('Öffentliche Anreise', 2),
28 ('Aufstieg möglich', True),
29 ('Aufstieg getrennt', (0.0, None)),
31 ('Aufstiegshilfe', [('Sessellift', 'gratis'), ('Bus', None)]),
32 ('Beleuchtungsanlage', (0.0, 'in Planung für 2020')),
33 ('Beleuchtungstage', (None, None)),
36 ('Webauskunft', (True, 'http://example.com/schneelage')),
37 ('Telefonauskunft', [('+43-664-1808482', 'Bergkristallhütte')]),
38 ('Bild', 'Rodelbahn Bergkristallhütte 2009-03-03.jpg'),
39 ('In Übersichtskarte', True),
42 sledrun_from_rodelbahnbox(rodelbahnbox, sledrun)
43 self.assertEqual(47.30982, sledrun.position_latitude)
44 self.assertEqual(9.986508, sledrun.position_longitude)
45 self.assertEqual(None, sledrun.top_latitude)
46 self.assertEqual(None, sledrun.top_longitude)
47 self.assertEqual(1244, sledrun.top_elevation)
48 self.assertEqual(46.20210, sledrun.bottom_latitude)
49 self.assertEqual(8.506047, sledrun.bottom_longitude)
50 self.assertEqual(None, sledrun.bottom_elevation)
51 self.assertEqual(5045, sledrun.length)
52 self.assertEqual(3, sledrun.difficulty)
53 self.assertEqual(2, sledrun.avalanches)
54 self.assertEqual('SchneeFunFit', sledrun.operator)
55 self.assertEqual(2, sledrun.public_transport)
56 self.assertEqual(True, sledrun.walkup_possible)
57 self.assertEqual(105, sledrun.walkup_time)
58 self.assertEqual(0.0, sledrun.walkup_separate)
59 self.assertEqual(None, sledrun.walkup_separate_comment)
60 self.assertEqual(True, sledrun.lift)
61 self.assertEqual('Sessellift (gratis); Bus', sledrun.lift_details)
62 self.assertEqual(0.0, sledrun.night_light)
63 self.assertEqual('in Planung für 2020', sledrun.night_light_comment)
64 self.assertEqual(None, sledrun.night_light_days)
65 self.assertEqual(None, sledrun.night_light_days_comment)
66 self.assertEqual(False, sledrun.sled_rental)
67 self.assertEqual('Nein', sledrun.sled_rental_comment)
68 self.assertEqual('Nein', sledrun.cachet)
69 self.assertEqual('http://example.com/schneelage', sledrun.information_web)
70 self.assertEqual('+43-664-1808482 (Bergkristallhütte)', sledrun.information_phone)
71 self.assertEqual('Rodelbahn Bergkristallhütte 2009-03-03.jpg', sledrun.image)
72 self.assertEqual(True, sledrun.show_in_overview)
73 self.assertEqual(72, sledrun.forum_id)
75 def test_sledrun_to_rodelbahnbox(self):
79 sledrun.position_longitude = 13.5
80 sledrun.position_latitude = 50.7
81 sledrun.top_longitude = 12.2
82 sledrun.top_latitude = 49.8
83 sledrun.top_elevation = 3456
84 sledrun.bottom_longitude = 9.89
85 sledrun.bottom_latitude = 51.2
86 sledrun.bottom_elevation = 2075
88 sledrun.difficulty = 3
89 sledrun.avalanches = 2
90 sledrun.operator = 'McRodel'
91 sledrun.public_transport = 3
92 sledrun.walkup_possible = True
93 sledrun.walkup_time = 77
94 sledrun.walkup_separate = 0.5
95 sledrun.walkup_separate_comment = 'Nur unterer Teil'
97 sledrun.lift_details = 'Sessellift'
98 sledrun.night_light = 1.0
99 sledrun.night_light_comment = 'Schlecht beleuchtet'
100 sledrun.night_light_days = 6
101 sledrun.night_light_days_comment = 'Mo-Sa'
102 sledrun.sled_rental = True
103 sledrun.sled_rental_comment = 'In der Hütte'
104 sledrun.cachet = 'Tiroler Rodelbahngütesielgel mittelschwer 2010'
105 sledrun.information_web = 'http://example.com'
106 sledrun.information_phone = '+4364412345678'
107 sledrun.image = 'Sicht_von_unten.jpg'
108 sledrun.show_in_overview = True
109 sledrun.forum_id = 65
110 rodelbahnbox = sledrun_to_rodelbahnbox(sledrun)
111 self.assertEqual(rodelbahnbox['Position'], LonLat(lon=13.5, lat=50.7))
112 self.assertEqual(rodelbahnbox['Position oben'], LonLat(12.2, 49.8))
113 self.assertEqual(rodelbahnbox['Höhe oben'], 3456)
114 self.assertEqual(rodelbahnbox['Position unten'], LonLat(9.89, 51.2))
115 self.assertEqual(rodelbahnbox['Höhe unten'], 2075)
116 self.assertEqual(rodelbahnbox['Länge'], 9644)
117 self.assertEqual(rodelbahnbox['Schwierigkeit'], 3)
118 self.assertEqual(rodelbahnbox['Lawinen'], 2)
119 self.assertEqual(rodelbahnbox['Betreiber'], 'McRodel')
120 self.assertEqual(rodelbahnbox['Öffentliche Anreise'], 3)
121 self.assertEqual(rodelbahnbox['Aufstieg möglich'], True)
122 self.assertEqual(rodelbahnbox['Aufstieg getrennt'], (0.5, 'Nur unterer Teil'))
123 self.assertEqual(rodelbahnbox['Gehzeit'], 77)
124 self.assertEqual(rodelbahnbox['Aufstiegshilfe'], [('Sessellift', None)])
125 self.assertEqual(rodelbahnbox['Beleuchtungsanlage'], (1.0, 'Schlecht beleuchtet'))
126 self.assertEqual(rodelbahnbox['Beleuchtungstage'], (6, 'Mo-Sa'))
127 self.assertEqual(rodelbahnbox['Rodelverleih'], (True, 'In der Hütte'))
128 self.assertEqual(rodelbahnbox['Gütesiegel'], 'Tiroler Rodelbahngütesielgel mittelschwer 2010')
129 self.assertEqual(rodelbahnbox['Webauskunft'], 'http://example.com')
130 self.assertEqual(rodelbahnbox['Bild'], 'Sicht_von_unten.jpg')
131 self.assertEqual(rodelbahnbox['In Übersichtskarte'], True)
132 self.assertEqual(rodelbahnbox['Forumid'], 65)
135 class TestInn(unittest.TestCase):
136 def test_inn_from_gasthausbox(self):
139 gasthausbox = collections.OrderedDict()
140 gasthausbox['Position'] = LonLat(11.015883, 9.876000)
141 gasthausbox['Höhe'] = 2145
142 gasthausbox['Betreiber'] = 'Max Mustermann'
143 gasthausbox['Sitzplätze'] = 30
144 gasthausbox['Übernachtung'] = (False, None)
145 gasthausbox['Rauchfrei'] = 0.5
146 gasthausbox['Rodelverleih'] = (True, '6 Euro')
147 gasthausbox['Handyempfang'] = []
148 gasthausbox['Homepage'] = (True, 'http://www.graf-ferdinand.at/')
149 gasthausbox['E-Mail'] = [(('max.mustermann@graf-ferdinand.at', False), None)]
150 gasthausbox['Telefon'] = [('+43-5039-21666', None), ('+43-686-4134880', 'Sommer')]
151 gasthausbox['Bild'] = 'Gasthaus_Graf_Ferdinand_Haus_01.jpg'
152 gasthausbox['Rodelbahnen'] = ['[[Finstertaler Speicher]]']
154 inn_from_gasthausbox(gasthausbox, inn)
155 self.assertEqual(inn.position_latitude, 9.876000)
156 self.assertEqual(inn.position_longitude, 11.015883)
157 self.assertEqual(inn.position_elevation, 2145)
158 self.assertEqual(inn.operator, 'Max Mustermann')
159 self.assertEqual(inn.seats, 30)
160 self.assertEqual(inn.overnight, False)
161 self.assertEqual(inn.overnight_comment, None)
162 self.assertEqual(inn.smoker_area, True)
163 self.assertEqual(inn.nonsmoker_area, True)
164 self.assertEqual(inn.sled_rental, True)
165 self.assertEqual(inn.sled_rental_comment, '6 Euro')
166 self.assertEqual(inn.mobile_provider, 'Nein')
167 self.assertEqual(inn.homepage, 'http://www.graf-ferdinand.at/')
168 self.assertEqual(inn.email_list, 'max.mustermann@graf-ferdinand.at')
169 self.assertEqual(inn.phone_list, '+43-5039-21666; +43-686-4134880 (Sommer)')
170 self.assertEqual(inn.image, 'Gasthaus_Graf_Ferdinand_Haus_01.jpg')
171 self.assertEqual(inn.sledding_list, '[[Finstertaler Speicher]]')
174 def test_inn_to_gasthausbox(self):
178 inn.position_latitude = 9.876000
179 inn.position_longitude = 11.015883
180 inn.position_elevation = 2145
181 inn.operator = 'Max Mustermann'
183 inn.overnight = False
184 inn.overnight_comment = None
185 inn.smoker_area = True
186 inn.nonsmoker_area = True
187 inn.sled_rental = True
188 inn.sled_rental_comment = '6 Euro'
189 inn.mobile_provider = 'Nein'
190 inn.homepage = 'http://www.graf-ferdinand.at/'
191 inn.email_list = 'max.mustermann@graf-ferdinand.at'
192 inn.phone_list = '+43-5039-21666; +43-686-4134880 (Sommer)'
193 inn.image = 'Gasthaus_Graf_Ferdinand_Haus_01.jpg'
194 inn.sledding_list = '[[Finstertaler Speicher]]'
195 gasthausbox = inn_to_gasthausbox(inn)
196 self.assertEqual(gasthausbox['Position'], LonLat(11.015883, 9.876000))
197 self.assertEqual(gasthausbox['Höhe'], 2145)
198 self.assertEqual(gasthausbox['Betreiber'], 'Max Mustermann')
199 self.assertEqual(gasthausbox['Sitzplätze'], 30)
200 self.assertEqual(gasthausbox['Übernachtung'], (False, None))
201 self.assertEqual(gasthausbox['Rauchfrei'], 0.5)
202 self.assertEqual(gasthausbox['Rodelverleih'], (True, '6 Euro'))
203 self.assertEqual(gasthausbox['Handyempfang'], [])
204 self.assertEqual(gasthausbox['Homepage'], (True, 'http://www.graf-ferdinand.at/'))
205 self.assertEqual(gasthausbox['E-Mail'], [(('max.mustermann@graf-ferdinand.at', False), None)])
206 self.assertEqual(gasthausbox['Telefon'], [('+43-5039-21666', None), ('+43-686-4134880', 'Sommer')])
207 self.assertEqual(gasthausbox['Bild'], 'Gasthaus_Graf_Ferdinand_Haus_01.jpg')
208 self.assertEqual(gasthausbox['Rodelbahnen'], ['[[Finstertaler Speicher]]'])
211 class TestLonlatEle(unittest.TestCase):
212 def test_lonlat_ele_from_template(self):
213 template = mwparserfromhell.parse('{{Position oben|46.942239 N 11.468819 E|1866}}').filter_templates()[0]
214 lonlat, ele = lonlat_ele_from_template(template)
215 self.assertEqual(LonLat(11.468819, 46.942239), lonlat)
216 self.assertEqual(1866, ele)
218 def test_latlon_ele_to_template(self):
219 template = latlon_ele_to_template((LonLat(11.468819, 46.942239), 1866), 'Position oben')
220 self.assertEqual('{{Position oben|46.942239 N 11.468819 E|1866}}', template)
223 class TestWrMwMarkup(unittest.TestCase):
224 def test_rodelbahnbox_to_sledrun(self):
225 wikitext = '''== Allgemeines ==
227 | Position = 47.309820 N 9.986508 E
234 | Lawinen = gelegentlich
236 | Öffentliche Anreise = Ja
238 | Aufstieg möglich = Nein
239 | Aufstieg getrennt = Nein
240 | Aufstiegshilfe = Nein
241 | Beleuchtungsanlage = Nein
246 | Telefonauskunft = +43-664-1808482 (Bergkristallhütte)
247 | Bild = Rodelbahn Bergkristallhütte 2009-03-03.jpg
248 | In Übersichtskarte = Ja
251 Die Rodelbahn zur Bergkristallhütte ist durchaus abwechslungsreich.'''
252 start, end, sledrun = wrpylib.wrmwmarkup.rodelbahnbox_to_sledrun(wikitext)
253 wrpylib.wrmwmarkup.sledrun_to_rodelbahnbox(sledrun)
256 def test_RodelbahnboxDictConverter(self):
257 v = wrpylib.wrmwmarkup.RodelbahnboxDictConverter()
259 sledrun = v.to_python(other)
260 assert sledrun.forum_id == 72
261 other2 = v.from_python(sledrun)
262 assert other == other2
265 def test_RodelbahnboxValidator(self):
266 v = wrpylib.wrmwmarkup.RodelbahnboxValidator()
267 wikitext = textwrap.dedent('''\
269 | Position = 47.309820 N 9.986508 E
276 | Lawinen = gelegentlich
278 | Öffentliche Anreise = Ja
279 | Aufstieg möglich = Nein
280 | Aufstieg getrennt = Nein
282 | Aufstiegshilfe = Nein
283 | Beleuchtungsanlage = Nein
288 | Telefonauskunft = +43-664-1808482 (Bergkristallhütte)
289 | Bild = Rodelbahn Bergkristallhütte 2009-03-03.jpg
290 | In Übersichtskarte = Ja
293 sledrun = v.to_python(wikitext)
294 wikitext2 = v.from_python(sledrun)
295 assert wikitext == wikitext2
296 wikitext = textwrap.dedent('''\
307 | Öffentliche Anreise =
309 | Aufstieg getrennt =
312 | Beleuchtungsanlage =
319 | In Übersichtskarte =
322 sledrun = v.to_python(wikitext)
323 wikitext2 = v.from_python(sledrun)
324 assert wikitext == wikitext2
327 def test_gasthausbox_to_inn(self):
328 wikitext = '''{{Gasthausbox
329 | Position = 47.295549 N 9.986970 E
336 | Handyempfang = A1; T-Mobile/Telering
337 | Homepage = http://www.bergkristallhuette.com/
338 | E-Mail = bergkristallhuette@gmx.at
339 | Telefon = +43-664-1808482
340 | Bild = Bergkritsallhütte 2009-02-07.JPG
341 | Rodelbahnen = [[Bergkristallhütte]]
343 Die Bergkristallhütte ist Teil des Boden-Vorsäß.'''
344 start, end, inn = wrpylib.wrmwmarkup.gasthausbox_to_inn(wikitext)
345 wrpylib.wrmwmarkup.inn_to_gasthausbox(inn)
348 def test_GasthausboxDictConverter(self):
349 v = wrpylib.wrmwmarkup.GasthausboxDictConverter()
350 other = collections.OrderedDict([
351 ('Position', (47.295549, 9.986970)),
354 ('Sitzplätze', None),
355 ('Übernachtung', (None, None)),
356 ('Rauchfrei', (True, False)),
357 ('Rodelverleih', (None, None)),
358 ('Handyempfang', 'A1; T-Mobile/Telering'),
359 ('Homepage', 'http://www.bergkristallhuette.com/'),
360 ('E-Mail', 'bergkristallhuette@gmx.at'),
361 ('Telefon', '+43-664-1808482'),
362 ('Bild', 'Bergkritsallhütte 2009-02-07.JPG'),
363 ('Rodelbahnen', '[[Bergkristallhütte]]')])
364 inn = v.to_python(other)
365 assert inn.homepage == 'http://www.bergkristallhuette.com/'
366 other2 = v.from_python(inn)
367 assert other == other2
370 def test_GasthausboxValidator(self):
371 v = wrpylib.wrmwmarkup.GasthausboxValidator()
372 wikitext = textwrap.dedent('''\
374 | Position = 47.295549 N 9.986970 E
381 | Handyempfang = A1; T-Mobile/Telering
382 | Homepage = http://www.bergkristallhuette.com/
383 | E-Mail = bergkristallhuette@gmx.at
384 | Telefon = +43-664-1808482
385 | Bild = Bergkritsallhütte 2009-02-07.JPG
386 | Rodelbahnen = [[Bergkristallhütte]]
388 inn = v.to_python(wikitext)
389 wikitext2 = v.from_python(inn)
390 assert wikitext == wikitext2
393 def test_googlemap_to_wrmap(self):
395 <googlemap version="0.9" lat="47.113291" lon="11.272337" zoom="15" height="450">
396 (Parkplatz)47.114958,11.266026
399 (Gasthaus) 47.114715, 11.266262, Alt Bärnbad (Gasthaus)
408 attributes, coords, paths = wrpylib.mwmarkup.parse_googlemap(wikitext)
409 json = wrpylib.wrmwmarkup.googlemap_to_wrmap(attributes, coords, paths)
410 assert json['properties']['lon'] == 11.272337
411 assert json['properties']['lat'] == 47.113291
412 assert json['properties']['zoom'] == 15
413 assert json['properties']['height'] == 450
414 assert json['features'][0]['properties']['type'] == 'parkplatz'
415 assert json['features'][0]['properties']['name'] == 'Erster Parkplatz'
416 assert json['features'][0]['geometry']['coordinates'] == [11.266026, 47.114958]
417 assert json['features'][1]['properties']['type'] == 'gasthaus'
418 assert json['features'][1]['properties']['name'] == 'Alt Bärnbad (Gasthaus)'
419 assert json['features'][1]['geometry']['coordinates'] == [11.266262, 47.114715]
420 assert json['features'][2]['properties']['type'] == 'rodelbahn'
421 assert json['features'][2]['geometry']['coordinates'] == [
422 [11.266262, 47.114715],
423 [11.268381, 47.114135],
424 [11.269322, 47.113421],
425 [11.269979, 47.11277],
426 [11.271119, 47.112408]]
428 def test_parse_wrmap(self):
430 <wrmap lat="47.2417134" lon="11.21408895" zoom="14" width="700" height="400">
431 <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 11.190454</gasthaus>
432 <parkplatz>47.245789 11.238971</parkplatz>
433 <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 11.238283</haltestelle>
441 json = wrpylib.wrmwmarkup.parse_wrmap(wikitext)
442 assert json['properties']['lon'] == 11.21408895
443 assert json['properties']['lat'] == 47.2417134
444 assert json['properties']['zoom'] == 14
445 assert json['properties']['width'] == 700
446 assert json['properties']['height'] == 400
447 assert json['features'][0]['properties']['type'] == 'gasthaus'
448 assert json['features'][0]['properties']['name'] == 'Rosskogelhütte'
449 assert json['features'][0]['properties']['wiki'] == 'Rosskogelhütte'
450 assert json['features'][0]['geometry']['coordinates'] == [11.190454, 47.240689]
451 assert json['features'][1]['properties']['type'] == 'parkplatz'
452 assert json['features'][1]['geometry']['coordinates'] == [11.238971, 47.245789]
453 assert json['features'][2]['properties']['type'] == 'haltestelle'
454 assert json['features'][2]['properties']['name'] == 'Oberperfuss Rangger Köpfl Lift'
455 assert json['features'][2]['geometry']['coordinates'] == [11.238283, 47.245711]
456 assert json['features'][3]['properties']['type'] == 'rodelbahn'
457 assert json['features'][3]['geometry']['coordinates'] == [
458 [11.203360, 47.238587],
459 [11.230868, 47.244951],
460 [11.237853, 47.245470]]
462 def test_create_wrmap(self):
464 'type': 'FeatureCollection',
470 'coordinates': [11.190454, 47.240689]},
471 'properties': {'type': 'gasthaus', 'name': 'Rosskogelhütte', 'wiki': 'Rosskogelhütte'}
476 'coordinates': [11.238971, 47.245789]},
477 'properties': {'type': 'parkplatz'}
482 'coordinates': [11.238283, 47.245711]},
483 'properties': {'type': 'haltestelle', 'name': 'Oberperfuss Rangger Köpfl Lift'}
487 'type': 'LineString',
489 [11.203360, 47.238587],
490 [11.230868, 47.244951],
491 [11.237853, 47.245470]]},
492 'properties': {'type': 'rodelbahn'}
502 wikitext = wrpylib.wrmwmarkup.create_wrmap(geojson)
503 assert wikitext == textwrap.dedent('''\
504 <wrmap height="400" lat="47.241713" lon="11.214089" width="700" zoom="14">
506 <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 N 11.190454 E</gasthaus>
507 <parkplatz>47.245789 N 11.238971 E</parkplatz>
508 <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 N 11.238283 E</haltestelle>
511 47.238587 N 11.203360 E
512 47.244951 N 11.230868 E
513 47.245470 N 11.237853 E