Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[r4329]: branches / 1.0 / turbogears / tests / test_util.py Maximize Restore History

Download this file

test_util.py    79 lines (52 with data), 1.9 kB

 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import sys
from StringIO import StringIO
from turbogears import util
def test_deprecated():
def some_old_function(x, y):
"""some old function"""
return x + y
some_old_function = util.deprecated('this is old')(some_old_function)
assert "some old function" in some_old_function.__doc__
some_old_function.__name__ == 'some_old_function'
stderr, sys.stderr = sys.stderr, StringIO()
try:
assert some_old_function(1, 2) == 3
finally:
stderr, sys.stderr = sys.stderr, stderr
assert 'DeprecationWarning: this is old' in stderr.getvalue()
stderr.close()
def test_call_on_stack():
def recurse(level):
if level:
return recurse(level-1)
return util.call_on_stack('recurse', dict())
assert not recurse(0)
assert recurse(1)
def recurse(level, arg=None):
if level:
return recurse(level-1, arg)
return util.call_on_stack('recurse', dict(arg='true'), 3)
assert not recurse(3, 'true')
assert recurse(4, 'true')
assert not recurse(4, 'false')
def test_remove_keys():
assert util.remove_keys(dict(x=1, y=2, z=3), 'xz') == dict(y=2)
def test_has_arg():
def fun(x, z=2):
pass
assert util.has_arg(fun, 'x')
assert not util.has_arg(fun, 'y')
assert util.has_arg(fun, 'z')
def test_arg_index():
def fun(a, b, y=3, z=4):
pass
assert util.arg_index(fun, 'a') == 0
assert util.arg_index(fun, 'b') == 1
assert util.arg_index(fun, 'c') is None
assert util.arg_index(fun, 'y') == 2
assert util.arg_index(fun, 'z') == 3
def test_fixentities():
assert util.fixentities('Chip & Chap') \
== 'Chip & Chap'
assert util.fixentities('<&quot;&lt;&copy;&gt;&quot;>') \
== '<&quot;&lt;&#169;&gt;&quot;>'