-#!/usr/bin/python2.6
+#!/usr/bin/python2.7
# -*- coding: iso-8859-15 -*-
+import collections
import wrpylib.wrmwmarkup
-import formencode
-
-
-def test_rodelbahnbox_to_sledrun():
- wikitext = u'''== Allgemeines ==
- {{Rodelbahnbox
- | Position = 47.309820 N 9.986508 E
- | Position oben =
- | Höhe oben = 1244
- | Position unten =
- | Höhe unten = 806
- | Länge = 5045
- | Schwierigkeit =
- | Lawinen = gelegentlich
- | Betreiber =
- | Öffentliche Anreise = Ja
- | Gehzeit = 105
- | Aufstieg getrennt = Nein
- | Aufstiegshilfe = Nein
- | Beleuchtungsanlage = Nein
- | Beleuchtungstage =
- | Rodelverleih = Ja
- | Gütesiegel =
- | Webauskunft =
- | Telefonauskunft = +43-664-1808482 (Bergkristallhütte)
- | Bild = Rodelbahn Bergkristallhütte 2009-03-03.jpg
- | In Übersichtskarte = Ja
- | Forumid = 72
- }}
- Die Rodelbahn zur Bergkristallhütte ist durchaus abwechslungsreich.'''
- class Sledrun(object): pass
- sledrun = Sledrun()
- wrpylib.wrmwmarkup.rodelbahnbox_to_sledrun(wikitext, sledrun)
- wrpylib.wrmwmarkup.sledrun_to_rodelbahnbox(sledrun)
-
-
-
-def test_gasthausbox_to_inn():
- wikitext = u'''{{Gasthausbox
- | Position = 47.295549 N 9.986970 E
- | Höhe = 1250
- | Betreiber =
- | Sitzplätze =
- | Übernachtung =
- | Rauchfrei = Nein
- | Rodelverleih =
- | Handyempfang = A1; T-Mobile/Telering
- | Homepage = http://www.bergkristallhuette.com/
- | E-Mail = bergkristallhuette@gmx.at
- | Telefon = +43-664-1808482
- | Bild = Bergkritsallhütte 2009-02-07.JPG
- | Rodelbahnen = [[Bergkristallhütte]]
- }}
- Die Bergkristallhütte ist Teil des Boden-Vorsäß.'''
- class Inn(object): pass
- inn = Inn()
- wrpylib.wrmwmarkup.gasthausbox_to_inn(wikitext, inn)
- wrpylib.wrmwmarkup.inn_to_gasthausbox(inn)
+import wrpylib.mwmarkup
+import textwrap
+import unittest
+
+
+class TestWrMwMarkup(unittest.TestCase):
+ def test_rodelbahnbox_to_sledrun(self):
+ wikitext = u'''== Allgemeines ==
+ {{Rodelbahnbox
+ | Position = 47.309820 N 9.986508 E
+ | Position oben =
+ | Höhe oben = 1244
+ | Position unten =
+ | Höhe unten = 806
+ | Länge = 5045
+ | Schwierigkeit =
+ | Lawinen = gelegentlich
+ | Betreiber =
+ | Öffentliche Anreise = Ja
+ | Gehzeit = 105
+ | Aufstieg möglich = Nein
+ | Aufstieg getrennt = Nein
+ | Aufstiegshilfe = Nein
+ | Beleuchtungsanlage = Nein
+ | Beleuchtungstage =
+ | Rodelverleih = Ja
+ | Gütesiegel =
+ | Webauskunft =
+ | Telefonauskunft = +43-664-1808482 (Bergkristallhütte)
+ | Bild = Rodelbahn Bergkristallhütte 2009-03-03.jpg
+ | In Übersichtskarte = Ja
+ | Forumid = 72
+ }}
+ Die Rodelbahn zur Bergkristallhütte ist durchaus abwechslungsreich.'''
+ start, end, sledrun = wrpylib.wrmwmarkup.rodelbahnbox_to_sledrun(wikitext)
+ wrpylib.wrmwmarkup.sledrun_to_rodelbahnbox(sledrun)
+
+
+ def test_RodelbahnboxDictConverter(self):
+ v = wrpylib.wrmwmarkup.RodelbahnboxDictConverter()
+ other = collections.OrderedDict([
+ (u'Position', (47.30982, 9.986508)),
+ (u'Position oben', (None, None)),
+ (u'Höhe oben', 1244),
+ (u'Position unten', (None, None)),
+ (u'Höhe unten', 806),
+ (u'Länge', 5045),
+ (u'Schwierigkeit', None),
+ (u'Lawinen', 3),
+ (u'Betreiber', None),
+ (u'Öffentliche Anreise', 6),
+ (u'Aufstieg möglich', True),
+ (u'Aufstieg getrennt', (0.0, None)),
+ (u'Gehzeit', 105),
+ (u'Aufstiegshilfe', (False, None)),
+ (u'Beleuchtungsanlage', (0.0, None)),
+ (u'Beleuchtungstage', (None, None)),
+ (u'Rodelverleih', (True, u'Ja')),
+ (u'Gütesiegel', None),
+ (u'Webauskunft', None),
+ (u'Telefonauskunft', u'+43-664-1808482 (Bergkristallhütte)'),
+ (u'Bild', u'Rodelbahn Bergkristallhütte 2009-03-03.jpg'),
+ (u'In Übersichtskarte', True),
+ (u'Forumid', 72)])
+ sledrun = v.to_python(other)
+ assert sledrun.forum_id == 72
+ other2 = v.from_python(sledrun)
+ assert other == other2
+
+
+ def test_RodelbahnboxValidator(self):
+ v = wrpylib.wrmwmarkup.RodelbahnboxValidator()
+ wikitext = textwrap.dedent(u'''\
+ {{Rodelbahnbox
+ | Position = 47.309820 N 9.986508 E
+ | Position oben =
+ | Höhe oben = 1244
+ | Position unten =
+ | Höhe unten = 806
+ | Länge = 5045
+ | Schwierigkeit =
+ | Lawinen = gelegentlich
+ | Betreiber =
+ | Öffentliche Anreise = Ja
+ | Aufstieg möglich = Nein
+ | Aufstieg getrennt = Nein
+ | Gehzeit = 105
+ | Aufstiegshilfe = Nein
+ | Beleuchtungsanlage = Nein
+ | Beleuchtungstage =
+ | Rodelverleih = Ja
+ | Gütesiegel =
+ | Webauskunft =
+ | Telefonauskunft = +43-664-1808482 (Bergkristallhütte)
+ | Bild = Rodelbahn Bergkristallhütte 2009-03-03.jpg
+ | In Übersichtskarte = Ja
+ | Forumid = 72
+ }}''')
+ sledrun = v.to_python(wikitext)
+ wikitext2 = v.from_python(sledrun)
+ assert wikitext == wikitext2
+ wikitext = textwrap.dedent(u'''\
+ {{Rodelbahnbox
+ | Position =
+ | Position oben =
+ | Höhe oben =
+ | Position unten =
+ | Höhe unten =
+ | Länge =
+ | Schwierigkeit =
+ | Lawinen =
+ | Betreiber =
+ | Öffentliche Anreise =
+ | Aufstieg möglich =
+ | Aufstieg getrennt =
+ | Gehzeit =
+ | Aufstiegshilfe =
+ | Beleuchtungsanlage =
+ | Beleuchtungstage =
+ | Rodelverleih =
+ | Gütesiegel =
+ | Webauskunft =
+ | Telefonauskunft =
+ | Bild =
+ | In Übersichtskarte =
+ | Forumid =
+ }}''')
+ sledrun = v.to_python(wikitext)
+ wikitext2 = v.from_python(sledrun)
+ assert wikitext == wikitext2
+
+
+ def test_gasthausbox_to_inn(self):
+ wikitext = u'''{{Gasthausbox
+ | Position = 47.295549 N 9.986970 E
+ | Höhe = 1250
+ | Betreiber =
+ | Sitzplätze =
+ | Übernachtung =
+ | Rauchfrei = Nein
+ | Rodelverleih =
+ | Handyempfang = A1; T-Mobile/Telering
+ | Homepage = http://www.bergkristallhuette.com/
+ | E-Mail = bergkristallhuette@gmx.at
+ | Telefon = +43-664-1808482
+ | Bild = Bergkritsallhütte 2009-02-07.JPG
+ | Rodelbahnen = [[Bergkristallhütte]]
+ }}
+ Die Bergkristallhütte ist Teil des Boden-Vorsäß.'''
+ start, end, inn = wrpylib.wrmwmarkup.gasthausbox_to_inn(wikitext)
+ wrpylib.wrmwmarkup.inn_to_gasthausbox(inn)
+
+
+ def test_GasthausboxDictConverter(self):
+ v = wrpylib.wrmwmarkup.GasthausboxDictConverter()
+ other = collections.OrderedDict([
+ (u'Position', (47.295549, 9.986970)),
+ (u'Höhe', 1250),
+ (u'Betreiber', None),
+ (u'Sitzplätze', None),
+ (u'Übernachtung', (None, None)),
+ (u'Rauchfrei', (True, False)),
+ (u'Rodelverleih', (None, None)),
+ (u'Handyempfang', u'A1; T-Mobile/Telering'),
+ (u'Homepage', u'http://www.bergkristallhuette.com/'),
+ (u'E-Mail', u'bergkristallhuette@gmx.at'),
+ (u'Telefon', u'+43-664-1808482'),
+ (u'Bild', u'Bergkritsallhütte 2009-02-07.JPG'),
+ (u'Rodelbahnen', u'[[Bergkristallhütte]]')])
+ inn = v.to_python(other)
+ assert inn.homepage == u'http://www.bergkristallhuette.com/'
+ other2 = v.from_python(inn)
+ assert other == other2
+
+
+ def test_GasthausboxValidator(self):
+ v = wrpylib.wrmwmarkup.GasthausboxValidator()
+ wikitext = textwrap.dedent(u'''\
+ {{Gasthausbox
+ | Position = 47.295549 N 9.986970 E
+ | Höhe = 1250
+ | Betreiber =
+ | Sitzplätze =
+ | Übernachtung =
+ | Rauchfrei = Nein
+ | Rodelverleih =
+ | Handyempfang = A1; T-Mobile/Telering
+ | Homepage = http://www.bergkristallhuette.com/
+ | E-Mail = bergkristallhuette@gmx.at
+ | Telefon = +43-664-1808482
+ | Bild = Bergkritsallhütte 2009-02-07.JPG
+ | Rodelbahnen = [[Bergkristallhütte]]
+ }}''')
+ inn = v.to_python(wikitext)
+ wikitext2 = v.from_python(inn)
+ assert wikitext == wikitext2
+
+
+ def test_googlemap_to_wrmap(self):
+ wikitext = u'''
+ <googlemap version="0.9" lat="47.113291" lon="11.272337" zoom="15" height="450">
+ (Parkplatz)47.114958,11.266026
+ Erster Parkplatz
+
+ (Gasthaus) 47.114715, 11.266262, Alt Bärnbad (Gasthaus)
+ 6#FF014E9A
+ 47.114715,11.266262
+ 47.114135,11.268381
+ 47.113421,11.269322
+ 47.11277,11.269979
+ 47.112408,11.271119
+ </googlemap>
+ '''
+ attributes, coords, paths = wrpylib.mwmarkup.parse_googlemap(wikitext)
+ json = wrpylib.wrmwmarkup.googlemap_to_wrmap(attributes, coords, paths)
+ assert json['properties']['lon'] == 11.272337
+ assert json['properties']['lat'] == 47.113291
+ assert json['properties']['zoom'] == 15
+ assert json['properties']['height'] == 450
+ assert json['features'][0]['properties']['type'] == 'parkplatz'
+ assert json['features'][0]['properties']['name'] == 'Erster Parkplatz'
+ assert json['features'][0]['geometry']['coordinates'] == [11.266026, 47.114958]
+ assert json['features'][1]['properties']['type'] == 'gasthaus'
+ assert json['features'][1]['properties']['name'] == u'Alt Bärnbad (Gasthaus)'
+ assert json['features'][1]['geometry']['coordinates'] == [11.266262, 47.114715]
+ assert json['features'][2]['properties']['type'] == 'rodelbahn'
+ assert json['features'][2]['geometry']['coordinates'] == [
+ [11.266262, 47.114715],
+ [11.268381, 47.114135],
+ [11.269322, 47.113421],
+ [11.269979, 47.11277],
+ [11.271119, 47.112408]]
+
+
+ def test_parse_wrmap(self):
+ wikitext = u'''
+ <wrmap lat="47.2417134" lon="11.21408895" zoom="14" width="700" height="400">
+ <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 11.190454</gasthaus>
+ <parkplatz>47.245789 11.238971</parkplatz>
+ <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 11.238283</haltestelle>
+ <rodelbahn>
+ 47.238587 11.203360
+ 47.244951 11.230868
+ 47.245470 11.237853
+ </rodelbahn>
+ </wrmap>
+ '''
+ json = wrpylib.wrmwmarkup.parse_wrmap(wikitext)
+ assert json['properties']['lon'] == 11.21408895
+ assert json['properties']['lat'] == 47.2417134
+ assert json['properties']['zoom'] == 14
+ assert json['properties']['width'] == 700
+ assert json['properties']['height'] == 400
+ assert json['features'][0]['properties']['type'] == 'gasthaus'
+ assert json['features'][0]['properties']['name'] == u'Rosskogelhütte'
+ assert json['features'][0]['properties']['wiki'] == u'Rosskogelhütte'
+ assert json['features'][0]['geometry']['coordinates'] == [11.190454, 47.240689]
+ assert json['features'][1]['properties']['type'] == 'parkplatz'
+ assert json['features'][1]['geometry']['coordinates'] == [11.238971, 47.245789]
+ assert json['features'][2]['properties']['type'] == 'haltestelle'
+ assert json['features'][2]['properties']['name'] == u'Oberperfuss Rangger Köpfl Lift'
+ assert json['features'][2]['geometry']['coordinates'] == [11.238283, 47.245711]
+ assert json['features'][3]['properties']['type'] == 'rodelbahn'
+ assert json['features'][3]['geometry']['coordinates'] == [
+ [11.203360, 47.238587],
+ [11.230868, 47.244951],
+ [11.237853, 47.245470]]
+
+
+ def test_create_wrmap(self):
+ geojson = {
+ 'type': 'FeatureCollection',
+ 'features':
+ [{
+ 'type': 'Feature',
+ 'geometry': {
+ 'type': 'Point',
+ 'coordinates': [11.190454, 47.240689]},
+ 'properties': {'type': 'gasthaus', 'name': u'Rosskogelhütte', 'wiki': u'Rosskogelhütte'}
+ }, {
+ 'type': 'Feature',
+ 'geometry': {
+ 'type': 'Point',
+ 'coordinates': [11.238971, 47.245789]},
+ 'properties': {'type': 'parkplatz'}
+ }, {
+ 'type': 'Feature',
+ 'geometry': {
+ 'type': 'Point',
+ 'coordinates': [11.238283, 47.245711]},
+ 'properties': {'type': 'haltestelle', 'name': u'Oberperfuss Rangger Köpfl Lift'}
+ }, {
+ 'type': 'Feature',
+ 'geometry': {
+ 'type': 'LineString',
+ 'coordinates': [
+ [11.203360, 47.238587],
+ [11.230868, 47.244951],
+ [11.237853, 47.245470]]},
+ 'properties': {'type': 'rodelbahn'}
+ }],
+ 'properties': {
+ 'lon': 11.21408895,
+ 'lat': 47.2417134,
+ 'zoom': 14,
+ 'width': 700,
+ 'height': 400}
+ }
+
+ wikitext = wrpylib.wrmwmarkup.create_wrmap(geojson)
+ assert wikitext == textwrap.dedent(u'''\
+ <wrmap height="400" lat="47.241713" lon="11.214089" width="700" zoom="14">
+
+ <gasthaus name="Rosskogelhütte" wiki="Rosskogelhütte">47.240689 N 11.190454 E</gasthaus>
+ <parkplatz>47.245789 N 11.238971 E</parkplatz>
+ <haltestelle name="Oberperfuss Rangger Köpfl Lift">47.245711 N 11.238283 E</haltestelle>
+
+ <rodelbahn>
+ 47.238587 N 11.203360 E
+ 47.244951 N 11.230868 E
+ 47.245470 N 11.237853 E
+ </rodelbahn>
+
+ </wrmap>''')