~ubuntu-branches/ubuntu/utopic/mako/utopic-proposed

« back to all changes in this revision

Viewing changes to test/test_template.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski
  • Date: 2014-06-10 20:38:26 UTC
  • mfrom: (1.4.7)
  • Revision ID: package-import@ubuntu.com-20140610203826-5gtppywd9v3gf14a
Tags: 1.0.0-1
* New upstream release
* Add python-changelog and python-sphinx-paramlinks to Build-Depends
  (needed while rebuilding documentation)
* Enable Python 3.X tests during build (add necessary packages to
  Build-Depends)
* Update links to upstream changelog (now points to changelog.rst)
* Add lintian override for source-is-missing doc/searchindex.js
  (this file is generated by sphinx-build, all sources are in the tarball)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: utf-8 -*-
2
2
 
3
 
from mako.template import Template, ModuleTemplate
 
3
from mako.template import Template, ModuleTemplate, ModuleInfo
4
4
from mako.lookup import TemplateLookup
5
5
from mako.ext.preprocessors import convert_comments
6
6
from mako import exceptions, runtime
12
12
from test import TemplateTest, eq_, template_base, module_base, \
13
13
    requires_python_26_or_greater, assert_raises, assert_raises_message, \
14
14
    requires_python_2
 
15
import unittest
15
16
 
16
17
class ctx(object):
17
18
    def __init__(self, a, b):
1235
1236
            "This is base.", "0", "1", "2", "3", "4"
1236
1237
        ]
1237
1238
 
 
1239
class TestTemplateAPI(unittest.TestCase):
 
1240
    def test_metadata(self):
 
1241
        t = Template("""
 
1242
Text
 
1243
Text
 
1244
% if bar:
 
1245
    ${expression}
 
1246
% endif
 
1247
 
 
1248
<%include file='bar'/>
 
1249
 
 
1250
""", uri="/some/template")
 
1251
        eq_(
 
1252
            ModuleInfo.get_module_source_metadata(t.code, full_line_map=True),
 
1253
            {
 
1254
                'full_line_map': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
 
1255
                                    0, 0, 0, 0, 0, 0, 1, 4, 5, 5, 5, 7, 8,
 
1256
                                    8, 8, 8, 8, 8, 8],
 
1257
                'source_encoding': 'ascii',
 
1258
                'filename': None,
 
1259
                'line_map': {34: 28, 14: 0, 21: 1, 22: 4, 23: 5, 24: 5,
 
1260
                                    25: 5, 26: 7, 27: 8, 28: 8},
 
1261
                'uri': '/some/template'
 
1262
            }
 
1263
 
 
1264
        )
 
1265
 
 
1266
    def test_metadata_two(self):
 
1267
        t = Template("""
 
1268
Text
 
1269
Text
 
1270
% if bar:
 
1271
    ${expression}
 
1272
% endif
 
1273
 
 
1274
    <%block name="foo">
 
1275
        hi block
 
1276
    </%block>
 
1277
 
 
1278
 
 
1279
""", uri="/some/template")
 
1280
        eq_(
 
1281
            ModuleInfo.get_module_source_metadata(t.code, full_line_map=True),
 
1282
            {
 
1283
                'full_line_map': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 
1284
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 4, 5, 5, 5, 7, 7, 7,
 
1285
                            7, 7, 10, 10, 10, 10, 10, 10, 8, 8, 8, 8, 8,
 
1286
                            8, 8, 8, 8, 8, 8, 8],
 
1287
                'source_encoding': 'ascii',
 
1288
                'filename': None,
 
1289
                'line_map': {33: 10, 39: 8, 45: 8, 14: 0, 51: 45, 23: 1,
 
1290
                                24: 4, 25: 5, 26: 5, 27: 5, 28: 7},
 
1291
                'uri': '/some/template'}
 
1292
        )
1238
1293
 
1239
1294
class PreprocessTest(TemplateTest):
1240
1295
    def test_old_comments(self):