2 # -*- coding: iso-8859-15 -*-
6 import mwparserfromhell
7 import wrpylib.mwmarkup
8 from wrpylib.wrmwmarkup import *
11 class TestSledrun(unittest.TestCase):
12 def test_sledrun_from_rodelbahnbox(self):
15 rodelbahnbox = collections.OrderedDict([
16 ('Position', LonLat(9.986508, 47.30982)),
17 ('Position oben', LonLat(None, None)),
19 ('Position unten', LonLat(8.506047, 46.20210)),
24 ('Betreiber', 'SchneeFunFit'),
25 ('Öffentliche Anreise', 2),
26 ('Aufstieg möglich', True),
27 ('Aufstieg getrennt', (0.0, None)),
29 ('Aufstiegshilfe', [('Sessellift', 'gratis'), ('Bus', None)]),
30 ('Beleuchtungsanlage', (0.0, 'in Planung für 2020')),
31 ('Beleuchtungstage', (None, None)),
34 ('Webauskunft', (True, 'http://example.com/schneelage')),
35 ('Telefonauskunft', [('+43-664-1808482', 'Bergkristallhütte')]),
36 ('Bild', 'Rodelbahn Bergkristallhütte 2009-03-03.jpg'),
37 ('In Übersichtskarte', True),
40 sledrun_from_rodelbahnbox(rodelbahnbox, sledrun)
41 self.assertEqual(47.30982, sledrun.position_latitude)
42 self.assertEqual(9.986508, sledrun.position_longitude)
43 self.assertEqual(None, sledrun.top_latitude)
44 self.assertEqual(None, sledrun.top_longitude)
45 self.assertEqual(1244, sledrun.top_elevation)
46 self.assertEqual(46.20210, sledrun.bottom_latitude)
47 self.assertEqual(8.506047, sledrun.bottom_longitude)
48 self.assertEqual(None, sledrun.bottom_elevation)
49 self.assertEqual(5045, sledrun.length)
50 self.assertEqual(3, sledrun.difficulty)
51 self.assertEqual(2, sledrun.avalanches)
52 self.assertEqual('SchneeFunFit', sledrun.operator)
53 self.assertEqual(2, sledrun.public_transport)
54 self.assertEqual(True, sledrun.walkup_possible)
55 self.assertEqual(105, sledrun.walkup_time)
56 self.assertEqual(0.0, sledrun.walkup_separate)
57 self.assertEqual(None, sledrun.walkup_separate_comment)
58 self.assertEqual(True, sledrun.lift)
59 self.assertEqual('Sessellift (gratis); Bus', sledrun.lift_details)
60 self.assertEqual(0.0, sledrun.night_light)
61 self.assertEqual('in Planung für 2020', sledrun.night_light_comment)
62 self.assertEqual(None, sledrun.night_light_days)
63 self.assertEqual(None, sledrun.night_light_days_comment)
64 self.assertEqual(False, sledrun.sled_rental)
65 self.assertEqual('Nein', sledrun.sled_rental_comment)
66 self.assertEqual('Nein', sledrun.cachet)
67 self.assertEqual('http://example.com/schneelage', sledrun.information_web)
68 self.assertEqual('+43-664-1808482 (Bergkristallhütte)', sledrun.information_phone)
69 self.assertEqual('Rodelbahn Bergkristallhütte 2009-03-03.jpg', sledrun.image)
70 self.assertEqual(True, sledrun.show_in_overview)
71 self.assertEqual(72, sledrun.forum_id)
73 def test_sledrun_to_rodelbahnbox(self):
77 sledrun.position_longitude = 13.5
78 sledrun.position_latitude = 50.7
79 sledrun.top_longitude = 12.2
80 sledrun.top_latitude = 49.8
81 sledrun.top_elevation = 3456
82 sledrun.bottom_longitude = 9.89
83 sledrun.bottom_latitude = 51.2
84 sledrun.bottom_elevation = 2075
86 sledrun.difficulty = 3
87 sledrun.avalanches = 2
88 sledrun.operator = 'McRodel'
89 sledrun.public_transport = 3
90 sledrun.walkup_possible = True
91 sledrun.walkup_time = 77
92 sledrun.walkup_separate = 0.5
93 sledrun.walkup_separate_comment = 'Nur unterer Teil'
95 sledrun.lift_details = 'Sessellift'
96 sledrun.night_light = 1.0
97 sledrun.night_light_comment = 'Schlecht beleuchtet'
98 sledrun.night_light_days = 6
99 sledrun.night_light_days_comment = 'Mo-Sa'
100 sledrun.sled_rental = True
101 sledrun.sled_rental_comment = 'In der Hütte'
102 sledrun.cachet = 'Tiroler Rodelbahngütesielgel mittelschwer 2010'
103 sledrun.information_web = 'http://example.com'
104 sledrun.information_phone = '+4364412345678'
105 sledrun.image = 'Sicht_von_unten.jpg'
106 sledrun.show_in_overview = True
107 sledrun.forum_id = 65
108 rodelbahnbox = sledrun_to_rodelbahnbox(sledrun)
109 self.assertEqual(rodelbahnbox['Position'], LonLat(lon=13.5, lat=50.7))
110 self.assertEqual(rodelbahnbox['Position oben'], LonLat(12.2, 49.8))
111 self.assertEqual(rodelbahnbox['Höhe oben'], 3456)
112 self.assertEqual(rodelbahnbox['Position unten'], LonLat(9.89, 51.2))
113 self.assertEqual(rodelbahnbox['Höhe unten'], 2075)
114 self.assertEqual(rodelbahnbox['Länge'], 9644)
115 self.assertEqual(rodelbahnbox['Schwierigkeit'], 3)
116 self.assertEqual(rodelbahnbox['Lawinen'], 2)
117 self.assertEqual(rodelbahnbox['Betreiber'], 'McRodel')
118 self.assertEqual(rodelbahnbox['Öffentliche Anreise'], 3)
119 self.assertEqual(rodelbahnbox['Aufstieg möglich'], True)
120 self.assertEqual(rodelbahnbox['Aufstieg getrennt'], (0.5, 'Nur unterer Teil'))
121 self.assertEqual(rodelbahnbox['Gehzeit'], 77)
122 self.assertEqual(rodelbahnbox['Aufstiegshilfe'], [('Sessellift', None)])
123 self.assertEqual(rodelbahnbox['Beleuchtungsanlage'], (1.0, 'Schlecht beleuchtet'))
124 self.assertEqual(rodelbahnbox['Beleuchtungstage'], (6, 'Mo-Sa'))
125 self.assertEqual(rodelbahnbox['Rodelverleih'], (True, 'In der Hütte'))
126 self.assertEqual(rodelbahnbox['Gütesiegel'], 'Tiroler Rodelbahngütesielgel mittelschwer 2010')
127 self.assertEqual(rodelbahnbox['Webauskunft'], 'http://example.com')
128 self.assertEqual(rodelbahnbox['Bild'], 'Sicht_von_unten.jpg')
129 self.assertEqual(rodelbahnbox['In Übersichtskarte'], True)
130 self.assertEqual(rodelbahnbox['Forumid'], 65)
133 class TestInn(unittest.TestCase):
134 def test_inn_from_gasthausbox(self):
137 gasthausbox = [] # TODO: populate for test
139 inn_from_gasthausbox(gasthausbox, inn)
142 def test_inn_to_gasthausbox(self):
145 inn = Inn() # TODO: populate for test
146 gasthausbox = inn_to_gasthausbox(inn)
150 class TestLonlatEle(unittest.TestCase):
151 def test_lonlat_ele_from_template(self):
152 template = mwparserfromhell.parse('{{Position oben|46.942239 N 11.468819 E|1866}}').filter_templates()[0]
153 lonlat, ele = lonlat_ele_from_template(template)
154 self.assertEqual(LonLat(11.468819, 46.942239), lonlat)
155 self.assertEqual(1866, ele)
157 def test_latlon_ele_to_template(self):
158 template = latlon_ele_to_template((LonLat(11.468819, 46.942239), 1866), 'Position oben')
159 self.assertEqual('{{Position oben|46.942239 N 11.468819 E|1866}}', template)
162 class TestWrMwMarkup(unittest.TestCase):
163 def test_rodelbahnbox_to_sledrun(self):
164 wikitext = '''== Allgemeines ==
166 | Position = 47.309820 N 9.986508 E
173 | Lawinen = gelegentlich
175 | Öffentliche Anreise = Ja
177 | Aufstieg möglich = Nein
178 | Aufstieg getrennt = Nein
179 | Aufstiegshilfe = Nein
180 | Beleuchtungsanlage = Nein
185 | Telefonauskunft = +43-664-1808482 (Bergkristallhütte)
186 | Bild = Rodelbahn Bergkristallhütte 2009-03-03.jpg
187 | In Übersichtskarte = Ja
190 Die Rodelbahn zur Bergkristallhütte ist durchaus abwechslungsreich.'''
191 start, end, sledrun = wrpylib.wrmwmarkup.rodelbahnbox_to_sledrun(wikitext)
192 wrpylib.wrmwmarkup.sledrun_to_rodelbahnbox(sledrun)
195 def test_RodelbahnboxDictConverter(self):
196 v = wrpylib.wrmwmarkup.RodelbahnboxDictConverter()
198 sledrun = v.to_python(other)
199 assert sledrun.forum_id == 72
200 other2 = v.from_python(sledrun)
201 assert other == other2
204 def test_RodelbahnboxValidator(self):
205 v = wrpylib.wrmwmarkup.RodelbahnboxValidator()
206 wikitext = textwrap.dedent('''\
208 | Position = 47.309820 N 9.986508 E
215 | Lawinen = gelegentlich
217 | Öffentliche Anreise = Ja
218 | Aufstieg möglich = Nein
219 | Aufstieg getrennt = Nein
221 | Aufstiegshilfe = Nein
222 | Beleuchtungsanlage = Nein
227 | Telefonauskunft = +43-664-1808482 (Bergkristallhütte)
228 | Bild = Rodelbahn Bergkristallhütte 2009-03-03.jpg
229 | In Übersichtskarte = Ja
232 sledrun = v.to_python(wikitext)
233 wikitext2 = v.from_python(sledrun)
234 assert wikitext == wikitext2
235 wikitext = textwrap.dedent('''\
246 | Öffentliche Anreise =
248 | Aufstieg getrennt =
251 | Beleuchtungsanlage =
258 | In Übersichtskarte =
261 sledrun = v.to_python(wikitext)
262 wikitext2 = v.from_python(sledrun)
263 assert wikitext == wikitext2
266 def test_gasthausbox_to_inn(self):
267 wikitext = '''{{Gasthausbox
268 | Position = 47.295549 N 9.986970 E
275 | Handyempfang = A1; T-Mobile/Telering
276 | Homepage = http://www.bergkristallhuette.com/
277 | E-Mail = bergkristallhuette@gmx.at
278 | Telefon = +43-664-1808482
279 | Bild = Bergkritsallhütte 2009-02-07.JPG
280 | Rodelbahnen = [[Bergkristallhütte]]
282 Die Bergkristallhütte ist Teil des Boden-Vorsäß.'''
283 start, end, inn = wrpylib.wrmwmarkup.gasthausbox_to_inn(wikitext)
284 wrpylib.wrmwmarkup.inn_to_gasthausbox(inn)
287 def test_GasthausboxDictConverter(self):
288 v = wrpylib.wrmwmarkup.GasthausboxDictConverter()
289 other = collections.OrderedDict([
290 ('Position', (47.295549, 9.986970)),
293 ('Sitzplätze', None),
294 ('Übernachtung', (None, None)),
295 ('Rauchfrei', (True, False)),
296 ('Rodelverleih', (None, None)),
297 ('Handyempfang', 'A1; T-Mobile/Telering'),
298 ('Homepage', 'http://www.bergkristallhuette.com/'),
299 ('E-Mail', 'bergkristallhuette@gmx.at'),
300 ('Telefon', '+43-664-1808482'),
301 ('Bild', 'Bergkritsallhütte 2009-02-07.JPG'),
302 ('Rodelbahnen', '[[Bergkristallhütte]]')])
303 inn = v.to_python(other)
304 assert inn.homepage == 'http://www.bergkristallhuette.com/'
305 other2 = v.from_python(inn)
306 assert other == other2
309 def test_GasthausboxValidator(self):
310 v = wrpylib.wrmwmarkup.GasthausboxValidator()
311 wikitext = textwrap.dedent('''\
313 | Position = 47.295549 N 9.986970 E
320 | Handyempfang = A1; T-Mobile/Telering
321 | Homepage = http://www.bergkristallhuette.com/
322 | E-Mail = bergkristallhuette@gmx.at
323 | Telefon = +43-664-1808482
324 | Bild = Bergkritsallhütte 2009-02-07.JPG
325 | Rodelbahnen = [[Bergkristallhütte]]
327 inn = v.to_python(wikitext)
328 wikitext2 = v.from_python(inn)
329 assert wikitext == wikitext2
332 def test_googlemap_to_wrmap(self):
334 <googlemap version="0.9" lat="47.113291" lon="11.272337" zoom="15" height="450">
335 (Parkplatz)47.114958,11.266026
338 (Gasthaus) 47.114715, 11.266262, Alt Bärnbad (Gasthaus)
347 attributes, coords, paths = wrpylib.mwmarkup.parse_googlemap(wikitext)
348 json = wrpylib.wrmwmarkup.googlemap_to_wrmap(attributes, coords, paths)
349 assert json['properties']['lon'] == 11.272337
350 assert json['properties']['lat'] == 47.113291
351 assert json['properties']['zoom'] == 15
352 assert json['properties']['height'] == 450
353 assert json['features'][0]['properties']['type'] == 'parkplatz'
354 assert json['features'][0]['properties']['name'] == 'Erster Parkplatz'
355 assert json['features'][0]['geometry']['coordinates'] == [11.266026, 47.114958]
356 assert json['features'][1]['properties']['type'] == 'gasthaus'
357 assert json['features'][1]['properties']['name'] == 'Alt Bärnbad (Gasthaus)'
358 assert json['features'][1]['geometry']['coordinates'] == [11.266262, 47.114715]
359 assert json['features'][2]['properties']['type'] == 'rodelbahn'
360 assert json['features'][2]['geometry']['coordinates'] == [
361 [11.266262, 47.114715],
362 [11.268381, 47.114135],
363 [11.269322, 47.113421],
364 [11.269979, 47.11277],
365 [11.271119, 47.112408]]
367 def test_parse_wrmap(self):
369 <wrmap lat="47.2417134" lon="11.21408895" zoom="14" width="700" height="400">
370 <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 11.190454</gasthaus>
371 <parkplatz>47.245789 11.238971</parkplatz>
372 <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 11.238283</haltestelle>
380 json = wrpylib.wrmwmarkup.parse_wrmap(wikitext)
381 assert json['properties']['lon'] == 11.21408895
382 assert json['properties']['lat'] == 47.2417134
383 assert json['properties']['zoom'] == 14
384 assert json['properties']['width'] == 700
385 assert json['properties']['height'] == 400
386 assert json['features'][0]['properties']['type'] == 'gasthaus'
387 assert json['features'][0]['properties']['name'] == 'Rosskogelhütte'
388 assert json['features'][0]['properties']['wiki'] == 'Rosskogelhütte'
389 assert json['features'][0]['geometry']['coordinates'] == [11.190454, 47.240689]
390 assert json['features'][1]['properties']['type'] == 'parkplatz'
391 assert json['features'][1]['geometry']['coordinates'] == [11.238971, 47.245789]
392 assert json['features'][2]['properties']['type'] == 'haltestelle'
393 assert json['features'][2]['properties']['name'] == 'Oberperfuss Rangger Köpfl Lift'
394 assert json['features'][2]['geometry']['coordinates'] == [11.238283, 47.245711]
395 assert json['features'][3]['properties']['type'] == 'rodelbahn'
396 assert json['features'][3]['geometry']['coordinates'] == [
397 [11.203360, 47.238587],
398 [11.230868, 47.244951],
399 [11.237853, 47.245470]]
401 def test_create_wrmap(self):
403 'type': 'FeatureCollection',
409 'coordinates': [11.190454, 47.240689]},
410 'properties': {'type': 'gasthaus', 'name': 'Rosskogelhütte', 'wiki': 'Rosskogelhütte'}
415 'coordinates': [11.238971, 47.245789]},
416 'properties': {'type': 'parkplatz'}
421 'coordinates': [11.238283, 47.245711]},
422 'properties': {'type': 'haltestelle', 'name': 'Oberperfuss Rangger Köpfl Lift'}
426 'type': 'LineString',
428 [11.203360, 47.238587],
429 [11.230868, 47.244951],
430 [11.237853, 47.245470]]},
431 'properties': {'type': 'rodelbahn'}
441 wikitext = wrpylib.wrmwmarkup.create_wrmap(geojson)
442 assert wikitext == textwrap.dedent('''\
443 <wrmap height="400" lat="47.241713" lon="11.214089" width="700" zoom="14">
445 <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 N 11.190454 E</gasthaus>
446 <parkplatz>47.245789 N 11.238971 E</parkplatz>
447 <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 N 11.238283 E</haltestelle>
450 47.238587 N 11.203360 E
451 47.244951 N 11.230868 E
452 47.245470 N 11.237853 E