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 möglich = Nein
25 | Aufstieg getrennt = Nein
26 | Aufstiegshilfe = Nein
27 | Beleuchtungsanlage = Nein
32 | Telefonauskunft = +43-664-1808482 (Bergkristallhütte)
33 | Bild = Rodelbahn Bergkristallhütte 2009-03-03.jpg
34 | In Übersichtskarte = Ja
37 Die Rodelbahn zur Bergkristallhütte ist durchaus abwechslungsreich.'''
38 start, end, sledrun = wrpylib.wrmwmarkup.rodelbahnbox_to_sledrun(wikitext)
39 wrpylib.wrmwmarkup.sledrun_to_rodelbahnbox(sledrun)
42 def test_RodelbahnboxDictConverter():
43 v = wrpylib.wrmwmarkup.RodelbahnboxDictConverter()
44 other = collections.OrderedDict([
45 (u'Position', (47.30982, 9.986508)),
46 (u'Position oben', (None, None)),
48 (u'Position unten', (None, None)),
51 (u'Schwierigkeit', None),
54 (u'Öffentliche Anreise', 6),
55 (u'Aufstieg möglich', True),
56 (u'Aufstieg getrennt', (0.0, None)),
58 (u'Aufstiegshilfe', (False, None)),
59 (u'Beleuchtungsanlage', (0.0, None)),
60 (u'Beleuchtungstage', (None, None)),
61 (u'Rodelverleih', (True, u'Ja')),
62 (u'Gütesiegel', None),
63 (u'Webauskunft', None),
64 (u'Telefonauskunft', u'+43-664-1808482 (Bergkristallhütte)'),
65 (u'Bild', u'Rodelbahn Bergkristallhütte 2009-03-03.jpg'),
66 (u'In Übersichtskarte', True),
68 sledrun = v.to_python(other)
69 assert sledrun.forum_id == 72
70 other2 = v.from_python(sledrun)
71 assert other == other2
74 def test_RodelbahnboxValidator():
75 v = wrpylib.wrmwmarkup.RodelbahnboxValidator()
76 wikitext = textwrap.dedent(u'''\
78 | Position = 47.309820 N 9.986508 E
85 | Lawinen = gelegentlich
87 | Öffentliche Anreise = Ja
88 | Aufstieg möglich = Nein
89 | Aufstieg getrennt = Nein
91 | Aufstiegshilfe = Nein
92 | Beleuchtungsanlage = Nein
97 | Telefonauskunft = +43-664-1808482 (Bergkristallhütte)
98 | Bild = Rodelbahn Bergkristallhütte 2009-03-03.jpg
99 | In Übersichtskarte = Ja
102 sledrun = v.to_python(wikitext)
103 wikitext2 = v.from_python(sledrun)
104 assert wikitext == wikitext2
105 wikitext = textwrap.dedent(u'''\
116 | Öffentliche Anreise =
118 | Aufstieg getrennt =
121 | Beleuchtungsanlage =
128 | In Übersichtskarte =
131 sledrun = v.to_python(wikitext)
132 wikitext2 = v.from_python(sledrun)
133 assert wikitext == wikitext2
136 def test_gasthausbox_to_inn():
137 wikitext = u'''{{Gasthausbox
138 | Position = 47.295549 N 9.986970 E
145 | Handyempfang = A1; T-Mobile/Telering
146 | Homepage = http://www.bergkristallhuette.com/
147 | E-Mail = bergkristallhuette@gmx.at
148 | Telefon = +43-664-1808482
149 | Bild = Bergkritsallhütte 2009-02-07.JPG
150 | Rodelbahnen = [[Bergkristallhütte]]
152 Die Bergkristallhütte ist Teil des Boden-Vorsäß.'''
153 start, end, inn = wrpylib.wrmwmarkup.gasthausbox_to_inn(wikitext)
154 wrpylib.wrmwmarkup.inn_to_gasthausbox(inn)
157 def test_googlemap_to_wrmap():
159 <googlemap version="0.9" lat="47.113291" lon="11.272337" zoom="15" height="450">
160 (Parkplatz)47.114958,11.266026
163 (Gasthaus) 47.114715, 11.266262, Alt Bärnbad (Gasthaus)
172 attributes, coords, paths = wrpylib.mwmarkup.parse_googlemap(wikitext)
173 json = wrpylib.wrmwmarkup.googlemap_to_wrmap(attributes, coords, paths)
174 assert json['properties']['lon'] == 11.272337
175 assert json['properties']['lat'] == 47.113291
176 assert json['properties']['zoom'] == 15
177 assert json['properties']['height'] == 450
178 assert json['features'][0]['properties']['type'] == 'parkplatz'
179 assert json['features'][0]['properties']['name'] == 'Erster Parkplatz'
180 assert json['features'][0]['geometry']['coordinates'] == [11.266026, 47.114958]
181 assert json['features'][1]['properties']['type'] == 'gasthaus'
182 assert json['features'][1]['properties']['name'] == u'Alt Bärnbad (Gasthaus)'
183 assert json['features'][1]['geometry']['coordinates'] == [11.266262, 47.114715]
184 assert json['features'][2]['properties']['type'] == 'rodelbahn'
185 assert json['features'][2]['geometry']['coordinates'] == [
186 [11.266262, 47.114715],
187 [11.268381, 47.114135],
188 [11.269322, 47.113421],
189 [11.269979, 47.11277],
190 [11.271119, 47.112408]]
193 def test_parse_wrmap():
195 <wrmap lat="47.2417134" lon="11.21408895" zoom="14" width="700" height="400">
196 <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 11.190454</gasthaus>
197 <parkplatz>47.245789 11.238971</parkplatz>
198 <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 11.238283</haltestelle>
206 json = wrpylib.wrmwmarkup.parse_wrmap(wikitext)
207 assert json['properties']['lon'] == 11.21408895
208 assert json['properties']['lat'] == 47.2417134
209 assert json['properties']['zoom'] == 14
210 assert json['properties']['width'] == 700
211 assert json['properties']['height'] == 400
212 assert json['features'][0]['properties']['type'] == 'gasthaus'
213 assert json['features'][0]['properties']['name'] == u'Rosskogelhütte'
214 assert json['features'][0]['properties']['wiki'] == u'Rosskogelhütte'
215 assert json['features'][0]['geometry']['coordinates'] == [11.190454, 47.240689]
216 assert json['features'][1]['properties']['type'] == 'parkplatz'
217 assert json['features'][1]['geometry']['coordinates'] == [11.238971, 47.245789]
218 assert json['features'][2]['properties']['type'] == 'haltestelle'
219 assert json['features'][2]['properties']['name'] == u'Oberperfuss Rangger Köpfl Lift'
220 assert json['features'][2]['geometry']['coordinates'] == [11.238283, 47.245711]
221 assert json['features'][3]['properties']['type'] == 'rodelbahn'
222 assert json['features'][3]['geometry']['coordinates'] == [
223 [11.203360, 47.238587],
224 [11.230868, 47.244951],
225 [11.237853, 47.245470]]
228 def test_create_wrmap():
230 'type': 'FeatureCollection',
236 'coordinates': [11.190454, 47.240689]},
237 'properties': {'type': 'gasthaus', 'name': u'Rosskogelhütte', 'wiki': u'Rosskogelhütte'}
242 'coordinates': [11.238971, 47.245789]},
243 'properties': {'type': 'parkplatz'}
248 'coordinates': [11.238283, 47.245711]},
249 'properties': {'type': 'haltestelle', 'name': u'Oberperfuss Rangger Köpfl Lift'}
253 'type': 'LineString',
255 [11.203360, 47.238587],
256 [11.230868, 47.244951],
257 [11.237853, 47.245470]]},
258 'properties': {'type': 'rodelbahn'}
268 wikitext = wrpylib.wrmwmarkup.create_wrmap(geojson)
269 assert wikitext == textwrap.dedent(u'''\
270 <wrmap height="400" lat="47.241713" lon="11.214089" width="700" zoom="14">
272 <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 N 11.190454 E</gasthaus>
273 <parkplatz>47.245789 N 11.238971 E</parkplatz>
274 <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 N 11.238283 E</haltestelle>
277 47.238587 N 11.203360 E
278 47.244951 N 11.230868 E
279 47.245470 N 11.237853 E