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', '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):
76 sledrun = Sledrun() # TODO: populate for test
77 rodelbahnbox = sledrun_to_rodelbahnbox(sledrun)
81 class TestInn(unittest.TestCase):
82 def test_inn_from_gasthausbox(self):
85 gasthausbox = [] # TODO: populate for test
87 inn_from_gasthausbox(gasthausbox, inn)
90 def test_inn_to_gasthausbox(self):
93 inn = Inn() # TODO: populate for test
94 gasthausbox = inn_to_gasthausbox(inn)
98 class TestLonlatEle(unittest.TestCase):
99 def test_lonlat_ele_from_template(self):
100 template = mwparserfromhell.parse('{{Position oben|46.942239 N 11.468819 E|1866}}').filter_templates()[0]
101 lonlat, ele = lonlat_ele_from_template(template)
102 self.assertEqual(LonLat(11.468819, 46.942239), lonlat)
103 self.assertEqual(1866, ele)
105 def test_latlon_ele_to_template(self):
106 template = latlon_ele_to_template((LonLat(11.468819, 46.942239), 1866), 'Position oben')
107 self.assertEqual('{{Position oben|46.942239 N 11.468819 E|1866}}', template)
110 class TestWrMwMarkup(unittest.TestCase):
111 def test_rodelbahnbox_to_sledrun(self):
112 wikitext = '''== Allgemeines ==
114 | Position = 47.309820 N 9.986508 E
121 | Lawinen = gelegentlich
123 | Öffentliche Anreise = Ja
125 | Aufstieg möglich = Nein
126 | Aufstieg getrennt = Nein
127 | Aufstiegshilfe = Nein
128 | Beleuchtungsanlage = Nein
133 | Telefonauskunft = +43-664-1808482 (Bergkristallhütte)
134 | Bild = Rodelbahn Bergkristallhütte 2009-03-03.jpg
135 | In Übersichtskarte = Ja
138 Die Rodelbahn zur Bergkristallhütte ist durchaus abwechslungsreich.'''
139 start, end, sledrun = wrpylib.wrmwmarkup.rodelbahnbox_to_sledrun(wikitext)
140 wrpylib.wrmwmarkup.sledrun_to_rodelbahnbox(sledrun)
143 def test_RodelbahnboxDictConverter(self):
144 v = wrpylib.wrmwmarkup.RodelbahnboxDictConverter()
146 sledrun = v.to_python(other)
147 assert sledrun.forum_id == 72
148 other2 = v.from_python(sledrun)
149 assert other == other2
152 def test_RodelbahnboxValidator(self):
153 v = wrpylib.wrmwmarkup.RodelbahnboxValidator()
154 wikitext = textwrap.dedent('''\
156 | Position = 47.309820 N 9.986508 E
163 | Lawinen = gelegentlich
165 | Öffentliche Anreise = Ja
166 | Aufstieg möglich = Nein
167 | Aufstieg getrennt = Nein
169 | Aufstiegshilfe = Nein
170 | Beleuchtungsanlage = Nein
175 | Telefonauskunft = +43-664-1808482 (Bergkristallhütte)
176 | Bild = Rodelbahn Bergkristallhütte 2009-03-03.jpg
177 | In Übersichtskarte = Ja
180 sledrun = v.to_python(wikitext)
181 wikitext2 = v.from_python(sledrun)
182 assert wikitext == wikitext2
183 wikitext = textwrap.dedent('''\
194 | Öffentliche Anreise =
196 | Aufstieg getrennt =
199 | Beleuchtungsanlage =
206 | In Übersichtskarte =
209 sledrun = v.to_python(wikitext)
210 wikitext2 = v.from_python(sledrun)
211 assert wikitext == wikitext2
214 def test_gasthausbox_to_inn(self):
215 wikitext = '''{{Gasthausbox
216 | Position = 47.295549 N 9.986970 E
223 | Handyempfang = A1; T-Mobile/Telering
224 | Homepage = http://www.bergkristallhuette.com/
225 | E-Mail = bergkristallhuette@gmx.at
226 | Telefon = +43-664-1808482
227 | Bild = Bergkritsallhütte 2009-02-07.JPG
228 | Rodelbahnen = [[Bergkristallhütte]]
230 Die Bergkristallhütte ist Teil des Boden-Vorsäß.'''
231 start, end, inn = wrpylib.wrmwmarkup.gasthausbox_to_inn(wikitext)
232 wrpylib.wrmwmarkup.inn_to_gasthausbox(inn)
235 def test_GasthausboxDictConverter(self):
236 v = wrpylib.wrmwmarkup.GasthausboxDictConverter()
237 other = collections.OrderedDict([
238 ('Position', (47.295549, 9.986970)),
241 ('Sitzplätze', None),
242 ('Übernachtung', (None, None)),
243 ('Rauchfrei', (True, False)),
244 ('Rodelverleih', (None, None)),
245 ('Handyempfang', 'A1; T-Mobile/Telering'),
246 ('Homepage', 'http://www.bergkristallhuette.com/'),
247 ('E-Mail', 'bergkristallhuette@gmx.at'),
248 ('Telefon', '+43-664-1808482'),
249 ('Bild', 'Bergkritsallhütte 2009-02-07.JPG'),
250 ('Rodelbahnen', '[[Bergkristallhütte]]')])
251 inn = v.to_python(other)
252 assert inn.homepage == 'http://www.bergkristallhuette.com/'
253 other2 = v.from_python(inn)
254 assert other == other2
257 def test_GasthausboxValidator(self):
258 v = wrpylib.wrmwmarkup.GasthausboxValidator()
259 wikitext = textwrap.dedent('''\
261 | Position = 47.295549 N 9.986970 E
268 | Handyempfang = A1; T-Mobile/Telering
269 | Homepage = http://www.bergkristallhuette.com/
270 | E-Mail = bergkristallhuette@gmx.at
271 | Telefon = +43-664-1808482
272 | Bild = Bergkritsallhütte 2009-02-07.JPG
273 | Rodelbahnen = [[Bergkristallhütte]]
275 inn = v.to_python(wikitext)
276 wikitext2 = v.from_python(inn)
277 assert wikitext == wikitext2
280 def test_googlemap_to_wrmap(self):
282 <googlemap version="0.9" lat="47.113291" lon="11.272337" zoom="15" height="450">
283 (Parkplatz)47.114958,11.266026
286 (Gasthaus) 47.114715, 11.266262, Alt Bärnbad (Gasthaus)
295 attributes, coords, paths = wrpylib.mwmarkup.parse_googlemap(wikitext)
296 json = wrpylib.wrmwmarkup.googlemap_to_wrmap(attributes, coords, paths)
297 assert json['properties']['lon'] == 11.272337
298 assert json['properties']['lat'] == 47.113291
299 assert json['properties']['zoom'] == 15
300 assert json['properties']['height'] == 450
301 assert json['features'][0]['properties']['type'] == 'parkplatz'
302 assert json['features'][0]['properties']['name'] == 'Erster Parkplatz'
303 assert json['features'][0]['geometry']['coordinates'] == [11.266026, 47.114958]
304 assert json['features'][1]['properties']['type'] == 'gasthaus'
305 assert json['features'][1]['properties']['name'] == 'Alt Bärnbad (Gasthaus)'
306 assert json['features'][1]['geometry']['coordinates'] == [11.266262, 47.114715]
307 assert json['features'][2]['properties']['type'] == 'rodelbahn'
308 assert json['features'][2]['geometry']['coordinates'] == [
309 [11.266262, 47.114715],
310 [11.268381, 47.114135],
311 [11.269322, 47.113421],
312 [11.269979, 47.11277],
313 [11.271119, 47.112408]]
315 def test_parse_wrmap(self):
317 <wrmap lat="47.2417134" lon="11.21408895" zoom="14" width="700" height="400">
318 <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 11.190454</gasthaus>
319 <parkplatz>47.245789 11.238971</parkplatz>
320 <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 11.238283</haltestelle>
328 json = wrpylib.wrmwmarkup.parse_wrmap(wikitext)
329 assert json['properties']['lon'] == 11.21408895
330 assert json['properties']['lat'] == 47.2417134
331 assert json['properties']['zoom'] == 14
332 assert json['properties']['width'] == 700
333 assert json['properties']['height'] == 400
334 assert json['features'][0]['properties']['type'] == 'gasthaus'
335 assert json['features'][0]['properties']['name'] == 'Rosskogelhütte'
336 assert json['features'][0]['properties']['wiki'] == 'Rosskogelhütte'
337 assert json['features'][0]['geometry']['coordinates'] == [11.190454, 47.240689]
338 assert json['features'][1]['properties']['type'] == 'parkplatz'
339 assert json['features'][1]['geometry']['coordinates'] == [11.238971, 47.245789]
340 assert json['features'][2]['properties']['type'] == 'haltestelle'
341 assert json['features'][2]['properties']['name'] == 'Oberperfuss Rangger Köpfl Lift'
342 assert json['features'][2]['geometry']['coordinates'] == [11.238283, 47.245711]
343 assert json['features'][3]['properties']['type'] == 'rodelbahn'
344 assert json['features'][3]['geometry']['coordinates'] == [
345 [11.203360, 47.238587],
346 [11.230868, 47.244951],
347 [11.237853, 47.245470]]
349 def test_create_wrmap(self):
351 'type': 'FeatureCollection',
357 'coordinates': [11.190454, 47.240689]},
358 'properties': {'type': 'gasthaus', 'name': 'Rosskogelhütte', 'wiki': 'Rosskogelhütte'}
363 'coordinates': [11.238971, 47.245789]},
364 'properties': {'type': 'parkplatz'}
369 'coordinates': [11.238283, 47.245711]},
370 'properties': {'type': 'haltestelle', 'name': 'Oberperfuss Rangger Köpfl Lift'}
374 'type': 'LineString',
376 [11.203360, 47.238587],
377 [11.230868, 47.244951],
378 [11.237853, 47.245470]]},
379 'properties': {'type': 'rodelbahn'}
389 wikitext = wrpylib.wrmwmarkup.create_wrmap(geojson)
390 assert wikitext == textwrap.dedent('''\
391 <wrmap height="400" lat="47.241713" lon="11.214089" width="700" zoom="14">
393 <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 N 11.190454 E</gasthaus>
394 <parkplatz>47.245789 N 11.238971 E</parkplatz>
395 <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 N 11.238283 E</haltestelle>
398 47.238587 N 11.203360 E
399 47.244951 N 11.230868 E
400 47.245470 N 11.237853 E