예제 #1
0
    def test_factory(self):
        "Testing the data factory"
        class MyFactory:
            def __call__(self, o, time, y=1):
                d = dict()
                d['o'] = o
                d['y'] = y
                d['time'] = time
                d['func'] = lambda x: x + 1
                return d

        our_dir, _ = os.path.split(__file__)
        report = Report(os.path.join(our_dir, 'templates', 'time.tmpl'),
                        'text/plain', MyFactory(), self.loader)

        a = StubObject(name='Foo')
        eq_(report(o=a, time="One o'clock").render(),
            "Hi Foo,\nIt's One o'clock to 2 !\n")
        eq_(report(o=a, time="One o'clock", y=4).render(),
            "Hi Foo,\nIt's One o'clock to 5 !\n")
        assert_raises(TypeError, report, a)
예제 #2
0
 def setup(self):
     self.loader = MIMETemplateLoader()
     our_dir, _ = os.path.split(__file__)
     self.report = Report(os.path.join(our_dir, 'templates', 'test.tmpl'),
                          'text/plain', DefaultFactory(), self.loader)
예제 #3
0
 def test_include(self):
     our_dir = os.path.dirname(__file__)
     template_path = os.path.join(our_dir, 'templates')
     relative_report = Report(os.path.join(template_path, 'include.tmpl'),
                              'text/plain')
     eq_(relative_report().render(), 'Another Hello.\n\n')