Esempio n. 1
0
 def test_render(self):
     tests = [
         (Template(self.name), "{{foo}}"),
         (Template(self.name, self.params), "{{foo|bar|baz|eggs=spam}}")
     ]
     for template, rendered in tests:
         self.assertEqual(template.render(), rendered)
Esempio n. 2
0
 def test_repr(self):
     correct1=  'Template(name=foo, params={})'
     correct2 = 'Template(name=foo, params={"1": "bar", "2": "baz", "eggs": "spam"})'
     tests = [(Template(self.name), correct1),
              (Template(self.name, self.params), correct2)]
     for template, correct in tests:
         self.assertEqual(repr(template), correct)
         self.assertEqual(str(template), correct)
Esempio n. 3
0
 def test_name(self):
     templates = [
         Template(self.name),
         Template(self.name, self.params),
         Template(name=self.name),
         Template(name=self.name, params=self.params)
     ]
     for template in templates:
         self.assertEqual(template.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")
     ]
Esempio n. 5
0
 def test_getitem(self):
     template = Template(name=self.name, params=self.params)
     self.assertIs(template[0], self.bar)
     self.assertIs(template[1], self.baz)
     self.assertIs(template[2], self.eggs)
     self.assertIs(template["1"], self.bar)
     self.assertIs(template["2"], self.baz)
     self.assertIs(template["eggs"], self.eggs)
Esempio n. 6
0
    def test_cmp(self):
        tmp1 = Template(self.name)
        tmp2 = Template(name=self.name)
        tmp3 = Template(self.name, [])
        tmp4 = Template(name=self.name, params=[])
        tmp5 = Template(self.name, self.params)
        tmp6 = Template(name=self.name, params=self.params)

        for tmpA, tmpB in permutations((tmp1, tmp2, tmp3, tmp4), 2):
            self.assertEqual(tmpA, tmpB)

        for tmpA, tmpB in permutations((tmp5, tmp6), 2):
            self.assertEqual(tmpA, tmpB)

        for tmpA in (tmp5, tmp6):
            for tmpB in (tmp1, tmp2, tmp3, tmp4):
                self.assertNotEqual(tmpA, tmpB)
                self.assertNotEqual(tmpB, tmpA)
Esempio n. 7
0
 def test_params(self):
     for template in (Template(self.name), Template(name=self.name)):
         self.assertEqual(template.params, [])
     for template in (Template(self.name, self.params),
                      Template(name=self.name, params=self.params)):
         self.assertEqual(template.params, self.params)
Esempio n. 8
0
 def test_construct(self):
     Template(self.name)
     Template(self.name, self.params)
     Template(name=self.name)
     Template(name=self.name, params=self.params)
Esempio n. 9
0
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import unittest

from mwparserfromhell.parameter import Parameter
from mwparserfromhell.parser import Parser
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}}",