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):
177 inn = Inn() # TODO: populate for test
178 gasthausbox = inn_to_gasthausbox(inn)
182 class TestLonlatEle(unittest.TestCase):
183 def test_lonlat_ele_from_template(self):
184 template = mwparserfromhell.parse('{{Position oben|46.942239 N 11.468819 E|1866}}').filter_templates()[0]
185 lonlat, ele = lonlat_ele_from_template(template)
186 self.assertEqual(LonLat(11.468819, 46.942239), lonlat)
187 self.assertEqual(1866, ele)
189 def test_latlon_ele_to_template(self):
190 template = latlon_ele_to_template((LonLat(11.468819, 46.942239), 1866), 'Position oben')
191 self.assertEqual('{{Position oben|46.942239 N 11.468819 E|1866}}', template)
194 class TestWrMwMarkup(unittest.TestCase):
195 def test_rodelbahnbox_to_sledrun(self):
196 wikitext = '''== Allgemeines ==
198 | Position = 47.309820 N 9.986508 E
205 | Lawinen = gelegentlich
207 | Öffentliche Anreise = Ja
209 | Aufstieg möglich = Nein
210 | Aufstieg getrennt = Nein
211 | Aufstiegshilfe = Nein
212 | Beleuchtungsanlage = Nein
217 | Telefonauskunft = +43-664-1808482 (Bergkristallhütte)
218 | Bild = Rodelbahn Bergkristallhütte 2009-03-03.jpg
219 | In Übersichtskarte = Ja
222 Die Rodelbahn zur Bergkristallhütte ist durchaus abwechslungsreich.'''
223 start, end, sledrun = wrpylib.wrmwmarkup.rodelbahnbox_to_sledrun(wikitext)
224 wrpylib.wrmwmarkup.sledrun_to_rodelbahnbox(sledrun)
227 def test_RodelbahnboxDictConverter(self):
228 v = wrpylib.wrmwmarkup.RodelbahnboxDictConverter()
230 sledrun = v.to_python(other)
231 assert sledrun.forum_id == 72
232 other2 = v.from_python(sledrun)
233 assert other == other2
236 def test_RodelbahnboxValidator(self):
237 v = wrpylib.wrmwmarkup.RodelbahnboxValidator()
238 wikitext = textwrap.dedent('''\
240 | Position = 47.309820 N 9.986508 E
247 | Lawinen = gelegentlich
249 | Öffentliche Anreise = Ja
250 | Aufstieg möglich = Nein
251 | Aufstieg getrennt = Nein
253 | Aufstiegshilfe = Nein
254 | Beleuchtungsanlage = Nein
259 | Telefonauskunft = +43-664-1808482 (Bergkristallhütte)
260 | Bild = Rodelbahn Bergkristallhütte 2009-03-03.jpg
261 | In Übersichtskarte = Ja
264 sledrun = v.to_python(wikitext)
265 wikitext2 = v.from_python(sledrun)
266 assert wikitext == wikitext2
267 wikitext = textwrap.dedent('''\
278 | Öffentliche Anreise =
280 | Aufstieg getrennt =
283 | Beleuchtungsanlage =
290 | In Übersichtskarte =
293 sledrun = v.to_python(wikitext)
294 wikitext2 = v.from_python(sledrun)
295 assert wikitext == wikitext2
298 def test_gasthausbox_to_inn(self):
299 wikitext = '''{{Gasthausbox
300 | Position = 47.295549 N 9.986970 E
307 | Handyempfang = A1; T-Mobile/Telering
308 | Homepage = http://www.bergkristallhuette.com/
309 | E-Mail = bergkristallhuette@gmx.at
310 | Telefon = +43-664-1808482
311 | Bild = Bergkritsallhütte 2009-02-07.JPG
312 | Rodelbahnen = [[Bergkristallhütte]]
314 Die Bergkristallhütte ist Teil des Boden-Vorsäß.'''
315 start, end, inn = wrpylib.wrmwmarkup.gasthausbox_to_inn(wikitext)
316 wrpylib.wrmwmarkup.inn_to_gasthausbox(inn)
319 def test_GasthausboxDictConverter(self):
320 v = wrpylib.wrmwmarkup.GasthausboxDictConverter()
321 other = collections.OrderedDict([
322 ('Position', (47.295549, 9.986970)),
325 ('Sitzplätze', None),
326 ('Übernachtung', (None, None)),
327 ('Rauchfrei', (True, False)),
328 ('Rodelverleih', (None, None)),
329 ('Handyempfang', 'A1; T-Mobile/Telering'),
330 ('Homepage', 'http://www.bergkristallhuette.com/'),
331 ('E-Mail', 'bergkristallhuette@gmx.at'),
332 ('Telefon', '+43-664-1808482'),
333 ('Bild', 'Bergkritsallhütte 2009-02-07.JPG'),
334 ('Rodelbahnen', '[[Bergkristallhütte]]')])
335 inn = v.to_python(other)
336 assert inn.homepage == 'http://www.bergkristallhuette.com/'
337 other2 = v.from_python(inn)
338 assert other == other2
341 def test_GasthausboxValidator(self):
342 v = wrpylib.wrmwmarkup.GasthausboxValidator()
343 wikitext = textwrap.dedent('''\
345 | Position = 47.295549 N 9.986970 E
352 | Handyempfang = A1; T-Mobile/Telering
353 | Homepage = http://www.bergkristallhuette.com/
354 | E-Mail = bergkristallhuette@gmx.at
355 | Telefon = +43-664-1808482
356 | Bild = Bergkritsallhütte 2009-02-07.JPG
357 | Rodelbahnen = [[Bergkristallhütte]]
359 inn = v.to_python(wikitext)
360 wikitext2 = v.from_python(inn)
361 assert wikitext == wikitext2
364 def test_googlemap_to_wrmap(self):
366 <googlemap version="0.9" lat="47.113291" lon="11.272337" zoom="15" height="450">
367 (Parkplatz)47.114958,11.266026
370 (Gasthaus) 47.114715, 11.266262, Alt Bärnbad (Gasthaus)
379 attributes, coords, paths = wrpylib.mwmarkup.parse_googlemap(wikitext)
380 json = wrpylib.wrmwmarkup.googlemap_to_wrmap(attributes, coords, paths)
381 assert json['properties']['lon'] == 11.272337
382 assert json['properties']['lat'] == 47.113291
383 assert json['properties']['zoom'] == 15
384 assert json['properties']['height'] == 450
385 assert json['features'][0]['properties']['type'] == 'parkplatz'
386 assert json['features'][0]['properties']['name'] == 'Erster Parkplatz'
387 assert json['features'][0]['geometry']['coordinates'] == [11.266026, 47.114958]
388 assert json['features'][1]['properties']['type'] == 'gasthaus'
389 assert json['features'][1]['properties']['name'] == 'Alt Bärnbad (Gasthaus)'
390 assert json['features'][1]['geometry']['coordinates'] == [11.266262, 47.114715]
391 assert json['features'][2]['properties']['type'] == 'rodelbahn'
392 assert json['features'][2]['geometry']['coordinates'] == [
393 [11.266262, 47.114715],
394 [11.268381, 47.114135],
395 [11.269322, 47.113421],
396 [11.269979, 47.11277],
397 [11.271119, 47.112408]]
399 def test_parse_wrmap(self):
401 <wrmap lat="47.2417134" lon="11.21408895" zoom="14" width="700" height="400">
402 <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 11.190454</gasthaus>
403 <parkplatz>47.245789 11.238971</parkplatz>
404 <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 11.238283</haltestelle>
412 json = wrpylib.wrmwmarkup.parse_wrmap(wikitext)
413 assert json['properties']['lon'] == 11.21408895
414 assert json['properties']['lat'] == 47.2417134
415 assert json['properties']['zoom'] == 14
416 assert json['properties']['width'] == 700
417 assert json['properties']['height'] == 400
418 assert json['features'][0]['properties']['type'] == 'gasthaus'
419 assert json['features'][0]['properties']['name'] == 'Rosskogelhütte'
420 assert json['features'][0]['properties']['wiki'] == 'Rosskogelhütte'
421 assert json['features'][0]['geometry']['coordinates'] == [11.190454, 47.240689]
422 assert json['features'][1]['properties']['type'] == 'parkplatz'
423 assert json['features'][1]['geometry']['coordinates'] == [11.238971, 47.245789]
424 assert json['features'][2]['properties']['type'] == 'haltestelle'
425 assert json['features'][2]['properties']['name'] == 'Oberperfuss Rangger Köpfl Lift'
426 assert json['features'][2]['geometry']['coordinates'] == [11.238283, 47.245711]
427 assert json['features'][3]['properties']['type'] == 'rodelbahn'
428 assert json['features'][3]['geometry']['coordinates'] == [
429 [11.203360, 47.238587],
430 [11.230868, 47.244951],
431 [11.237853, 47.245470]]
433 def test_create_wrmap(self):
435 'type': 'FeatureCollection',
441 'coordinates': [11.190454, 47.240689]},
442 'properties': {'type': 'gasthaus', 'name': 'Rosskogelhütte', 'wiki': 'Rosskogelhütte'}
447 'coordinates': [11.238971, 47.245789]},
448 'properties': {'type': 'parkplatz'}
453 'coordinates': [11.238283, 47.245711]},
454 'properties': {'type': 'haltestelle', 'name': 'Oberperfuss Rangger Köpfl Lift'}
458 'type': 'LineString',
460 [11.203360, 47.238587],
461 [11.230868, 47.244951],
462 [11.237853, 47.245470]]},
463 'properties': {'type': 'rodelbahn'}
473 wikitext = wrpylib.wrmwmarkup.create_wrmap(geojson)
474 assert wikitext == textwrap.dedent('''\
475 <wrmap height="400" lat="47.241713" lon="11.214089" width="700" zoom="14">
477 <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 N 11.190454 E</gasthaus>
478 <parkplatz>47.245789 N 11.238971 E</parkplatz>
479 <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 N 11.238283 E</haltestelle>
482 47.238587 N 11.203360 E
483 47.244951 N 11.230868 E
484 47.245470 N 11.237853 E