-#!/usr/bin/python3.4
-# coding=utf-8
import unittest
import mwparserfromhell
import wrpylib.mwmarkup
rb = list(wikicode.filter_templates())[0]
self.assertEqual(rb.name.strip(), 'Rodelbahnbox')
self.assertEqual(rb.get('Aufstiegshilfe').value.strip(), 'Nein')
- self.assertEqual(rb[:2], '{{')
- self.assertEqual(rb[-2:], '}}')
+ self.assertEqual(str(rb)[:2], '{{')
+ self.assertEqual(str(rb)[-2:], '}}')
def test_template_to_table(self):
wikitext = '{{Rodelbahnbox | Unbenannt | Position = 47.309820 N 9.986508 E | Aufstieg möglich = Ja }}'
template.add('Aufstieg möglich', 'Ja')
self.assertEqual(template, '{{Rodelbahnbox|Unbenannt|Position=47.309820 N 9.986508 E|Aufstieg möglich=Ja}}')
- wrpylib.mwmarkup.template_to_table(template)
+ wrpylib.mwmarkup.format_template_table(template)
self.assertEqual(template,
'{{Rodelbahnbox\n' +
'| Unbenannt\n' +
'| Aufstieg möglich = Ja\n' +
'}}')
- wrpylib.mwmarkup.template_to_table(template, 18)
+ wrpylib.mwmarkup.format_template_table(template, 18)
self.assertEqual(template,
'{{Rodelbahnbox\n' +
'| Unbenannt\n' +
template.add('Aufstieg möglich', 'Ja')
self.assertEqual(template, '{{Rodelbahnbox|Unbenannt|Position=47.309820 N 9.986508 E|Aufstieg möglich=Ja}}')
- wrpylib.mwmarkup.template_to_table(template)
+ wrpylib.mwmarkup.format_template_table(template)
self.assertEqual(template,
'{{Rodelbahnbox\n' +
'| Unbenannt\n' +
wikicode = mwparserfromhell.parse(wikitext)
tag = next(wikicode.ifilter_tags())
self.assertEqual('tag', tag.tag)
+
+
+class TestFormatTemplate(unittest.TestCase):
+ def test_format_template_oneline(self):
+ value = mwparserfromhell.parse('{{ my_template || | var = 7 }}').filter_templates()[0]
+ wrpylib.mwmarkup.format_template_oneline(value)
+ self.assertEqual('{{my_template| | |var=7}}', value)
+
+
+class TestMwApi(unittest.TestCase):
+ def test_dbkey_to_title(self):
+ self.assertEqual(wrpylib.mwmarkup.dbkey_to_title('My_Title'), 'My Title')
+ self.assertEqual(wrpylib.mwmarkup.dbkey_to_title('My Title'), 'My Title') # should not happen
+ self.assertEqual(wrpylib.mwmarkup.dbkey_to_title('My_nice_Title'), 'My nice Title')