summaryrefslogtreecommitdiff
path: root/cheetah/Tests
diff options
context:
space:
mode:
authorR. Tyler Ballance <tyler@monkeypox.org>2009-11-15 17:20:23 -0800
committerR. Tyler Ballance <tyler@monkeypox.org>2009-11-16 00:04:10 -0800
commit47fbe57de8fc7fab20fd2d6b381ffbae411b74bc (patch)
treef58b3097f2ccb9f5b99fe857abeef3861e7f34b7 /cheetah/Tests
parent74961058e939739e97f9c570d5fc8c0959760dc9 (diff)
downloadpython-cheetah-47fbe57de8fc7fab20fd2d6b381ffbae411b74bc.tar.gz
Clean up a swath of fixes suggested by 2to3
Fixes from 2to3 include: xrange, ws_comma, repr, reduce, raise, idioms, has_key, future, filter, exec, callable, apply
Diffstat (limited to 'cheetah/Tests')
-rw-r--r--cheetah/Tests/CheetahWrapper.py2
-rw-r--r--cheetah/Tests/NameMapper.py72
-rw-r--r--cheetah/Tests/Performance.py8
-rw-r--r--cheetah/Tests/SyntaxAndOutput.py68
-rw-r--r--cheetah/Tests/Template.py8
5 files changed, 79 insertions, 79 deletions
diff --git a/cheetah/Tests/CheetahWrapper.py b/cheetah/Tests/CheetahWrapper.py
index e44edef..1097aa0 100644
--- a/cheetah/Tests/CheetahWrapper.py
+++ b/cheetah/Tests/CheetahWrapper.py
@@ -531,7 +531,7 @@ def listTests(cheetahWrapperFile):
"""
rx = re.compile( R'self\.go\("(.*?)"\)' )
f = open(cheetahWrapperFile)
- while 1:
+ while True:
lin = f.readline()
if not lin:
break
diff --git a/cheetah/Tests/NameMapper.py b/cheetah/Tests/NameMapper.py
index 8efd6ac..fe6b658 100644
--- a/cheetah/Tests/NameMapper.py
+++ b/cheetah/Tests/NameMapper.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
-from __future__ import generators
+
import sys
import types
import os
@@ -34,7 +34,7 @@ class DummyClass:
x = 'A string'
try:
- for i in [1,2,3,4]:
+ for i in [1, 2, 3, 4]:
if x == 2:
pass
@@ -53,52 +53,52 @@ def funcThatRaises():
testNamespace = {
- 'aStr':'blarg',
- 'anInt':1,
- 'aFloat':1.5,
- 'aDict': {'one':'item1',
- 'two':'item2',
- 'nestedDict':{'one':'nestedItem1',
- 'two':'nestedItem2',
- 'funcThatRaises':funcThatRaises,
+ 'aStr': 'blarg',
+ 'anInt': 1,
+ 'aFloat': 1.5,
+ 'aDict': {'one': 'item1',
+ 'two': 'item2',
+ 'nestedDict': {'one': 'nestedItem1',
+ 'two': 'nestedItem2',
+ 'funcThatRaises': funcThatRaises,
'aClass': DummyClass,
},
- 'nestedFunc':dummyFunc,
+ 'nestedFunc': dummyFunc,
},
'aClass': DummyClass,
'aFunc': dummyFunc,
'anObj': DummyClass(),
'aMeth': DummyClass().meth1,
- 'none' : None,
- 'emptyString':'',
- 'funcThatRaises':funcThatRaises,
+ 'none': None,
+ 'emptyString': '',
+ 'funcThatRaises': funcThatRaises,
}
-autoCallResults = {'aFunc':'Scooby',
- 'aMeth':'doo',
+autoCallResults = {'aFunc': 'Scooby',
+ 'aMeth': 'doo',
}
results = testNamespace.copy()
-results.update({'anObj.meth1':'doo',
- 'aDict.one':'item1',
- 'aDict.nestedDict':testNamespace['aDict']['nestedDict'],
- 'aDict.nestedDict.one':'nestedItem1',
- 'aDict.nestedDict.aClass':DummyClass,
- 'aDict.nestedFunc':'Scooby',
- 'aClass.classVar1':123,
- 'anObj.instanceVar1':123,
- 'anObj.meth3':'A string',
+results.update({'anObj.meth1': 'doo',
+ 'aDict.one': 'item1',
+ 'aDict.nestedDict': testNamespace['aDict']['nestedDict'],
+ 'aDict.nestedDict.one': 'nestedItem1',
+ 'aDict.nestedDict.aClass': DummyClass,
+ 'aDict.nestedFunc': 'Scooby',
+ 'aClass.classVar1': 123,
+ 'anObj.instanceVar1': 123,
+ 'anObj.meth3': 'A string',
})
for k in testNamespace.keys():
# put them in the globals for the valueFromFrame tests
- exec '%s = testNamespace[k]'%k
+ exec('%s = testNamespace[k]'%k)
##################################################
## TEST BASE CLASSES
class NameMapperTest(unittest.TestCase):
- failureException = (NotFound,AssertionError)
+ failureException = (NotFound, AssertionError)
_testNamespace = testNamespace
_results = results
@@ -117,7 +117,7 @@ class NameMapperTest(unittest.TestCase):
def check(self, name):
got = self.get(name)
- if autoCallResults.has_key(name):
+ if name in autoCallResults:
expected = autoCallResults[name]
else:
expected = self._results[name]
@@ -317,7 +317,7 @@ class VFN(NameMapperTest):
def test(self=self):
self.get('anObj.methX')
- self.assertRaises(NotFound,test)
+ self.assertRaises(NotFound, test)
def test44(self):
"""NotFound test in a loop"""
@@ -325,7 +325,7 @@ class VFN(NameMapperTest):
self.get('anObj.methX')
for i in range(10):
- self.assertRaises(NotFound,test)
+ self.assertRaises(NotFound, test)
def test45(self):
"""Other exception from meth test"""
@@ -340,7 +340,7 @@ class VFN(NameMapperTest):
self.get('anObj.meth2')
for i in range(10):
- self.assertRaises(ValueError,test)
+ self.assertRaises(ValueError, test)
def test47(self):
"""None in dict lookup"""
@@ -373,7 +373,7 @@ class VFN(NameMapperTest):
self.get('funcThatRaises')
for i in range(10):
- self.assertRaises(ValueError,test)
+ self.assertRaises(ValueError, test)
def test53(self):
@@ -389,7 +389,7 @@ class VFN(NameMapperTest):
self.get('aDict.nestedDict.funcThatRaises')
for i in range(10):
- self.assertRaises(ValueError,test)
+ self.assertRaises(ValueError, test)
def test55(self):
"""aDict.nestedDict.aClass in dict lookup"""
@@ -428,10 +428,10 @@ class VFS(VFN):
if lng == 1:
return [self.namespace()]
elif lng == 2:
- return [self.namespace(),{'dummy':1234}]
+ return [self.namespace(), {'dummy':1234}]
elif lng == 3:
# a tuple for kicks
- return ({'dummy':1234}, self.namespace(),{'dummy':1234})
+ return ({'dummy':1234}, self.namespace(), {'dummy':1234})
elif lng == 4:
# a generator for more kicks
return self.searchListGenerator()
@@ -439,7 +439,7 @@ class VFS(VFN):
def searchListGenerator(self):
class Test:
pass
- for i in [Test(),{'dummy':1234}, self.namespace(),{'dummy':1234}]:
+ for i in [Test(), {'dummy':1234}, self.namespace(), {'dummy':1234}]:
yield i
def get(self, name, autocall=True):
diff --git a/cheetah/Tests/Performance.py b/cheetah/Tests/Performance.py
index fc74367..d76cc00 100644
--- a/cheetah/Tests/Performance.py
+++ b/cheetah/Tests/Performance.py
@@ -78,7 +78,7 @@ class DynamicTemplatePerformanceTest(unittest.TestCase):
#pass
#end def
'''
- for i in xrange(self.loops):
+ for i in range(self.loops):
klass = Cheetah.Template.Template.compile(template)
assert klass
test_BasicDynamic = perftest(1200)(test_BasicDynamic)
@@ -91,7 +91,7 @@ class PerformanceTest(unittest.TestCase):
def runTest(self):
self.prof = hotshot.Profile('%s.prof' % self.__class__.__name__)
self.prof.start()
- for i in xrange(self.iterations):
+ for i in range(self.iterations):
if hasattr(self, 'performanceSample'):
self.display = True
self.performanceSample()
@@ -130,7 +130,7 @@ class BunchOfWriteCalls(PerformanceTest):
template = '''
#import sys
#import os
- #for i in xrange(1000)
+ #for i in range(1000)
$i
#end for
'''
@@ -210,7 +210,7 @@ class LongCompileTest(PerformanceTest):
<body>
$header()
- #for $i in $xrange(10)
+ #for $i in $range(10)
This is just some stupid page!
<br/>
#end for
diff --git a/cheetah/Tests/SyntaxAndOutput.py b/cheetah/Tests/SyntaxAndOutput.py
index 0702ded..452dcbb 100644
--- a/cheetah/Tests/SyntaxAndOutput.py
+++ b/cheetah/Tests/SyntaxAndOutput.py
@@ -67,37 +67,37 @@ def dummyFunc(arg="Scooby"):
return arg
defaultTestNameSpace = {
- 'aStr':'blarg',
- 'anInt':1,
- 'aFloat':1.5,
- 'aList': ['item0','item1','item2'],
- 'aDict': {'one':'item1',
- 'two':'item2',
- 'nestedDict':{1:'nestedItem1',
+ 'aStr': 'blarg',
+ 'anInt': 1,
+ 'aFloat': 1.5,
+ 'aList': ['item0', 'item1', 'item2'],
+ 'aDict': {'one': 'item1',
+ 'two': 'item2',
+ 'nestedDict': {1:'nestedItem1',
'two':'nestedItem2'
},
- 'nestedFunc':dummyFunc,
+ 'nestedFunc': dummyFunc,
},
'aFunc': dummyFunc,
'anObj': DummyClass(),
'aMeth': DummyClass().meth1,
'aStrToBeIncluded': "$aStr $anInt",
- 'none' : None,
- 'emptyString':'',
- 'numOne':1,
- 'numTwo':2,
- 'zero':0,
+ 'none': None,
+ 'emptyString': '',
+ 'numOne': 1,
+ 'numTwo': 2,
+ 'zero': 0,
'tenDigits': 1234567890,
'webSafeTest': 'abc <=> &',
'strip1': ' \t strippable whitespace \t\t \n',
'strip2': ' \t strippable whitespace \t\t ',
'strip3': ' \t strippable whitespace \t\t\n1 2 3\n',
- 'blockToBeParsed':"""$numOne $numTwo""",
- 'includeBlock2':"""$numOne $numTwo $aSetVar""",
+ 'blockToBeParsed': """$numOne $numTwo""",
+ 'includeBlock2': """$numOne $numTwo $aSetVar""",
- 'includeFileName':'parseTest.txt',
- 'listOfLambdas':[lambda x: x, lambda x: x, lambda x: x,],
+ 'includeFileName': 'parseTest.txt',
+ 'listOfLambdas': [lambda x: x, lambda x: x, lambda x: x,],
'list': [
{'index': 0, 'numOne': 1, 'numTwo': 2},
{'index': 1, 'numOne': 1, 'numTwo': 2},
@@ -105,7 +105,7 @@ defaultTestNameSpace = {
'nameList': [('john', 'doe'), ('jane', 'smith')],
'letterList': ['a', 'b', 'c'],
'_': lambda x: 'Translated: ' + x,
- 'unicodeData':u'aoeu12345\u1234',
+ 'unicodeData': u'aoeu12345\u1234',
}
@@ -185,9 +185,9 @@ Template output mismatch:
if self._debugEOLReplacement and self._EOLreplacement:
EOLrepl = self._EOLreplacement
marker = '*EOL*'
- return self.report % {'template': self._input.replace(EOLrepl,marker),
- 'expected': expectedOutput.replace(EOLrepl,marker),
- 'actual': output.replace(EOLrepl,marker),
+ return self.report % {'template': self._input.replace(EOLrepl, marker),
+ 'expected': expectedOutput.replace(EOLrepl, marker),
+ 'actual': output.replace(EOLrepl, marker),
'end': '(end)'}
else:
return self.report % {'template': self._input,
@@ -237,7 +237,7 @@ class Backslashes(OutputTest):
convertEOLs = False
def setUp(self):
- fp = open('backslashes.txt','w')
+ fp = open('backslashes.txt', 'w')
fp.write(r'\ #LogFormat "%h %l %u %t \"%r\" %>s %b"' + '\n\n\n\n\n\n\n')
fp.flush()
fp.close
@@ -620,7 +620,7 @@ class Placeholders(OutputTest):
tmpl = tmpl.subclass('#for name in $names: $*1*(name) ')
assert str(tmpl({'names':names}))=='You '*len(names)
- if versionTuple > (2,2):
+ if versionTuple > (2, 2):
tmpl = tmpl.subclass('#for name in $names: $*1*(name) ')
assert str(tmpl(names=names))=='You '*len(names)
@@ -1477,7 +1477,7 @@ class YieldDirective(OutputTest):
)
- for src in (src1,src2,src3):
+ for src in (src1, src2, src3):
klass = Template.compile(src, keepRefToGeneratedCode=True)
#print klass._CHEETAH_generatedModuleCode
iter = klass().respond()
@@ -1487,7 +1487,7 @@ class YieldDirective(OutputTest):
# @@TR: need to expand this to cover error conditions etc.
-if versionTuple < (2,3):
+if versionTuple < (2, 3):
del YieldDirective
class ForDirective(OutputTest):
@@ -1589,7 +1589,7 @@ class ForDirective(OutputTest):
self.verify("#for $i in range(5): \n$i\n#end for",
"0\n1\n2\n3\n4\n")
-if versionTuple < (2,3):
+if versionTuple < (2, 3):
del ForDirective.test12
class RepeatDirective(OutputTest):
@@ -1826,7 +1826,7 @@ class DecoratorDirective(OutputTest):
"$testMeth",
"1234\n")
-if versionTuple < (2,4):
+if versionTuple < (2, 4):
del DecoratorDirective
class BlockDirective(OutputTest):
@@ -1941,7 +1941,7 @@ inner
class IncludeDirective(OutputTest):
def setUp(self):
- fp = open('parseTest.txt','w')
+ fp = open('parseTest.txt', 'w')
fp.write("$numOne $numTwo")
fp.flush()
fp.close
@@ -3192,7 +3192,7 @@ public class X
##################################################
## CREATE CONVERTED EOL VERSIONS OF THE TEST CASES
-if OutputTest._useNewStyleCompilation and versionTuple >= (2,3):
+if OutputTest._useNewStyleCompilation and versionTuple >= (2, 3):
extraCompileKwArgsForDiffBaseclass = {'baseclass':dict}
else:
extraCompileKwArgsForDiffBaseclass = {'baseclass':object}
@@ -3202,16 +3202,16 @@ def install_eols():
klasses = [v for v in globals().values() if isinstance(v, type) and issubclass(v, unittest.TestCase)]
for klass in klasses:
name = klass.__name__
- if hasattr(klass,'convertEOLs') and klass.convertEOLs:
+ if hasattr(klass, 'convertEOLs') and klass.convertEOLs:
win32Src = r"class %(name)s_Win32EOL(%(name)s): _EOLreplacement = '\r\n'"%locals()
macSrc = r"class %(name)s_MacEOL(%(name)s): _EOLreplacement = '\r'"%locals()
- exec win32Src in globals()
- exec macSrc in globals()
+ exec(win32Src, globals())
+ exec(macSrc, globals())
- if versionTuple >= (2,3):
+ if versionTuple >= (2, 3):
src = r"class %(name)s_DiffBaseClass(%(name)s): "%locals()
src += " _extraCompileKwArgs = extraCompileKwArgsForDiffBaseclass"
- exec src in globals()
+ exec(src, globals())
del name
del klass
diff --git a/cheetah/Tests/Template.py b/cheetah/Tests/Template.py
index 7edbdb9..331c0f9 100644
--- a/cheetah/Tests/Template.py
+++ b/cheetah/Tests/Template.py
@@ -44,7 +44,7 @@ class ClassMethods_compile(TemplateTest):
assert str(t)=='1234'
def test_moduleFileCaching(self):
- if versionTuple < (2,3):
+ if versionTuple < (2, 3):
return
tmpDir = tempfile.mkdtemp()
try:
@@ -220,9 +220,9 @@ class Preprocessors(TemplateTest):
class TemplateSubclass(Template):
pass
- compilerSettings = {'cheetahVarStartToken':'@',
- 'directiveStartToken':'%',
- 'commentStartToken':'%%',
+ compilerSettings = {'cheetahVarStartToken': '@',
+ 'directiveStartToken': '%',
+ 'commentStartToken': '%%',
}
for arg in ['@ %',