Ejemplo n.º 1
0
 def test_register_without_priority(self):
     """ Registering a tag without specifying a priority: default to 0 """
     tag_objs = [Tag("dummy"), Tag("dumdum"), Tag("mudmud")]
     tag.register(*tag_objs)
     tags = tag.get_manager()._tag_list
     self.assertTrue(0 in tags.keys())
     self.assertEqual(len(tags[0]), 3)
     self.assertListEqual(tags[0], tag_objs)
Ejemplo n.º 2
0
    def test_register_Tag_sublass(self):
        """ Registering a Tag subclass """

        class DummyTag(Tag):
            pass

        t = DummyTag("dummy")
        tag.register(t)
        self.assertTrue(isinstance(tag.get_manager()._tag_list[0], DummyTag))
Ejemplo n.º 3
0
 def test_global_cache_clear(self):
     """ Clearing all registered tags' cache """
     tag.register(tag.Tag("dummy", cached=True), tag.Tag("dumdum", cached=True), tag.Tag("mudmud", cached=True))
     m = tag.get_manager()
     for t in m:
         t.process("dummydumdummudmud", **{"dummy": "dummy", "dumdum": "dumdum", "mudmud": "mudmud"})
     m.clear_cache()
     for t in m:
         self.assertEqual({}, t.cache)
Ejemplo n.º 4
0
 def test_several_tags(self):
     """ Rendering a template containing several different tags """
     tag.register("%dummytag%", "{muddytag}", "--dumdum--")
     tmpl = template.Template("%dummytag%, {muddytag} & --dumdum--")
     args = {
         "%dummytag%" : "dummyval",
         "{muddytag}" : "foo",
         "--dumdum--" : "bar"
     }
     self.assertEqual("dummyval, foo & bar", self.render(tmpl, **args))
Ejemplo n.º 5
0
 def test_basic_rendering_filetemplate(self):
     """ Basic rendering of a file template """
     tag.register(r"{{ (\w+) }}")
     t = template.Template.from_file(self.tmplpath)
     rt = t(title="TIE Is Evil", name="Raphi", age=26)
     self.assertEqual("{{ include testinclude.txt }}\n"
                      "TIE Is Evil\n"
                      "Hello, my name is Raphi\n"
                      "I'm 26 years old and my name is Raphi !",
                      rt)
Ejemplo n.º 6
0
    def test_custom_manager_registration(self):
        """ Registration with a custom tag manager """

        class dummy_manager(object):
            patterns = []

            def add(self, t):
                self.patterns.append(t)

        dm = dummy_manager()
        tag.set_manager(dm)
        tag.register(*self.tags)
        self.assertListEqual(self.tags, dm.patterns)
Ejemplo n.º 7
0
 def test_rendering_filetemplate_with_customtag(self):
     """ Rendering a file template with a custom tag defined """
     def include_tag(match, **context):
         fname = match.group(1)
         return "Contents of file %s" % fname
     tag.register(r"{{ (\w+) }}")
     tag.register(tag.Tag(r"{{ include (\w.+) }}", processor=include_tag))
     t = template.Template.from_file(self.tmplpath)
     rt = t(title="TIE Is Evil", name="Bobby", age=32)
     self.assertEqual("Contents of file testinclude.txt\n"
                      "TIE Is Evil\n"
                      "Hello, my name is Bobby\n"
                      "I'm 32 years old and my name is Bobby !",
                      rt)
Ejemplo n.º 8
0
 def test_repeated_tags(self):
     """ Rendering a template containing repeated tags """
     tag.register("--dumdum--")
     tmpl = template.Template("--dumdum--, --dumdum-- & --dumdum--")
     self.assertEqual("foo, foo & foo",
                      self.render(tmpl, **{"--dumdum--": "foo"}))
Ejemplo n.º 9
0
 def test_single_tag(self):
     """ Rendering a single tag template """
     tag.register("%dummytag%")
     tmpl = template.Template("dum dummy %dummytag% dumdum")
     self.assertEqual("dum dummy dummyval dumdum",
                      self.render(tmpl, **{"%dummytag%": "dummyval"}))
Ejemplo n.º 10
0
 def test_no_tag_matched(self):
     """ Template default renderer should return the template string unchanged if no tag matched """
     tag.register('foo')
     tmpl = template.Template("dummydumdum")
     self.assertEqual(tmpl.template, self.render(tmpl))
Ejemplo n.º 11
0
 def test_register_with_priority(self):
     """ Registering tag with a PriorityTagManager """
     try:
         tag.register(("dummy", 0), ("dumdum", 7), ("mudmud", 4))
     except Exception:
         self.fail("Couldnt register Priority Tags")
Ejemplo n.º 12
0
 def test_manager_iterator(self):
     """ Iterating directly over a TagManager """
     tags = TestRegistration.tags
     tag.register(*tags)
     for i, t in enumerate(tag._manager):
         self.assertEqual(t, tags[i])
Ejemplo n.º 13
0
 def test_register_string(self):
     """ Registering string instead of Tag instances """
     tag.register("dummy", "dumdum", "mudmud")
     self.assertTrue(all(map(lambda t: isinstance(t, tag.Tag), tag._manager)))
Ejemplo n.º 14
0
 def test_basic_registration(self):
     """ Basic tag registration and retrieval """
     tag.register(*self.tags)
     self.assertEqual(len(tag._manager._tag_list), 3)
     self.assertListEqual(self.tags, tag._manager._tag_list)
Ejemplo n.º 15
0
 def test_check_tags_priority(self):
     """ Checking Tags priority """
     tag.register(("dummy", 4), ("dumdum", 7), ("mudmud", 0))
     tag_patterns = [t.regexp.pattern for t in tag.get_manager()]
     self.assertListEqual(tag_patterns, ["mudmud", "dummy", "dumdum"])