Exemplo n.º 1
0
 def test_getattr(self):
     # Test T tempt tag factory __getattr__
     custom_tag = T.CustomTag()
     self.assertIsInstance(custom_tag, Tag)
     self.assertIsInstance(custom_tag, DOMElement)
     self.assertEqual(custom_tag._CustomTag__tag, 'customtag')
     self.assertEqual(custom_tag.__class__.__name__, 'CustomTag')
Exemplo n.º 2
0
    def test_inside_places(self):
        class Obj:
            foo = 'foo'
            bar = 'bar'

            class TestA(InsideDiv):
                def repr(self):
                    self(self.bar)

            class A(InsideSpan):
                def repr(self):
                    self(self.foo + 'test')

            class Test2(InsideP):
                def repr(self):
                    self(self.bar + 'test')

        inst = Obj()
        self.assertEqual(Span()(A()(inst)).render(),
                         '<span><a>footest</a></span>')

        inst = Obj()
        self.assertEqual(Div()(Div()(inst)).render(),
                         '<div><div>bar</div></div>')

        inst = Obj()
        self.assertEqual(P()(T.CustomTag()(inst)).render(),
                         '<p><customtag>bartest</customtag></p>')
Exemplo n.º 3
0
    def test_dump(self):
        # Test T dumping a Tempy object to a file
        result = """# -*- coding: utf-8 -*-
from tempy import T
from tempy.tags import *
Div(klass="cssClass", bool_attr="True")(A(href=\"\"\"www.foo.bar\"\"\")(\"\"\"non-tempy content\"\"\"), T.CustomTag(numb_attr=9), Br(), Doctype("html"), Comment("test comment"), T.Void.TestVoid())"""
        filename = 'test.py'
        tempy_tree = [
            Div(klass='cssClass',
                bool_attr=bool)(A(href='www.foo.bar')('non-tempy content'),
                                T.CustomTag(numb_attr=9), Br(),
                                Doctype('html'), Comment('test comment'),
                                T.Void.TestVoid()),
        ]
        T.dump(tempy_tree, filename)
        with open(filename, 'r') as f:
            self.assertEqual(Counter(f.read()), Counter(result))
        os.remove(filename)

        T.dump(tempy_tree, 'test')
        os.remove(filename)

        with self.assertRaises(ValueError):
            T.dump(tempy_tree, 'test.jpg')

        with self.assertRaises(ValueError):
            T.dump(tempy_tree, None)