test('count', 'aaa', 3, 'a')
test('count', 'aaa', 0, 'b')
-
+
test('find', 'abcdefghiabc', 0, 'abc')
test('find', 'abcdefghiabc', 9, 'abc', 1)
test('find', 'abcdefghiabc', -1, 'def', 4)
# test codec's full path name (see test/testcodec.py)
codecname = 'test.testcodec'
-
+
check(unicode('abc', codecname), u'abc')
check(unicode('xdef', codecname), u'abcdef')
check(unicode('defx', codecname), u'defabc')
print '\\001 maps to undefined: OK'
else:
print '*** check failed: \\001 does not map to undefined'
-
Roger E. Masse
"""
-from test_support import verify, verbose
+from test_support import verify, verbose
import crypt
c = crypt.crypt('mypassword', 'ab')
"unsupported format character 'a' (0x61) at index 5")
test_exc(u'abc %\u3000', 1, ValueError,
"unsupported format character '?' (0x3000) at index 5")
-
fails = fails + 1
def test_make_parser2():
- try:
+ try:
# Creating parsers several times in a row should succeed.
# Testing this because there have been failures of this kind
# before.
return 0
else:
return p
-
-
+
+
# ===========================================================================
#
# saxutils tests
return parser.getSystemId() is None and \
parser.getPublicId() is None and \
- parser.getLineNumber() == 1
+ parser.getLineNumber() == 1
def test_expat_locator_withinfo():
result = StringIO()
return file
def verify(condition, reason='test failed'):
-
- """ Verify that condition is true. If not, raise an
- AssertionError.
-
- The optinal argument reason can be given to provide
- a better error text.
-
- """
- if not condition:
- raise AssertionError,reason
+
+ """ Verify that condition is true. If not, raise an
+ AssertionError.
+
+ The optinal argument reason can be given to provide
+ a better error text.
+
+ """
+ if not condition:
+ raise AssertionError,reason
# Non surrogate above surrogate value, fixup required
def test_lecmp(s, s2):
- verify(s < s2 , "comparison failed on %s < %s" % (s, s2))
+ verify(s < s2 , "comparison failed on %s < %s" % (s, s2))
def test_fixup(s):
s2 = u'\ud800\udc01'
verify(u'\ud84d\udc56'.encode('utf-8') == \
''.join((chr(0xf0), chr(0xa3), chr(0x91), chr(0x96))) )
# UTF-8 specific decoding tests
-verify(unicode(''.join((chr(0xf0), chr(0xa3), chr(0x91), chr(0x96))),
+verify(unicode(''.join((chr(0xf0), chr(0xa3), chr(0x91), chr(0x96))),
'utf-8') == u'\ud84d\udc56' )
-verify(unicode(''.join((chr(0xf0), chr(0x90), chr(0x80), chr(0x82))),
+verify(unicode(''.join((chr(0xf0), chr(0x90), chr(0x80), chr(0x82))),
'utf-8') == u'\ud800\udc02' )
-verify(unicode(''.join((chr(0xe2), chr(0x82), chr(0xac))),
+verify(unicode(''.join((chr(0xe2), chr(0x82), chr(0xac))),
'utf-8') == u'\u20ac' )
# Other possible utf-8 test cases:
'cp852', 'cp855', 'cp860', 'cp861', 'cp862',
'cp863', 'cp865', 'cp866',
'iso8859_10', 'iso8859_13', 'iso8859_14', 'iso8859_15',
- 'iso8859_2', 'iso8859_4', 'iso8859_5',
+ 'iso8859_2', 'iso8859_4', 'iso8859_5',
'iso8859_9', 'koi8_r', 'latin_1',
'mac_cyrillic', 'mac_latin2',
#'cp1250', 'cp1251', 'cp1252', 'cp1253', 'cp1254', 'cp1255',
#'cp1256', 'cp1257', 'cp1258',
#'cp424', 'cp856', 'cp857', 'cp864', 'cp869', 'cp874',
- #'iso8859_3', 'iso8859_6', 'iso8859_7',
+ #'iso8859_3', 'iso8859_6', 'iso8859_7',
#'mac_greek', 'mac_iceland','mac_roman', 'mac_turkish',
### These fail the round-trip:
from test_support import verbose
class XReader:
- def __init__(self):
- self.count = 5
+ def __init__(self):
+ self.count = 5
- def readlines(self, sizehint = None):
- self.count = self.count - 1
- return map(lambda x: "%d\n" % x, range(self.count))
+ def readlines(self, sizehint = None):
+ self.count = self.count - 1
+ return map(lambda x: "%d\n" % x, range(self.count))
class Null: pass
lineno = 0
try:
- xreadlines.xreadlines(Null())[0]
+ xreadlines.xreadlines(Null())[0]
except AttributeError, detail:
- print "AttributeError (expected)"
+ print "AttributeError (expected)"
else:
- print "Did not throw attribute error"
+ print "Did not throw attribute error"
try:
- xreadlines.xreadlines(XReader)[0]
+ xreadlines.xreadlines(XReader)[0]
except TypeError, detail:
- print "TypeError (expected)"
+ print "TypeError (expected)"
else:
- print "Did not throw type error"
+ print "Did not throw type error"
try:
- xreadlines.xreadlines(XReader())[1]
+ xreadlines.xreadlines(XReader())[1]
except RuntimeError, detail:
- print "RuntimeError (expected):", detail
+ print "RuntimeError (expected):", detail
else:
- print "Did not throw runtime error"
+ print "Did not throw runtime error"
xresult = ['0\n', '1\n', '2\n', '3\n', '0\n', '1\n', '2\n', '0\n', '1\n', '0\n']
for line in xreadlines.xreadlines(XReader()):
- if line != xresult[lineno]:
- print "line %d differs" % lineno
- lineno += 1
+ if line != xresult[lineno]:
+ print "line %d differs" % lineno
+ lineno += 1
def encode(self,input,errors='strict'):
return codecs.charmap_encode(input,errors,encoding_map)
-
+
def decode(self,input,errors='strict'):
return codecs.charmap_decode(input,errors,decoding_map)
class StreamWriter(Codec,codecs.StreamWriter):
pass
-
+
class StreamReader(Codec,codecs.StreamReader):
pass
encoding_map = {}
for k,v in decoding_map.items():
encoding_map[v] = k
-