def test_templates(self): tests = [(Parameter(self.name, self.value3, self.templates3), self.templates3), (Parameter(name=self.name, value=self.value4, templates=self.templates4), self.templates4)] for param, correct in tests: self.assertEqual(param.templates, correct)
def test_value(self): tests = [(Parameter(self.name, self.value1), self.value1), (Parameter(self.name, self.value2, self.templates2), self.value2), (Parameter(name=self.name, value=self.value3), self.value3), (Parameter(name=self.name, value=self.value4, templates=self.templates4), self.value4)] for param, correct in tests: self.assertEqual(param.value, correct)
def test_name(self): params = [ Parameter(self.name, self.value1), Parameter(self.name, self.value2, self.templates2), Parameter(name=self.name, value=self.value3), Parameter(name=self.name, value=self.value4, templates=self.templates4) ] for param in params: self.assertEqual(param.name, self.name)
def setUp(self): self.name = "foo" self.value1 = "bar" self.value2 = "{{spam}}" self.value3 = "bar{{spam}}" self.value4 = "embedded {{eggs|spam|baz=buz}} {{goes}} here" self.templates2 = [Template("spam")] self.templates3 = [Template("spam")] self.templates4 = [ Template("eggs", [Parameter("1", "spam"), Parameter("baz", "buz")]), Template("goes") ]
def test_magic(self): params = [ Parameter(self.name, self.value1), Parameter(self.name, self.value2, self.templates2), Parameter(self.name, self.value3, self.templates3), Parameter(self.name, self.value4, self.templates4) ] for param in params: self.assertEqual(repr(param), repr(param.value)) self.assertEqual(str(param), str(param.value)) self.assertIs(param < "eggs", param.value < "eggs") self.assertIs(param <= "bar{{spam}}", param.value <= "bar{{spam}}") self.assertIs(param == "bar", param.value == "bar") self.assertIs(param != "bar", param.value != "bar") self.assertIs(param > "eggs", param.value > "eggs") self.assertIs(param >= "bar{{spam}}", param.value >= "bar{{spam}}") self.assertEquals(bool(param), bool(param.value)) self.assertEquals(len(param), len(param.value)) self.assertEquals(list(param), list(param.value)) self.assertEquals(param[2], param.value[2]) self.assertEquals(list(reversed(param)), list(reversed(param.value))) self.assertIs("bar" in param, "bar" in param.value) self.assertEquals(param + "test", param.value + "test") self.assertEquals("test" + param, "test" + param.value) # add param # add template left # add template right self.assertEquals( param * 3, Parameter(param.name, param.value * 3, param.templates * 3)) self.assertEquals( 3 * param, Parameter(param.name, 3 * param.value, 3 * param.templates)) # add param inplace # add template implace # add str inplace # multiply int inplace self.assertIsInstance(param, Parameter) self.assertIsInstance(param.value, str)
def setUp(self): self.name = "foo" self.bar = Parameter("1", "bar") self.baz = Parameter("2", "baz") self.eggs = Parameter("eggs", "spam") self.params = [self.bar, self.baz, self.eggs]
def test_construct(self): Parameter(self.name, self.value1) Parameter(self.name, self.value2, self.templates2) Parameter(name=self.name, value=self.value3) Parameter(name=self.name, value=self.value4, templates=self.templates4)
from mwparserfromhell.template import Template TESTS = [ ("", []), ("abcdef ghijhk", []), ("abc{this is not a template}def", []), ("neither is {{this one}nor} {this one {despite}} containing braces", []), ("this is an acceptable {{template}}", [Template("template")]), ("{{multiple}}{{templates}}", [Template("multiple"), Template("templates")]), ("multiple {{-}} templates {{+}}!", [Template("-"), Template("+")]), ("{{{no templates here}}}", []), ("{ {{templates here}}}", [Template("templates here")]), ("{{{{I do not exist}}}}", []), ("{{foo|bar|baz|eggs=spam}}", [Template("foo", [Parameter("1", "bar"), Parameter("2", "baz"), Parameter("eggs", "spam")])]), ("{{abc def|ghi|jk=lmno|pqr|st=uv|wx|yz}}", [Template("abc def", [Parameter("1", "ghi"), Parameter("jk", "lmno"), Parameter("2", "pqr"), Parameter("st", "uv"), Parameter("3", "wx"), Parameter("4", "yz")])]), ("{{this has a|{{template}}|inside of it}}", [Template("this has a", [Parameter("1", "{{template}}", [Template("template")]), Parameter("2", "inside of it")])]), ("{{{{I exist}} }}", [Template("I exist", [] )]), ("{{}}") ] class TestParser(unittest.TestCase): def test_parse(self):