Пример #1
0
    def test_path(self):
        template = PageTemplateFile("path.pt")

        class Context(object):
            dummy_wysiwyg_support = True

        context = Context()
        template = template.__get__(context, Context)

        result = template(editor="dummy")
        self.assertTrue("supported" in result)
        self.assertTrue("some path" in result)
Пример #2
0
def load_template(name, context=None, _memo={}):
    ''' load the main template '''
    if name not in _memo:
        tpl = PageTemplateFile(name)

        if context is not None:
            bound = tpl.bind(context)
            _memo[name] = bound
        else:
            _memo[name] = tpl

    return _memo[name]
Пример #3
0
    def test_path(self):
        template = PageTemplateFile("path.pt")

        class Context(object):
            dummy_wysiwyg_support = True

        context = Context()
        template = template.__get__(context, Context)

        result = template(editor="dummy")
        self.assertTrue("supported" in result)
        self.assertTrue("some path" in result)
Пример #4
0
    def test_path(self):
        from z3c.pt.pagetemplate import PageTemplateFile
        template = PageTemplateFile("path.pt")

        class Context(object):
            dummy_wysiwyg_support = True

        context = Context()
        template = template.__get__(context, Context)

        result = template(editor="dummy")
        self.failUnless("supported" in result)
        self.failUnless("some path" in result)
Пример #5
0
 def test_exists(self):
     from z3c.pt.pagetemplate import PageTemplateFile
     template = PageTemplateFile("exists.pt")
     def dont_call():
         raise RuntimeError()
     result = template(callable=dont_call)
     self.failUnless('ok' in result)
Пример #6
0
 def test_nocall(self):
     from z3c.pt.pagetemplate import PageTemplateFile
     template = PageTemplateFile("nocall.pt")
     def dont_call():
         raise RuntimeError()
     result = template(callable=dont_call)
     self.failUnless(repr(dont_call) in result)
Пример #7
0
    def test_exists(self):
        template = PageTemplateFile("exists.pt")

        def dont_call():
            raise AssertionError("Should not be called")

        result = template(callable=dont_call)
        self.assertTrue("ok" in result)
Пример #8
0
    def test_nocall(self):
        template = PageTemplateFile("nocall.pt")

        def dont_call():
            raise AssertionError("Should not be called")

        result = template(callable=dont_call)
        self.assertTrue(repr(dont_call) in result)
Пример #9
0
class z3cPageTemplate(grok.components.GrokTemplate):
    def setFromString(self, string):
        self._template = PageTemplate(string)

    def setFromFilename(self, filename, _prefix=None):
        filename = os.path.join(_prefix, filename)
        self._template = PageTemplateFile(filename)

    def render(self, view):
        return self._template.render(**self.getNamespace(view))
Пример #10
0
 def test_boolean_attribute(self):
     from z3c.pt.pagetemplate import PageTemplateFile
     template = PageTemplateFile("boolean.pt")
     result = template()
     self.failIf('False' in result)
     self.failUnless('checked="checked"' in result)
Пример #11
0
 def test_false_attribute(self):
     from z3c.pt.pagetemplate import PageTemplateFile
     template = PageTemplateFile("false.pt")
     result = template()
     self.failUnless('False' in result)
Пример #12
0
        actions['callgrind'] = ''
    if config.profiling.memory_profile_log:
        actions['memory_profile_start'] = (memory(), resident())
    if actions:
        if 'sql' in actions:
            condition = actions['sql']
            if condition not in (True, False):
                condition = condition['condition']
            da.start_sql_logging(condition)
        if 'show' in actions or available_profilers.intersection(actions):
            _profilers.profiler = Profiler()
            _profilers.profiler.start()
        _profilers.profiling = True
        _profilers.actions = actions

template = PageTemplateFile(
    os.path.join(os.path.dirname(__file__), 'profile.pt'))


available_profilers = frozenset(('pstats', 'callgrind'))


def start():
    """Turn on profiling from code.
    """
    actions = _profilers.actions
    profiler = _profilers.profiler
    if actions is None:
        actions = _profilers.actions = {}
        _profilers.profiling = True
    elif 'inline' not in actions and (
        'show' in actions or available_profilers.intersection(actions)):
Пример #13
0
 def test_boolean_attribute(self):
     template = PageTemplateFile("boolean.pt")
     result = template()
     self.assertFalse("False" in result)
     self.assertTrue('checked="checked"' in result)
Пример #14
0
 def test_false_attribute(self):
     template = PageTemplateFile("false.pt")
     result = template()
     self.assertTrue("False" in result)
Пример #15
0
 def setFromFilename(self, filename, _prefix=None):
     filename = os.path.join(_prefix, filename)
     self._template = PageTemplateFile(filename)
Пример #16
0
 def setFromString(self, string):
     self._template = PageTemplate(string)