2 # -*- coding: iso-8859-15 -*-
4 import wrpylib.wrmwmarkup
5 import wrpylib.mwmarkup
10 def test_rodelbahnbox_to_sledrun():
11 wikitext = u'''== Allgemeines ==
13 | Position = 47.309820 N 9.986508 E
20 | Lawinen = gelegentlich
22 | Öffentliche Anreise = Ja
24 | Aufstieg getrennt = Nein
25 | Aufstiegshilfe = Nein
26 | Beleuchtungsanlage = Nein
31 | Telefonauskunft = +43-664-1808482 (Bergkristallhütte)
32 | Bild = Rodelbahn Bergkristallhütte 2009-03-03.jpg
33 | In Übersichtskarte = Ja
36 Die Rodelbahn zur Bergkristallhütte ist durchaus abwechslungsreich.'''
37 start, end, sledrun = wrpylib.wrmwmarkup.rodelbahnbox_to_sledrun(wikitext)
38 wrpylib.wrmwmarkup.sledrun_to_rodelbahnbox(sledrun, '1.3')
41 def test_RodelbahnboxDictConverter():
42 v = wrpylib.wrmwmarkup.RodelbahnboxDictConverter()
43 other = collections.OrderedDict([
44 (u'Position', (47.30982, 9.986508)),
45 (u'Position oben', (None, None)),
47 (u'Position unten', (None, None)),
50 (u'Schwierigkeit', None),
53 (u'Öffentliche Anreise', 6),
54 (u'Aufstieg möglich', True),
55 (u'Aufstieg getrennt', (0.0, None)),
57 (u'Aufstiegshilfe', (False, None)),
58 (u'Beleuchtungsanlage', (0.0, None)),
59 (u'Beleuchtungstage', (None, None)),
60 (u'Rodelverleih', (True, u'Ja')),
61 (u'Gütesiegel', None),
62 (u'Webauskunft', None),
63 (u'Telefonauskunft', u'+43-664-1808482 (Bergkristallhütte)'),
64 (u'Bild', u'Rodelbahn Bergkristallhütte 2009-03-03.jpg'),
65 (u'In Übersichtskarte', True),
67 sledrun = v.to_python(other)
68 assert sledrun.forum_id == 72
69 other2 = v.from_python(sledrun)
70 assert other == other2
73 def test_RodelbahnboxValidator():
74 v = wrpylib.wrmwmarkup.RodelbahnboxValidator()
75 wikitext = u'''{{Rodelbahnbox
76 | Position = 47.309820 N 9.986508 E
83 | Lawinen = gelegentlich
85 | Öffentliche Anreise = Ja
86 | Aufstieg möglich = Nein
87 | Aufstieg getrennt = Nein
89 | Aufstiegshilfe = Nein
90 | Beleuchtungsanlage = Nein
95 | Telefonauskunft = +43-664-1808482 (Bergkristallhütte)
96 | Bild = Rodelbahn Bergkristallhütte 2009-03-03.jpg
97 | In Übersichtskarte = Ja
100 sledrun = v.to_python(wikitext)
101 wikitext2 = v.from_python(sledrun)
102 assert wikitext == wikitext2
103 wikitext = u'''{{Rodelbahnbox
113 | Öffentliche Anreise =
115 | Aufstieg getrennt =
118 | Beleuchtungsanlage =
125 | In Übersichtskarte =
128 sledrun = v.to_python(wikitext)
129 wikitext2 = v.from_python(sledrun)
130 assert wikitext == wikitext2
133 def test_gasthausbox_to_inn():
134 wikitext = u'''{{Gasthausbox
135 | Position = 47.295549 N 9.986970 E
142 | Handyempfang = A1; T-Mobile/Telering
143 | Homepage = http://www.bergkristallhuette.com/
144 | E-Mail = bergkristallhuette@gmx.at
145 | Telefon = +43-664-1808482
146 | Bild = Bergkritsallhütte 2009-02-07.JPG
147 | Rodelbahnen = [[Bergkristallhütte]]
149 Die Bergkristallhütte ist Teil des Boden-Vorsäß.'''
150 start, end, inn = wrpylib.wrmwmarkup.gasthausbox_to_inn(wikitext)
151 wrpylib.wrmwmarkup.inn_to_gasthausbox(inn)
154 def test_googlemap_to_wrmap():
156 <googlemap version="0.9" lat="47.113291" lon="11.272337" zoom="15" height="450">
157 (Parkplatz)47.114958,11.266026
160 (Gasthaus) 47.114715, 11.266262, Alt Bärnbad (Gasthaus)
169 attributes, coords, paths = wrpylib.mwmarkup.parse_googlemap(wikitext)
170 json = wrpylib.wrmwmarkup.googlemap_to_wrmap(attributes, coords, paths)
171 assert json['properties']['lon'] == 11.272337
172 assert json['properties']['lat'] == 47.113291
173 assert json['properties']['zoom'] == 15
174 assert json['properties']['height'] == 450
175 assert json['features'][0]['properties']['type'] == 'parkplatz'
176 assert json['features'][0]['properties']['name'] == 'Erster Parkplatz'
177 assert json['features'][0]['geometry']['coordinates'] == [11.266026, 47.114958]
178 assert json['features'][1]['properties']['type'] == 'gasthaus'
179 assert json['features'][1]['properties']['name'] == u'Alt Bärnbad (Gasthaus)'
180 assert json['features'][1]['geometry']['coordinates'] == [11.266262, 47.114715]
181 assert json['features'][2]['properties']['type'] == 'rodelbahn'
182 assert json['features'][2]['geometry']['coordinates'] == [
183 [11.266262, 47.114715],
184 [11.268381, 47.114135],
185 [11.269322, 47.113421],
186 [11.269979, 47.11277],
187 [11.271119, 47.112408]]
190 def test_parse_wrmap():
192 <wrmap lat="47.2417134" lon="11.21408895" zoom="14" width="700" height="400">
193 <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 11.190454</gasthaus>
194 <parkplatz>47.245789 11.238971</parkplatz>
195 <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 11.238283</haltestelle>
203 json = wrpylib.wrmwmarkup.parse_wrmap(wikitext)
204 assert json['properties']['lon'] == 11.21408895
205 assert json['properties']['lat'] == 47.2417134
206 assert json['properties']['zoom'] == 14
207 assert json['properties']['width'] == 700
208 assert json['properties']['height'] == 400
209 assert json['features'][0]['properties']['type'] == 'gasthaus'
210 assert json['features'][0]['properties']['name'] == u'Rosskogelhütte'
211 assert json['features'][0]['properties']['wiki'] == u'Rosskogelhütte'
212 assert json['features'][0]['geometry']['coordinates'] == [11.190454, 47.240689]
213 assert json['features'][1]['properties']['type'] == 'parkplatz'
214 assert json['features'][1]['geometry']['coordinates'] == [11.238971, 47.245789]
215 assert json['features'][2]['properties']['type'] == 'haltestelle'
216 assert json['features'][2]['properties']['name'] == u'Oberperfuss Rangger Köpfl Lift'
217 assert json['features'][2]['geometry']['coordinates'] == [11.238283, 47.245711]
218 assert json['features'][3]['properties']['type'] == 'rodelbahn'
219 assert json['features'][3]['geometry']['coordinates'] == [
220 [11.203360, 47.238587],
221 [11.230868, 47.244951],
222 [11.237853, 47.245470]]
225 def test_create_wrmap():
227 'type': 'FeatureCollection',
233 'coordinates': [11.190454, 47.240689]},
234 'properties': {'type': 'gasthaus', 'name': u'Rosskogelhütte', 'wiki': u'Rosskogelhütte'}
239 'coordinates': [11.238971, 47.245789]},
240 'properties': {'type': 'parkplatz'}
245 'coordinates': [11.238283, 47.245711]},
246 'properties': {'type': 'haltestelle', 'name': u'Oberperfuss Rangger Köpfl Lift'}
250 'type': 'LineString',
252 [11.203360, 47.238587],
253 [11.230868, 47.244951],
254 [11.237853, 47.245470]]},
255 'properties': {'type': 'rodelbahn'}
265 wikitext = wrpylib.wrmwmarkup.create_wrmap(geojson)
266 assert wikitext == textwrap.dedent(u'''\
267 <wrmap height="400" lat="47.241713" lon="11.214089" width="700" zoom="14">
269 <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 N 11.190454 E</gasthaus>
270 <parkplatz>47.245789 N 11.238971 E</parkplatz>
271 <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 N 11.238283 E</haltestelle>
274 47.238587 N 11.203360 E
275 47.244951 N 11.230868 E
276 47.245470 N 11.237853 E