"Fossies" - the Fresh Open Source Software Archive

Member "cheetah3-3.2.6.post2/Cheetah/Tools/turbocheetah/tests/test_template.py" (20 Apr 2021, 2457 Bytes) of package /linux/www/cheetah3-3.2.6.post2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "test_template.py": 3-3.1.0_vs_3-3.2.0.

    1 import os
    2 from ..cheetahsupport import TurboCheetah
    3 
    4 here = os.path.dirname(__file__)
    5 
    6 values = {
    7     'v': 'VV',
    8     'one': 1,
    9 }
   10 
   11 
   12 def test_normal():
   13     plugin = TurboCheetah()
   14     # Make sure a simple test works:
   15     s = plugin.render(values, template='turbocheetah.tests.simple1')
   16     assert s.strip() == 'This is a test: VV'
   17     # Make sure one template can inherit from another:
   18     s = plugin.render(values, template='turbocheetah.tests.import_inherit')
   19     assert s.strip() == 'Inherited: import'
   20 
   21 
   22 def test_path():
   23     plugin = TurboCheetah()
   24     plugin.search_path = [here]
   25     # Make sure we pick up filenames (basic test):
   26     s = plugin.render(values, template_file='simple1')
   27     assert s.strip() == 'This is a test: VV'
   28     # Make sure we pick up subdirectories:
   29     s = plugin.render(values, template_file='sub/master')
   30     assert s.strip() == 'sub1: 1'
   31 
   32 
   33 def test_search():
   34     plugin = TurboCheetah()
   35     plugin.search_path = [os.path.join(here, 'sub'),
   36                           os.path.join(here, 'sub2'),
   37                           here]
   38     # Pick up from third entry:
   39     s = plugin.render(values, template_file='simple1')
   40     assert s.strip() == 'This is a test: VV'
   41     # Pick up from sub/master, non-ambiguous:
   42     s = plugin.render(values, template_file='master')
   43     assert s.strip() == 'sub1: 1'
   44     # Pick up from sub/page, inherit from sub/template:
   45     s = plugin.render(values, template_file='page')
   46     assert s.strip() == 'SUB: sub content'
   47     # Pick up from sub2/page_over, inherit from sub/template:
   48     s = plugin.render(values, template_file='page_over')
   49     assert s.strip() == 'SUB: override content'
   50     # Pick up from sub/page_template_over, inherit from
   51     # sub2/template_over:
   52     s = plugin.render(values, template_file='page_template_over')
   53     assert s.strip() == 'OVER: sub content'
   54     # Change page, make sure that undoes overrides:
   55     plugin.search_path = [os.path.join(here, 'sub'),
   56                           here]
   57     s = plugin.render(values, template_file='page_over')
   58     assert s.strip() == 'SUB: sub content'
   59 
   60 
   61 def test_string():
   62     # Make sure simple string evaluation works:
   63     plugin = TurboCheetah()
   64     s = plugin.render(values, template_string="""Hey $v""")
   65     assert s == "Hey VV"
   66     # Make sure a string can inherit from a file:
   67     plugin.search_path = [here]
   68     s = plugin.render(values, template_string="#extends inherit_from\ns value")
   69     assert s.strip() == 'inherit: s value'