File: test_util.py

package info (click to toggle)
mako 1.0.6%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,556 kB
  • ctags: 1,495
  • sloc: python: 11,807; makefile: 167
file content (51 lines) | stat: -rw-r--r-- 1,689 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- coding: utf-8 -*-

import os
import unittest
from mako import util, exceptions, compat
from test import eq_, skip_if, assert_raises_message
from mako.compat import u

class UtilTest(unittest.TestCase):
    def test_fast_buffer_write(self):
        buf = util.FastEncodingBuffer()
        buf.write("string a ")
        buf.write("string b")
        eq_(buf.getvalue(), "string a string b")

    def test_fast_buffer_truncate(self):
        buf = util.FastEncodingBuffer()
        buf.write("string a ")
        buf.write("string b")
        buf.truncate()
        buf.write("string c ")
        buf.write("string d")
        eq_(buf.getvalue(), "string c string d")

    def test_fast_buffer_encoded(self):
        s = u("drôl m’a rée « S’il")
        buf = util.FastEncodingBuffer(encoding='utf-8')
        buf.write(s[0:10])
        buf.write(s[10:])
        q = buf.getvalue()
        eq_(buf.getvalue(), s.encode('utf-8'))

    def test_read_file(self):
        fn = os.path.join(os.path.dirname(__file__), 'test_util.py')
        data = util.read_file(fn, 'rb')
        assert 'test_util' in str(data)  # str() for py3k

    @skip_if(lambda: compat.pypy, "Pypy does this differently")
    def test_load_module(self):
        fn = os.path.join(os.path.dirname(__file__), 'test_util.py')
        module = compat.load_module('mako.template', fn)
        import mako.template
        self.assertEqual(module, mako.template)

    def test_load_plugin_failure(self):
        loader = util.PluginLoader("fakegroup")
        assert_raises_message(
            exceptions.RuntimeException,
            "Can't load plugin fakegroup fake",
            loader.load, "fake"
        )