2 # -*- coding: iso-8859-15 -*-
6 import wrpylib.mwmarkup
7 import wrpylib.wrmwmarkup
10 class TestWrMwMarkup(unittest.TestCase):
11 def test_rodelbahnbox_to_sledrun(self):
12 wikitext = '''== Allgemeines ==
14 | Position = 47.309820 N 9.986508 E
21 | Lawinen = gelegentlich
23 | Öffentliche Anreise = Ja
25 | Aufstieg möglich = Nein
26 | Aufstieg getrennt = Nein
27 | Aufstiegshilfe = Nein
28 | Beleuchtungsanlage = Nein
33 | Telefonauskunft = +43-664-1808482 (Bergkristallhütte)
34 | Bild = Rodelbahn Bergkristallhütte 2009-03-03.jpg
35 | In Übersichtskarte = Ja
38 Die Rodelbahn zur Bergkristallhütte ist durchaus abwechslungsreich.'''
39 start, end, sledrun = wrpylib.wrmwmarkup.rodelbahnbox_to_sledrun(wikitext)
40 wrpylib.wrmwmarkup.sledrun_to_rodelbahnbox(sledrun)
43 def test_RodelbahnboxDictConverter(self):
44 v = wrpylib.wrmwmarkup.RodelbahnboxDictConverter()
45 other = collections.OrderedDict([
46 ('Position', (47.30982, 9.986508)),
47 ('Position oben', (None, None)),
49 ('Position unten', (None, None)),
52 ('Schwierigkeit', None),
55 ('Öffentliche Anreise', 6),
56 ('Aufstieg möglich', True),
57 ('Aufstieg getrennt', (0.0, None)),
59 ('Aufstiegshilfe', (False, None)),
60 ('Beleuchtungsanlage', (0.0, None)),
61 ('Beleuchtungstage', (None, None)),
62 ('Rodelverleih', (True, 'Ja')),
64 ('Webauskunft', None),
65 ('Telefonauskunft', '+43-664-1808482 (Bergkristallhütte)'),
66 ('Bild', 'Rodelbahn Bergkristallhütte 2009-03-03.jpg'),
67 ('In Übersichtskarte', True),
69 sledrun = v.to_python(other)
70 assert sledrun.forum_id == 72
71 other2 = v.from_python(sledrun)
72 assert other == other2
75 def test_RodelbahnboxValidator(self):
76 v = wrpylib.wrmwmarkup.RodelbahnboxValidator()
77 wikitext = textwrap.dedent('''\
79 | Position = 47.309820 N 9.986508 E
86 | Lawinen = gelegentlich
88 | Öffentliche Anreise = Ja
89 | Aufstieg möglich = Nein
90 | Aufstieg getrennt = Nein
92 | Aufstiegshilfe = Nein
93 | Beleuchtungsanlage = Nein
98 | Telefonauskunft = +43-664-1808482 (Bergkristallhütte)
99 | Bild = Rodelbahn Bergkristallhütte 2009-03-03.jpg
100 | In Übersichtskarte = Ja
103 sledrun = v.to_python(wikitext)
104 wikitext2 = v.from_python(sledrun)
105 assert wikitext == wikitext2
106 wikitext = textwrap.dedent('''\
117 | Öffentliche Anreise =
119 | Aufstieg getrennt =
122 | Beleuchtungsanlage =
129 | In Übersichtskarte =
132 sledrun = v.to_python(wikitext)
133 wikitext2 = v.from_python(sledrun)
134 assert wikitext == wikitext2
137 def test_gasthausbox_to_inn(self):
138 wikitext = '''{{Gasthausbox
139 | Position = 47.295549 N 9.986970 E
146 | Handyempfang = A1; T-Mobile/Telering
147 | Homepage = http://www.bergkristallhuette.com/
148 | E-Mail = bergkristallhuette@gmx.at
149 | Telefon = +43-664-1808482
150 | Bild = Bergkritsallhütte 2009-02-07.JPG
151 | Rodelbahnen = [[Bergkristallhütte]]
153 Die Bergkristallhütte ist Teil des Boden-Vorsäß.'''
154 start, end, inn = wrpylib.wrmwmarkup.gasthausbox_to_inn(wikitext)
155 wrpylib.wrmwmarkup.inn_to_gasthausbox(inn)
158 def test_GasthausboxDictConverter(self):
159 v = wrpylib.wrmwmarkup.GasthausboxDictConverter()
160 other = collections.OrderedDict([
161 ('Position', (47.295549, 9.986970)),
164 ('Sitzplätze', None),
165 ('Übernachtung', (None, None)),
166 ('Rauchfrei', (True, False)),
167 ('Rodelverleih', (None, None)),
168 ('Handyempfang', 'A1; T-Mobile/Telering'),
169 ('Homepage', 'http://www.bergkristallhuette.com/'),
170 ('E-Mail', 'bergkristallhuette@gmx.at'),
171 ('Telefon', '+43-664-1808482'),
172 ('Bild', 'Bergkritsallhütte 2009-02-07.JPG'),
173 ('Rodelbahnen', '[[Bergkristallhütte]]')])
174 inn = v.to_python(other)
175 assert inn.homepage == 'http://www.bergkristallhuette.com/'
176 other2 = v.from_python(inn)
177 assert other == other2
180 def test_GasthausboxValidator(self):
181 v = wrpylib.wrmwmarkup.GasthausboxValidator()
182 wikitext = textwrap.dedent('''\
184 | Position = 47.295549 N 9.986970 E
191 | Handyempfang = A1; T-Mobile/Telering
192 | Homepage = http://www.bergkristallhuette.com/
193 | E-Mail = bergkristallhuette@gmx.at
194 | Telefon = +43-664-1808482
195 | Bild = Bergkritsallhütte 2009-02-07.JPG
196 | Rodelbahnen = [[Bergkristallhütte]]
198 inn = v.to_python(wikitext)
199 wikitext2 = v.from_python(inn)
200 assert wikitext == wikitext2
203 def test_googlemap_to_wrmap(self):
205 <googlemap version="0.9" lat="47.113291" lon="11.272337" zoom="15" height="450">
206 (Parkplatz)47.114958,11.266026
209 (Gasthaus) 47.114715, 11.266262, Alt Bärnbad (Gasthaus)
218 attributes, coords, paths = wrpylib.mwmarkup.parse_googlemap(wikitext)
219 json = wrpylib.wrmwmarkup.googlemap_to_wrmap(attributes, coords, paths)
220 assert json['properties']['lon'] == 11.272337
221 assert json['properties']['lat'] == 47.113291
222 assert json['properties']['zoom'] == 15
223 assert json['properties']['height'] == 450
224 assert json['features'][0]['properties']['type'] == 'parkplatz'
225 assert json['features'][0]['properties']['name'] == 'Erster Parkplatz'
226 assert json['features'][0]['geometry']['coordinates'] == [11.266026, 47.114958]
227 assert json['features'][1]['properties']['type'] == 'gasthaus'
228 assert json['features'][1]['properties']['name'] == 'Alt Bärnbad (Gasthaus)'
229 assert json['features'][1]['geometry']['coordinates'] == [11.266262, 47.114715]
230 assert json['features'][2]['properties']['type'] == 'rodelbahn'
231 assert json['features'][2]['geometry']['coordinates'] == [
232 [11.266262, 47.114715],
233 [11.268381, 47.114135],
234 [11.269322, 47.113421],
235 [11.269979, 47.11277],
236 [11.271119, 47.112408]]
238 def test_parse_wrmap(self):
240 <wrmap lat="47.2417134" lon="11.21408895" zoom="14" width="700" height="400">
241 <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 11.190454</gasthaus>
242 <parkplatz>47.245789 11.238971</parkplatz>
243 <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 11.238283</haltestelle>
251 json = wrpylib.wrmwmarkup.parse_wrmap(wikitext)
252 assert json['properties']['lon'] == 11.21408895
253 assert json['properties']['lat'] == 47.2417134
254 assert json['properties']['zoom'] == 14
255 assert json['properties']['width'] == 700
256 assert json['properties']['height'] == 400
257 assert json['features'][0]['properties']['type'] == 'gasthaus'
258 assert json['features'][0]['properties']['name'] == 'Rosskogelhütte'
259 assert json['features'][0]['properties']['wiki'] == 'Rosskogelhütte'
260 assert json['features'][0]['geometry']['coordinates'] == [11.190454, 47.240689]
261 assert json['features'][1]['properties']['type'] == 'parkplatz'
262 assert json['features'][1]['geometry']['coordinates'] == [11.238971, 47.245789]
263 assert json['features'][2]['properties']['type'] == 'haltestelle'
264 assert json['features'][2]['properties']['name'] == 'Oberperfuss Rangger Köpfl Lift'
265 assert json['features'][2]['geometry']['coordinates'] == [11.238283, 47.245711]
266 assert json['features'][3]['properties']['type'] == 'rodelbahn'
267 assert json['features'][3]['geometry']['coordinates'] == [
268 [11.203360, 47.238587],
269 [11.230868, 47.244951],
270 [11.237853, 47.245470]]
272 def test_create_wrmap(self):
274 'type': 'FeatureCollection',
280 'coordinates': [11.190454, 47.240689]},
281 'properties': {'type': 'gasthaus', 'name': 'Rosskogelhütte', 'wiki': 'Rosskogelhütte'}
286 'coordinates': [11.238971, 47.245789]},
287 'properties': {'type': 'parkplatz'}
292 'coordinates': [11.238283, 47.245711]},
293 'properties': {'type': 'haltestelle', 'name': 'Oberperfuss Rangger Köpfl Lift'}
297 'type': 'LineString',
299 [11.203360, 47.238587],
300 [11.230868, 47.244951],
301 [11.237853, 47.245470]]},
302 'properties': {'type': 'rodelbahn'}
312 wikitext = wrpylib.wrmwmarkup.create_wrmap(geojson)
313 assert wikitext == textwrap.dedent('''\
314 <wrmap height="400" lat="47.241713" lon="11.214089" width="700" zoom="14">
316 <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 N 11.190454 E</gasthaus>
317 <parkplatz>47.245789 N 11.238971 E</parkplatz>
318 <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 N 11.238283 E</haltestelle>
321 47.238587 N 11.203360 E
322 47.244951 N 11.230868 E
323 47.245470 N 11.237853 E