summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc-André Lemburg <mal@egenix.com>2001-01-17 19:11:13 (GMT)
committerMarc-André Lemburg <mal@egenix.com>2001-01-17 19:11:13 (GMT)
commit3661908a6ac75026e4504d9f62a6ac2e2fb2ec5e (patch)
treeeea0f44df59aaaf014eb4580f1fad308e31601bf
parent8551dd60781f738e5e5ef4e22b6f071d27e20b50 (diff)
downloadcpython-3661908a6ac75026e4504d9f62a6ac2e2fb2ec5e.zip
cpython-3661908a6ac75026e4504d9f62a6ac2e2fb2ec5e.tar.gz
cpython-3661908a6ac75026e4504d9f62a6ac2e2fb2ec5e.tar.bz2
This patch removes all uses of "assert" in the regression test suite
and replaces them with a new API verify(). As a result the regression suite will also perform its tests in optimization mode. Written by Marc-Andre Lemburg. Copyright assigned to Guido van Rossum.
-rwxr-xr-xLib/test/test_al.py2
-rwxr-xr-xLib/test/test_array.py2
-rw-r--r--Lib/test/test_atexit.py2
-rw-r--r--Lib/test/test_audioop.py2
-rw-r--r--Lib/test/test_b2.py2
-rwxr-xr-xLib/test/test_binascii.py8
-rwxr-xr-xLib/test/test_binhex.py2
-rwxr-xr-xLib/test/test_bsddb.py2
-rw-r--r--Lib/test/test_bufio.py2
-rwxr-xr-xLib/test/test_cd.py2
-rw-r--r--Lib/test/test_cgi.py55
-rwxr-xr-xLib/test/test_cl.py2
-rwxr-xr-xLib/test/test_cmath.py2
-rw-r--r--Lib/test/test_compile.py2
-rw-r--r--Lib/test/test_cookie.py14
-rwxr-xr-xLib/test/test_crypt.py2
-rwxr-xr-xLib/test/test_dbm.py2
-rwxr-xr-xLib/test/test_dl.py2
-rwxr-xr-xLib/test/test_errno.py2
-rw-r--r--Lib/test/test_extcall.py7
-rwxr-xr-xLib/test/test_fcntl.py2
-rw-r--r--Lib/test/test_file.py4
-rw-r--r--Lib/test/test_fork1.py9
-rw-r--r--Lib/test/test_format.py2
-rw-r--r--Lib/test/test_gc.py6
-rwxr-xr-xLib/test/test_gdbm.py2
-rw-r--r--Lib/test/test_getopt.py64
-rwxr-xr-xLib/test/test_gl.py2
-rw-r--r--Lib/test/test_grammar.py20
-rwxr-xr-xLib/test/test_grp.py2
-rw-r--r--Lib/test/test_gzip.py6
-rwxr-xr-xLib/test/test_imageop.py2
-rwxr-xr-xLib/test/test_imgfile.py2
-rw-r--r--Lib/test/test_long.py8
-rw-r--r--Lib/test/test_minidom.py2
-rw-r--r--Lib/test/test_mmap.py36
-rw-r--r--Lib/test/test_new.py2
-rw-r--r--Lib/test/test_nis.py2
-rw-r--r--Lib/test/test_openpty.py2
-rw-r--r--Lib/test/test_parser.py2
-rw-r--r--Lib/test/test_pkg.py10
-rw-r--r--Lib/test/test_poll.py10
-rw-r--r--Lib/test/test_pty.py2
-rw-r--r--Lib/test/test_pwd.py2
-rw-r--r--Lib/test/test_re.py150
-rw-r--r--Lib/test/test_regex.py2
-rw-r--r--Lib/test/test_rfc822.py2
-rw-r--r--Lib/test/test_rgbimg.py2
-rw-r--r--Lib/test/test_sax.py2
-rw-r--r--Lib/test/test_select.py2
-rw-r--r--Lib/test/test_signal.py2
-rw-r--r--Lib/test/test_socket.py2
-rw-r--r--Lib/test/test_sre.py2
-rwxr-xr-xLib/test/test_strftime.py2
-rw-r--r--Lib/test/test_string.py2
-rw-r--r--Lib/test/test_strop.py2
-rw-r--r--Lib/test/test_sunaudiodev.py2
-rw-r--r--Lib/test/test_support.py12
-rw-r--r--Lib/test/test_thread.py2
-rw-r--r--Lib/test/test_timing.py2
-rw-r--r--Lib/test/test_tokenize.py2
-rw-r--r--Lib/test/test_ucn.py12
-rw-r--r--Lib/test/test_unicode.py186
-rw-r--r--Lib/test/test_unicodedata.py53
-rw-r--r--Lib/test/test_urllib.py13
-rw-r--r--Lib/test/test_userdict.py41
-rw-r--r--Lib/test/test_userlist.py2
-rwxr-xr-xLib/test/test_userstring.py2
-rw-r--r--Lib/test/test_winreg.py28
-rw-r--r--Lib/test/test_xmllib.py2
70 files changed, 436 insertions, 412 deletions
diff --git a/Lib/test/test_al.py b/Lib/test/test_al.py
index d11c7e5..4f86f39 100755
--- a/Lib/test/test_al.py
+++ b/Lib/test/test_al.py
@@ -3,7 +3,7 @@
Roger E. Masse
"""
import al
-from test_support import verbose
+from test_support import verify, verbose
alattrs = ['__doc__', '__name__', 'getdefault', 'getminmax', 'getname', 'getparams',
'newconfig', 'openport', 'queryparams', 'setparams']
diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py
index 087e65b..a20b870 100755
--- a/Lib/test/test_array.py
+++ b/Lib/test/test_array.py
@@ -3,7 +3,7 @@
Roger E. Masse
"""
import array
-from test_support import verbose, TESTFN, unlink, TestFailed
+from test_support import verify, verbose, TESTFN, unlink, TestFailed
def main():
diff --git a/Lib/test/test_atexit.py b/Lib/test/test_atexit.py
index 517610b..f76f110 100644
--- a/Lib/test/test_atexit.py
+++ b/Lib/test/test_atexit.py
@@ -1,5 +1,5 @@
# Test the exit module
-from test_support import verbose
+from test_support import verify, verbose
import atexit
def handler1():
diff --git a/Lib/test/test_audioop.py b/Lib/test/test_audioop.py
index 495a918..f74242d 100644
--- a/Lib/test/test_audioop.py
+++ b/Lib/test/test_audioop.py
@@ -1,6 +1,6 @@
# Test audioop.
import audioop
-from test_support import verbose
+from test_support import verify, verbose
def gendata1():
return '\0\1\2'
diff --git a/Lib/test/test_b2.py b/Lib/test/test_b2.py
index 9871652..3af5e66 100644
--- a/Lib/test/test_b2.py
+++ b/Lib/test/test_b2.py
@@ -267,7 +267,7 @@ if tuple(xrange(0,10,2)) != tuple(range(0,10,2)):
raise TestFailed, 'xrange(0,10,2)'
# regression tests for SourceForge bug #121695
def _range_test(r):
- assert r.start != r.stop, 'Test not valid for passed-in xrange object.'
+ verify(r.start != r.stop, 'Test not valid for passed-in xrange object.')
if r.stop in r:
raise TestFailed, 'r.stop in ' + `r`
if r.stop-r.step not in r:
diff --git a/Lib/test/test_binascii.py b/Lib/test/test_binascii.py
index 20f5400..f03fc55 100755
--- a/Lib/test/test_binascii.py
+++ b/Lib/test/test_binascii.py
@@ -1,6 +1,6 @@
"""Test the binascii C module."""
-from test_support import verbose
+from test_support import verify, verbose
import binascii
# Show module doc string
@@ -42,7 +42,7 @@ res = ""
for line in lines:
b = binascii.a2b_base64(line)
res = res + b
-assert res == testdata
+verify(res == testdata)
# Test base64 with random invalid characters sprinkled throughout
# (This requires a new version of binascii.)
@@ -67,7 +67,7 @@ res = ""
for line in map(addnoise, lines):
b = binascii.a2b_base64(line)
res = res + b
-assert res == testdata
+verify(res == testdata)
# Test uu
print "uu test"
@@ -82,7 +82,7 @@ res = ""
for line in lines:
b = binascii.a2b_uu(line)
res = res + b
-assert res == testdata
+verify(res == testdata)
# Test crc32()
crc = binascii.crc32("Test the CRC-32 of")
diff --git a/Lib/test/test_binhex.py b/Lib/test/test_binhex.py
index a2b2a2c..4cee4fb 100755
--- a/Lib/test/test_binhex.py
+++ b/Lib/test/test_binhex.py
@@ -6,7 +6,7 @@
"""
import binhex
import tempfile
-from test_support import verbose, TestSkipped
+from test_support import verify, verbose, TestSkipped
def test():
diff --git a/Lib/test/test_bsddb.py b/Lib/test/test_bsddb.py
index b59a4e0..e559b20 100755
--- a/Lib/test/test_bsddb.py
+++ b/Lib/test/test_bsddb.py
@@ -6,7 +6,7 @@
import os
import bsddb
import tempfile
-from test_support import verbose
+from test_support import verify, verbose
def test(openmethod, what):
diff --git a/Lib/test/test_bufio.py b/Lib/test/test_bufio.py
index 168a6b2..fb8fe10 100644
--- a/Lib/test/test_bufio.py
+++ b/Lib/test/test_bufio.py
@@ -13,7 +13,7 @@ from test_support import TestFailed, TESTFN
def drive_one(pattern, length):
q, r = divmod(length, len(pattern))
teststring = pattern * q + pattern[:r]
- assert len(teststring) == length
+ verify(len(teststring) == length)
try_one(teststring)
try_one(teststring + "x")
try_one(teststring[:-1])
diff --git a/Lib/test/test_cd.py b/Lib/test/test_cd.py
index 9a45a7d..7af2e0b 100755
--- a/Lib/test/test_cd.py
+++ b/Lib/test/test_cd.py
@@ -3,7 +3,7 @@
Roger E. Masse
"""
import cd
-from test_support import verbose
+from test_support import verify, verbose
cdattrs = ['BLOCKSIZE', 'CDROM', 'DATASIZE', 'ERROR', 'NODISC', 'PAUSED', 'PLAYING', 'READY',
'STILL', '__doc__', '__name__', 'atime', 'audio', 'catalog', 'control', 'createparser', 'error',
diff --git a/Lib/test/test_cgi.py b/Lib/test/test_cgi.py
index 71e275f..b1f5758 100644
--- a/Lib/test/test_cgi.py
+++ b/Lib/test/test_cgi.py
@@ -1,3 +1,4 @@
+from test_support import verify, verbose
import cgi
import os
import sys
@@ -117,9 +118,9 @@ def main():
# Test basic parsing
print repr(orig)
d = do_test(orig, "GET")
- assert d == expect, "Error parsing %s" % repr(orig)
+ verify(d == expect, "Error parsing %s" % repr(orig))
d = do_test(orig, "POST")
- assert d == expect, "Error parsing %s" % repr(orig)
+ verify(d == expect, "Error parsing %s" % repr(orig))
env = {'QUERY_STRING': orig}
fcd = cgi.FormContentDict(env)
@@ -127,21 +128,21 @@ def main():
fs = cgi.FieldStorage(environ=env)
if type(expect) == type({}):
# test dict interface
- assert len(expect) == len(fcd)
- assert norm(expect.keys()) == norm(fcd.keys())
- assert norm(expect.values()) == norm(fcd.values())
- assert norm(expect.items()) == norm(fcd.items())
- assert fcd.get("nonexistent field", "default") == "default"
- assert len(sd) == len(fs)
- assert norm(sd.keys()) == norm(fs.keys())
- assert fs.getvalue("nonexistent field", "default") == "default"
+ verify(len(expect) == len(fcd))
+ verify(norm(expect.keys()) == norm(fcd.keys()))
+ verify(norm(expect.values()) == norm(fcd.values()))
+ verify(norm(expect.items()) == norm(fcd.items()))
+ verify(fcd.get("nonexistent field", "default") == "default")
+ verify(len(sd) == len(fs))
+ verify(norm(sd.keys()) == norm(fs.keys()))
+ verify(fs.getvalue("nonexistent field", "default") == "default")
# test individual fields
for key in expect.keys():
expect_val = expect[key]
- assert fcd.has_key(key)
- assert norm(fcd[key]) == norm(expect[key])
- assert fcd.get(key, "default") == fcd[key]
- assert fs.has_key(key)
+ verify(fcd.has_key(key))
+ verify(norm(fcd[key]) == norm(expect[key]))
+ verify(fcd.get(key, "default") == fcd[key])
+ verify(fs.has_key(key))
if len(expect_val) > 1:
single_value = 0
else:
@@ -149,28 +150,28 @@ def main():
try:
val = sd[key]
except IndexError:
- assert not single_value
- assert fs.getvalue(key) == expect_val
+ verify(not single_value)
+ verify(fs.getvalue(key) == expect_val)
else:
- assert single_value
- assert val == expect_val[0]
- assert fs.getvalue(key) == expect_val[0]
- assert norm(sd.getlist(key)) == norm(expect_val)
+ verify(single_value)
+ verify(val == expect_val[0])
+ verify(fs.getvalue(key) == expect_val[0])
+ verify(norm(sd.getlist(key)) == norm(expect_val))
if single_value:
- assert norm(sd.values()) == \
- first_elts(norm(expect.values()))
- assert norm(sd.items()) == \
- first_second_elts(norm(expect.items()))
+ verify(norm(sd.values()) == \
+ first_elts(norm(expect.values())))
+ verify(norm(sd.items()) == \
+ first_second_elts(norm(expect.items())))
# Test the weird FormContentDict classes
env = {'QUERY_STRING': "x=1&y=2.0&z=2-3.%2b0&1=1abc"}
expect = {'x': 1, 'y': 2.0, 'z': '2-3.+0', '1': '1abc'}
d = cgi.InterpFormContentDict(env)
for k, v in expect.items():
- assert d[k] == v
+ verify(d[k] == v)
for k, v in d.items():
- assert expect[k] == v
- assert norm(expect.values()) == norm(d.values())
+ verify(expect[k] == v)
+ verify(norm(expect.values()) == norm(d.values()))
print "Testing log"
cgi.initlog()
diff --git a/Lib/test/test_cl.py b/Lib/test/test_cl.py
index 26c5146..f8112eb 100755
--- a/Lib/test/test_cl.py
+++ b/Lib/test/test_cl.py
@@ -3,7 +3,7 @@
Roger E. Masse
"""
import cl
-from test_support import verbose
+from test_support import verify, verbose
clattrs = ['ADDED_ALGORITHM_ERROR', 'ALAW', 'ALGORITHM_ID',
'ALGORITHM_VERSION', 'AUDIO', 'AWARE_ERROR', 'AWARE_MPEG_AUDIO',
diff --git a/Lib/test/test_cmath.py b/Lib/test/test_cmath.py
index 509c739..9caa216 100755
--- a/Lib/test/test_cmath.py
+++ b/Lib/test/test_cmath.py
@@ -3,7 +3,7 @@
Roger E. Masse
"""
import cmath
-from test_support import verbose
+from test_support import verify, verbose
testdict = {'acos' : 1.0,
'acosh' : 1.0,
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index 8905864..fa608b1 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -1,4 +1,4 @@
-from test_support import verbose, TestFailed
+from test_support import verify, verbose, TestFailed
if verbose:
print 'Running test on duplicate arguments'
diff --git a/Lib/test/test_cookie.py b/Lib/test/test_cookie.py
index bf3e9af..8dd0f6f 100644
--- a/Lib/test/test_cookie.py
+++ b/Lib/test/test_cookie.py
@@ -16,15 +16,15 @@ for data, dict in cases:
print str(C)
for k, v in dict.items():
print ' ', k, repr( C[k].value ), repr(v)
- assert C[k].value == v
+ verify(C[k].value == v)
print C[k]
C = Cookie.SimpleCookie()
C.load('Customer="WILE_E_COYOTE"; Version=1; Path=/acme')
-assert C['Customer'].value == 'WILE_E_COYOTE'
-assert C['Customer']['version'] == '1'
-assert C['Customer']['path'] == '/acme'
+verify(C['Customer'].value == 'WILE_E_COYOTE')
+verify(C['Customer']['version'] == '1')
+verify(C['Customer']['path'] == '/acme')
print C.output(['path'])
print C.js_output()
@@ -33,6 +33,6 @@ print C.js_output(['path'])
# Try cookie with quoted meta-data
C = Cookie.SimpleCookie()
C.load('Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"')
-assert C['Customer'].value == 'WILE_E_COYOTE'
-assert C['Customer']['version'] == '1'
-assert C['Customer']['path'] == '/acme'
+verify(C['Customer'].value == 'WILE_E_COYOTE')
+verify(C['Customer']['version'] == '1')
+verify(C['Customer']['path'] == '/acme')
diff --git a/Lib/test/test_crypt.py b/Lib/test/test_crypt.py
index 9fb93dd..442040f 100755
--- a/Lib/test/test_crypt.py
+++ b/Lib/test/test_crypt.py
@@ -3,7 +3,7 @@
Roger E. Masse
"""
-from test_support import verbose
+from test_support import verify, verbose
import crypt
c = crypt.crypt('mypassword', 'ab')
diff --git a/Lib/test/test_dbm.py b/Lib/test/test_dbm.py
index 94949cf..6510125 100755
--- a/Lib/test/test_dbm.py
+++ b/Lib/test/test_dbm.py
@@ -4,7 +4,7 @@
"""
import dbm
from dbm import error
-from test_support import verbose
+from test_support import verify, verbose
filename = '/tmp/delete_me'
diff --git a/Lib/test/test_dl.py b/Lib/test/test_dl.py
index 60a5cf0..c5b3bb4 100755
--- a/Lib/test/test_dl.py
+++ b/Lib/test/test_dl.py
@@ -4,7 +4,7 @@
"""
import dl
-from test_support import verbose,TestSkipped
+from test_support import verify, verbose,TestSkipped
sharedlibs = [
('/usr/lib/libc.so', 'getpid'),
diff --git a/Lib/test/test_errno.py b/Lib/test/test_errno.py
index cb1e729..2fb6b34 100755
--- a/Lib/test/test_errno.py
+++ b/Lib/test/test_errno.py
@@ -4,7 +4,7 @@
"""
import errno
-from test_support import verbose
+from test_support import verify, verbose
errors = ['E2BIG', 'EACCES', 'EADDRINUSE', 'EADDRNOTAVAIL', 'EADV',
'EAFNOSUPPORT', 'EAGAIN', 'EALREADY', 'EBADE', 'EBADF',
diff --git a/Lib/test/test_extcall.py b/Lib/test/test_extcall.py
index b53ced7..5b6c5ec 100644
--- a/Lib/test/test_extcall.py
+++ b/Lib/test/test_extcall.py
@@ -1,3 +1,4 @@
+from test_support import verify, verbose
from UserList import UserList
from test_support import TestFailed
import string
@@ -79,11 +80,11 @@ g(*Nothing())
# make sure the function call doesn't stomp on the dictionary?
d = {'a': 1, 'b': 2, 'c': 3}
d2 = d.copy()
-assert d == d2
+verify(d == d2)
g(1, d=4, **d)
print d
print d2
-assert d == d2, "function call modified dictionary"
+verify(d == d2, "function call modified dictionary")
# what about willful misconduct?
def saboteur(**kw):
@@ -91,7 +92,7 @@ def saboteur(**kw):
return kw
d = {}
kw = saboteur(a=1, **d)
-assert d == {}
+verify(d == {})
# break the cycle
del kw['x']
diff --git a/Lib/test/test_fcntl.py b/Lib/test/test_fcntl.py
index b6d4dfa..a598a41 100755
--- a/Lib/test/test_fcntl.py
+++ b/Lib/test/test_fcntl.py
@@ -6,7 +6,7 @@ import struct
import fcntl
import FCNTL
import os, sys
-from test_support import verbose, TESTFN
+from test_support import verify, verbose, TESTFN
filename = TESTFN
diff --git a/Lib/test/test_file.py b/Lib/test/test_file.py
index d73167a..a85e07c 100644
--- a/Lib/test/test_file.py
+++ b/Lib/test/test_file.py
@@ -1,6 +1,6 @@
import os
-from test_support import TESTFN
+from test_support import verify, TESTFN
from UserList import UserList
# verify writelines with instance sequence
@@ -11,7 +11,7 @@ f.close()
f = open(TESTFN, 'rb')
buf = f.read()
f.close()
-assert buf == '12'
+verify(buf == '12')
# verify writelines with integers
f = open(TESTFN, 'wb')
diff --git a/Lib/test/test_fork1.py b/Lib/test/test_fork1.py
index 4fd2662..bd3e977 100644
--- a/Lib/test/test_fork1.py
+++ b/Lib/test/test_fork1.py
@@ -12,7 +12,7 @@ That's OK, fork() is a grotesque hack anyway. ;-) [cjh]
"""
import os, sys, time, thread
-from test_support import TestSkipped
+from test_support import verify, verbose, TestSkipped
try:
if os.uname()[0] == "BeOS":
@@ -51,7 +51,7 @@ def main():
a = alive.keys()
a.sort()
- assert a == range(NUM_THREADS)
+ verify(a == range(NUM_THREADS))
prefork_lives = alive.copy()
@@ -68,8 +68,9 @@ def main():
else:
# Parent
spid, status = os.waitpid(cpid, 0)
- assert spid == cpid
- assert status == 0, "cause = %d, exit = %d" % (status&0xff, status>>8)
+ verify(spid == cpid)
+ verify(status == 0,
+ "cause = %d, exit = %d" % (status&0xff, status>>8) )
global stop
# Tell threads to die
stop = 1
diff --git a/Lib/test/test_format.py b/Lib/test/test_format.py
index f11eb54..a85c9f5 100644
--- a/Lib/test/test_format.py
+++ b/Lib/test/test_format.py
@@ -1,4 +1,4 @@
-from test_support import verbose
+from test_support import verify, verbose
import string, sys
# test string formatting operator (I am not sure if this is being tested
diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py
index f4714d5..1c008be 100644
--- a/Lib/test/test_gc.py
+++ b/Lib/test/test_gc.py
@@ -1,4 +1,4 @@
-from test_support import verbose, TestFailed
+from test_support import verify, verbose, TestFailed
import gc
def run_test(name, thunk):
@@ -161,7 +161,7 @@ def test():
print "disabling automatic collection"
enabled = gc.isenabled()
gc.disable()
- assert not gc.isenabled()
+ verify(not gc.isenabled() )
debug = gc.get_debug()
gc.set_debug(debug & ~gc.DEBUG_LEAK) # this test is supposed to leak
@@ -174,7 +174,7 @@ def test():
print "restoring automatic collection"
# make sure to always test gc.enable()
gc.enable()
- assert gc.isenabled()
+ verify(gc.isenabled())
if not enabled:
gc.disable()
diff --git a/Lib/test/test_gdbm.py b/Lib/test/test_gdbm.py
index 67c67eb..dfd05b7 100755
--- a/Lib/test/test_gdbm.py
+++ b/Lib/test/test_gdbm.py
@@ -5,7 +5,7 @@
import gdbm
from gdbm import error
-from test_support import verbose, TestFailed
+from test_support import verify, verbose, TestFailed
filename= '/tmp/delete_me'
diff --git a/Lib/test/test_getopt.py b/Lib/test/test_getopt.py
index 1460200..f8989f1 100644
--- a/Lib/test/test_getopt.py
+++ b/Lib/test/test_getopt.py
@@ -3,7 +3,7 @@
import getopt
from getopt import GetoptError
-from test_support import verbose
+from test_support import verify, verbose
def expectException(teststr, expected, failure=AssertionError):
"""Executes a statement passed in teststr, and raises an exception
@@ -17,22 +17,22 @@ def expectException(teststr, expected, failure=AssertionError):
if verbose:
print 'Running tests on getopt.short_has_arg'
-assert getopt.short_has_arg('a', 'a:')
-assert not getopt.short_has_arg('a', 'a')
+verify(getopt.short_has_arg('a', 'a:'))
+verify(not getopt.short_has_arg('a', 'a'))
expectException("tmp = getopt.short_has_arg('a', 'b')", GetoptError)
expectException("tmp = getopt.short_has_arg('a', '')", GetoptError)
if verbose:
print 'Running tests on getopt.long_has_args'
has_arg, option = getopt.long_has_args('abc', ['abc='])
-assert has_arg
-assert option == 'abc'
+verify(has_arg)
+verify(option == 'abc')
has_arg, option = getopt.long_has_args('abc', ['abc'])
-assert not has_arg
-assert option == 'abc'
+verify(not has_arg)
+verify(option == 'abc')
has_arg, option = getopt.long_has_args('abc', ['abcd'])
-assert not has_arg
-assert option == 'abcd'
+verify(not has_arg)
+verify(option == 'abcd')
expectException("has_arg, option = getopt.long_has_args('abc', ['def'])",
GetoptError)
expectException("has_arg, option = getopt.long_has_args('abc', [])",
@@ -44,20 +44,20 @@ expectException("has_arg, option = " + \
if verbose:
print 'Running tests on getopt.do_shorts'
opts, args = getopt.do_shorts([], 'a', 'a', [])
-assert opts == [('-a', '')]
-assert args == []
+verify(opts == [('-a', '')])
+verify(args == [])
opts, args = getopt.do_shorts([], 'a1', 'a:', [])
-assert opts == [('-a', '1')]
-assert args == []
+verify(opts == [('-a', '1')])
+verify(args == [])
#opts, args = getopt.do_shorts([], 'a=1', 'a:', [])
-#assert opts == [('-a', '1')]
-#assert args == []
+#verify(opts == [('-a', '1')])
+#verify(args == [])
opts, args = getopt.do_shorts([], 'a', 'a:', ['1'])
-assert opts == [('-a', '1')]
-assert args == []
+verify(opts == [('-a', '1')])
+verify(args == [])
opts, args = getopt.do_shorts([], 'a', 'a:', ['1', '2'])
-assert opts == [('-a', '1')]
-assert args == ['2']
+verify(opts == [('-a', '1')])
+verify(args == ['2'])
expectException("opts, args = getopt.do_shorts([], 'a1', 'a', [])",
GetoptError)
expectException("opts, args = getopt.do_shorts([], 'a', 'a:', [])",
@@ -66,23 +66,23 @@ expectException("opts, args = getopt.do_shorts([], 'a', 'a:', [])",
if verbose:
print 'Running tests on getopt.do_longs'
opts, args = getopt.do_longs([], 'abc', ['abc'], [])
-assert opts == [('--abc', '')]
-assert args == []
+verify(opts == [('--abc', '')])
+verify(args == [])
opts, args = getopt.do_longs([], 'abc=1', ['abc='], [])
-assert opts == [('--abc', '1')]
-assert args == []
+verify(opts == [('--abc', '1')])
+verify(args == [])
opts, args = getopt.do_longs([], 'abc=1', ['abcd='], [])
-assert opts == [('--abcd', '1')]
-assert args == []
+verify(opts == [('--abcd', '1')])
+verify(args == [])
opts, args = getopt.do_longs([], 'abc', ['ab', 'abc', 'abcd'], [])
-assert opts == [('--abc', '')]
-assert args == []
+verify(opts == [('--abc', '')])
+verify(args == [])
# Much like the preceding, except with a non-alpha character ("-") in
# option name that precedes "="; failed in
# http://sourceforge.net/bugs/?func=detailbug&bug_id=126863&group_id=5470
opts, args = getopt.do_longs([], 'foo=42', ['foo-bar', 'foo=',], [])
-assert opts == [('--foo', '42')]
-assert args == []
+verify(opts == [('--foo', '42')])
+verify(args == [])
expectException("opts, args = getopt.do_longs([], 'abc=1', ['abc'], [])",
GetoptError)
expectException("opts, args = getopt.do_longs([], 'abc', ['abc='], [])",
@@ -96,11 +96,11 @@ cmdline = ['-a', '1', '-b', '--alpha=2', '--beta', '-a', '3', '-a', '',
if verbose:
print 'Running tests on getopt.getopt'
opts, args = getopt.getopt(cmdline, 'a:b', ['alpha=', 'beta'])
-assert opts == [('-a', '1'), ('-b', ''), ('--alpha', '2'), ('--beta', ''),
- ('-a', '3'), ('-a', ''), ('--beta', '')]
+verify(opts == [('-a', '1'), ('-b', ''), ('--alpha', '2'), ('--beta', ''),
+ ('-a', '3'), ('-a', ''), ('--beta', '')] )
# Note ambiguity of ('-b', '') and ('-a', '') above. This must be
# accounted for in the code that calls getopt().
-assert args == ['arg1', 'arg2']
+verify(args == ['arg1', 'arg2'])
expectException(
"opts, args = getopt.getopt(cmdline, 'a:b', ['alpha', 'beta'])",
diff --git a/Lib/test/test_gl.py b/Lib/test/test_gl.py
index 61eaa83..72b0895 100755
--- a/Lib/test/test_gl.py
+++ b/Lib/test/test_gl.py
@@ -3,7 +3,7 @@
taken mostly from the documentation.
Roger E. Masse
"""
-from test_support import verbose, TestSkipped
+from test_support import verify, verbose, TestSkipped
import gl, GL, time
glattrs = ['RGBcolor', 'RGBcursor', 'RGBmode', 'RGBrange', 'RGBwritemask',
diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py
index b990c83..503cc80 100644
--- a/Lib/test/test_grammar.py
+++ b/Lib/test/test_grammar.py
@@ -83,18 +83,18 @@ x = 3.1e4
print '1.1.3 String literals'
-##def assert(s):
+##def verify(s):
## if not s: raise TestFailed, 'see traceback'
-x = ''; y = ""; assert(len(x) == 0 and x == y)
-x = '\''; y = "'"; assert(len(x) == 1 and x == y and ord(x) == 39)
-x = '"'; y = "\""; assert(len(x) == 1 and x == y and ord(x) == 34)
+x = ''; y = ""; verify(len(x) == 0 and x == y)
+x = '\''; y = "'"; verify(len(x) == 1 and x == y and ord(x) == 39)
+x = '"'; y = "\""; verify(len(x) == 1 and x == y and ord(x) == 34)
x = "doesn't \"shrink\" does it"
y = 'doesn\'t "shrink" does it'
-assert(len(x) == 24 and x == y)
+verify(len(x) == 24 and x == y)
x = "does \"shrink\" doesn't it"
y = 'does "shrink" doesn\'t it'
-assert(len(x) == 24 and x == y)
+verify(len(x) == 24 and x == y)
x = """
The "quick"
brown fox
@@ -102,25 +102,25 @@ jumps over
the 'lazy' dog.
"""
y = '\nThe "quick"\nbrown fox\njumps over\nthe \'lazy\' dog.\n'
-assert(x == y)
+verify(x == y)
y = '''
The "quick"
brown fox
jumps over
the 'lazy' dog.
-'''; assert(x == y)
+'''; verify(x == y)
y = "\n\
The \"quick\"\n\
brown fox\n\
jumps over\n\
the 'lazy' dog.\n\
-"; assert(x == y)
+"; verify(x == y)
y = '\n\
The \"quick\"\n\
brown fox\n\
jumps over\n\
the \'lazy\' dog.\n\
-'; assert(x == y)
+'; verify(x == y)
print '1.2 Grammar'
diff --git a/Lib/test/test_grp.py b/Lib/test/test_grp.py
index b737da9..eda39d5 100755
--- a/Lib/test/test_grp.py
+++ b/Lib/test/test_grp.py
@@ -4,7 +4,7 @@
"""
import grp
-from test_support import verbose
+from test_support import verify, verbose
groups = grp.getgrall()
if verbose:
diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py
index 7edc617..8191267 100644
--- a/Lib/test/test_gzip.py
+++ b/Lib/test/test_gzip.py
@@ -18,13 +18,13 @@ data2 = """/* zlibmodule.c -- gzip-compatible data compression */
f = gzip.GzipFile(filename, 'wb') ; f.write(data1 * 50) ; f.close()
f = gzip.GzipFile(filename, 'rb') ; d = f.read() ; f.close()
-assert d == data1*50
+verify(d == data1*50)
# Append to the previous file
f = gzip.GzipFile(filename, 'ab') ; f.write(data2 * 15) ; f.close()
f = gzip.GzipFile(filename, 'rb') ; d = f.read() ; f.close()
-assert d == (data1*50) + (data2*15)
+verify(d == (data1*50) + (data2*15))
# Try .readline() with varying line lengths
@@ -33,7 +33,7 @@ line_length = 0
while 1:
L = f.readline( line_length )
if L == "" and line_length != 0: break
- assert len(L) <= line_length
+ verify(len(L) <= line_length)
line_length = (line_length + 1) % 50
f.close()
diff --git a/Lib/test/test_imageop.py b/Lib/test/test_imageop.py
index 7a6981e..3a63e3c 100755
--- a/Lib/test/test_imageop.py
+++ b/Lib/test/test_imageop.py
@@ -5,7 +5,7 @@
Roger E. Masse
"""
-from test_support import verbose, unlink
+from test_support import verify, verbose, unlink
import imageop, uu
diff --git a/Lib/test/test_imgfile.py b/Lib/test/test_imgfile.py
index 8eb330d..5606bb0 100755
--- a/Lib/test/test_imgfile.py
+++ b/Lib/test/test_imgfile.py
@@ -4,7 +4,7 @@
Roger E. Masse
"""
-from test_support import verbose, unlink, findfile
+from test_support import verify, verbose, unlink, findfile
import imgfile, uu, os
diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py
index 5e0e001..1059ef6 100644
--- a/Lib/test/test_long.py
+++ b/Lib/test/test_long.py
@@ -1,4 +1,4 @@
-from test_support import TestFailed, verbose
+from test_support import verify, verbose, TestFailed
from string import join
from random import random, randint
@@ -41,7 +41,7 @@ def check(ok, *args):
# The sign of the number is also random.
def getran(ndigits):
- assert ndigits > 0
+ verify(ndigits > 0)
nbits_hi = ndigits * SHIFT
nbits_lo = nbits_hi - SHIFT + 1
answer = 0L
@@ -50,13 +50,13 @@ def getran(ndigits):
while nbits < nbits_lo:
bits = (r >> 1) + 1
bits = min(bits, nbits_hi - nbits)
- assert 1 <= bits <= SHIFT
+ verify(1 <= bits <= SHIFT)
nbits = nbits + bits
answer = answer << bits
if r & 1:
answer = answer | ((1 << bits) - 1)
r = int(random() * (SHIFT * 2))
- assert nbits_lo <= nbits <= nbits_hi
+ verify(nbits_lo <= nbits <= nbits_hi)
if random() < 0.5:
answer = -answer
return answer
diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py
index ee105c2..72f3e40 100644
--- a/Lib/test/test_minidom.py
+++ b/Lib/test/test_minidom.py
@@ -7,7 +7,7 @@ import xml.parsers.expat
import os.path
import sys
import traceback
-from test_support import verbose
+from test_support import verify, verbose
if __name__ == "__main__":
base = sys.argv[0]
diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py
index 7c49cf2..4673913 100644
--- a/Lib/test/test_mmap.py
+++ b/Lib/test/test_mmap.py
@@ -1,3 +1,4 @@
+from test_support import verify
import mmap
import string, os, re, sys
@@ -21,15 +22,15 @@ def test_both():
print type(m) # SF bug 128713: segfaulted on Linux
print ' Position of foo:', string.find(m, 'foo') / float(PAGESIZE), 'pages'
- assert string.find(m, 'foo') == PAGESIZE
+ verify(string.find(m, 'foo') == PAGESIZE)
print ' Length of file:', len(m) / float(PAGESIZE), 'pages'
- assert len(m) == 2*PAGESIZE
+ verify(len(m) == 2*PAGESIZE)
print ' Contents of byte 0:', repr(m[0])
- assert m[0] == '\0'
+ verify(m[0] == '\0')
print ' Contents of first 3 bytes:', repr(m[0:3])
- assert m[0:3] == '\0\0\0'
+ verify(m[0:3] == '\0\0\0')
# Modify the file's content
print "\n Modifying file's content..."
@@ -38,11 +39,11 @@ def test_both():
# Check that the modification worked
print ' Contents of byte 0:', repr(m[0])
- assert m[0] == '3'
+ verify(m[0] == '3')
print ' Contents of first 3 bytes:', repr(m[0:3])
- assert m[0:3] == '3\0\0'
+ verify(m[0:3] == '3\0\0')
print ' Contents of second page:', repr(m[PAGESIZE-1 : PAGESIZE + 7])
- assert m[PAGESIZE-1 : PAGESIZE + 7] == '\0foobar\0'
+ verify(m[PAGESIZE-1 : PAGESIZE + 7] == '\0foobar\0')
m.flush()
@@ -57,19 +58,19 @@ def test_both():
print ' Regex match on mmap (page start, length of match):',
print start / float(PAGESIZE), length
- assert start == PAGESIZE
- assert end == PAGESIZE + 6
+ verify(start == PAGESIZE)
+ verify(end == PAGESIZE + 6)
# test seeking around (try to overflow the seek implementation)
m.seek(0,0)
print ' Seek to zeroth byte'
- assert m.tell() == 0
+ verify(m.tell() == 0)
m.seek(42,1)
print ' Seek to 42nd byte'
- assert m.tell() == 42
+ verify(m.tell() == 42)
m.seek(0,2)
print ' Seek to last byte'
- assert m.tell() == len(m)
+ verify(m.tell() == len(m))
print ' Try to seek to negative position...'
try:
@@ -77,7 +78,7 @@ def test_both():
except ValueError:
pass
else:
- assert 0, 'expected a ValueError but did not get it'
+ verify(0, 'expected a ValueError but did not get it')
print ' Try to seek beyond end of mmap...'
try:
@@ -85,7 +86,7 @@ def test_both():
except ValueError:
pass
else:
- assert 0, 'expected a ValueError but did not get it'
+ verify(0, 'expected a ValueError but did not get it')
print ' Try to seek to negative position...'
try:
@@ -93,7 +94,7 @@ def test_both():
except ValueError:
pass
else:
- assert 0, 'expected a ValueError but did not get it'
+ verify(0, 'expected a ValueError but did not get it')
# Try resizing map
print ' Attempting resize()'
@@ -106,14 +107,15 @@ def test_both():
pass
else:
# resize() is supported
- assert len(m) == 512, "len(m) is %d, but expecting 512" % (len(m),)
+ verify(len(m) == 512,
+ "len(m) is %d, but expecting 512" % (len(m),) )
# Check that we can no longer seek beyond the new size.
try:
m.seek(513,0)
except ValueError:
pass
else:
- assert 0, 'Could seek beyond the new size'
+ verify(0, 'Could seek beyond the new size')
m.close()
os.unlink("foo")
diff --git a/Lib/test/test_new.py b/Lib/test/test_new.py
index 70ea38b..929155c 100644
--- a/Lib/test/test_new.py
+++ b/Lib/test/test_new.py
@@ -1,4 +1,4 @@
-from test_support import verbose
+from test_support import verify, verbose
import sys
import new
diff --git a/Lib/test/test_nis.py b/Lib/test/test_nis.py
index e1670d1..56382c5 100644
--- a/Lib/test/test_nis.py
+++ b/Lib/test/test_nis.py
@@ -1,4 +1,4 @@
-from test_support import verbose, TestFailed, TestSkipped
+from test_support import verify, verbose, TestFailed, TestSkipped
import nis
print 'nis.maps()'
diff --git a/Lib/test/test_openpty.py b/Lib/test/test_openpty.py
index fb81719..cd0191f 100644
--- a/Lib/test/test_openpty.py
+++ b/Lib/test/test_openpty.py
@@ -1,7 +1,7 @@
# Test to see if openpty works. (But don't worry if it isn't available.)
import os
-from test_support import verbose, TestFailed, TestSkipped
+from test_support import verify, verbose, TestFailed, TestSkipped
try:
if verbose:
diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py
index 6885767..891855a 100644
--- a/Lib/test/test_parser.py
+++ b/Lib/test/test_parser.py
@@ -3,7 +3,7 @@ import parser
import pprint
import sys
-from test_support import TestFailed
+from test_support import verify, TestFailed
#
# First, we test that we can generate trees from valid source fragments,
diff --git a/Lib/test/test_pkg.py b/Lib/test/test_pkg.py
index 5456100..80a11d8 100644
--- a/Lib/test/test_pkg.py
+++ b/Lib/test/test_pkg.py
@@ -3,7 +3,7 @@
import sys, os, string, tempfile, traceback
from os import mkdir, rmdir # Can't test if these fail
del mkdir, rmdir
-from test_support import verbose, TestFailed
+from test_support import verify, verbose, TestFailed
# Helpers to create and destroy hierarchies.
@@ -188,16 +188,16 @@ print dir()
t7, sub, subsub = None, None, None
import t7 as tas
print dir(tas)
-assert not t7
+verify(not t7)
from t7 import sub as subpar
print dir(subpar)
-assert not t7 and not sub
+verify(not t7 and not sub)
from t7.sub import subsub as subsubsub
print dir(subsubsub)
-assert not t7 and not sub and not subsub
+verify(not t7 and not sub and not subsub)
from t7.sub.subsub import spam as ham
print "t7.sub.subsub.spam =", ham
-assert not t7 and not sub and not subsub
+verify(not t7 and not sub and not subsub)
"""),
]
diff --git a/Lib/test/test_poll.py b/Lib/test/test_poll.py
index 576e4cc..f6d427c 100644
--- a/Lib/test/test_poll.py
+++ b/Lib/test/test_poll.py
@@ -1,7 +1,7 @@
# Test case for the os.poll() function
import sys, os, select, random
-from test_support import verbose, TestSkipped, TESTFN
+from test_support import verify, verbose, TestSkipped, TESTFN
try:
select.poll
@@ -55,7 +55,7 @@ def test_poll1():
raise RuntimeError, "no pipes ready for reading"
rd = random.choice(ready_readers)
buf = os.read(rd, MSG_LEN)
- assert len(buf) == MSG_LEN
+ verify(len(buf) == MSG_LEN)
print buf
os.close(r2w[rd]) ; os.close( rd )
p.unregister( r2w[rd] )
@@ -75,17 +75,17 @@ def poll_unit_tests():
p = select.poll()
p.register(FD)
r = p.poll()
- assert r[0] == (FD, select.POLLNVAL)
+ verify(r[0] == (FD, select.POLLNVAL))
f = open(TESTFN, 'w')
fd = f.fileno()
p = select.poll()
p.register(f)
r = p.poll()
- assert r[0][0] == fd
+ verify(r[0][0] == fd)
f.close()
r = p.poll()
- assert r[0] == (fd, select.POLLNVAL)
+ verify(r[0] == (fd, select.POLLNVAL))
os.unlink(TESTFN)
# type error for invalid arguments
diff --git a/Lib/test/test_pty.py b/Lib/test/test_pty.py
index 5ea7e6f..0354312 100644
--- a/Lib/test/test_pty.py
+++ b/Lib/test/test_pty.py
@@ -1,5 +1,5 @@
import pty, os, sys, string
-from test_support import verbose, TestFailed, TestSkipped
+from test_support import verify, verbose, TestFailed, TestSkipped
TEST_STRING_1 = "I wish to buy a fish license."
TEST_STRING_2 = "For my pet fish, Eric."
diff --git a/Lib/test/test_pwd.py b/Lib/test/test_pwd.py
index 7425f53..d179ed0 100644
--- a/Lib/test/test_pwd.py
+++ b/Lib/test/test_pwd.py
@@ -1,4 +1,4 @@
-from test_support import verbose
+from test_support import verify, verbose
import pwd
import string
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index 4d52c14..8ab6c7f 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -1,7 +1,7 @@
import sys
sys.path = ['.'] + sys.path
-from test_support import verbose, TestFailed
+from test_support import verify, verbose, TestFailed
import re
import sys, os, string, traceback
@@ -11,20 +11,20 @@ if verbose:
print 'Running tests on re.search and re.match'
try:
- assert re.search('x*', 'axx').span(0) == (0, 0)
- assert re.search('x*', 'axx').span() == (0, 0)
- assert re.search('x+', 'axx').span(0) == (1, 3)
- assert re.search('x+', 'axx').span() == (1, 3)
- assert re.search('x', 'aaa') is None
+ verify(re.search('x*', 'axx').span(0) == (0, 0))
+ verify(re.search('x*', 'axx').span() == (0, 0))
+ verify(re.search('x+', 'axx').span(0) == (1, 3))
+ verify(re.search('x+', 'axx').span() == (1, 3))
+ verify(re.search('x', 'aaa') is None)
except:
raise TestFailed, "re.search"
try:
- assert re.match('a*', 'xxx').span(0) == (0, 0)
- assert re.match('a*', 'xxx').span() == (0, 0)
- assert re.match('x*', 'xxxa').span(0) == (0, 3)
- assert re.match('x*', 'xxxa').span() == (0, 3)
- assert re.match('a+', 'xxx') is None
+ verify(re.match('a*', 'xxx').span(0) == (0, 0))
+ verify(re.match('a*', 'xxx').span() == (0, 0))
+ verify(re.match('x*', 'xxxa').span(0) == (0, 3))
+ verify(re.match('x*', 'xxxa').span() == (0, 3))
+ verify(re.match('a+', 'xxx') is None)
except:
raise TestFailed, "re.search"
@@ -32,40 +32,40 @@ if verbose:
print 'Running tests on re.sub'
try:
- assert re.sub("(?i)b+", "x", "bbbb BBBB") == 'x x'
+ verify(re.sub("(?i)b+", "x", "bbbb BBBB") == 'x x')
def bump_num(matchobj):
int_value = int(matchobj.group(0))
return str(int_value + 1)
- assert re.sub(r'\d+', bump_num, '08.2 -2 23x99y') == '9.3 -3 24x100y'
- assert re.sub(r'\d+', bump_num, '08.2 -2 23x99y', 3) == '9.3 -3 23x99y'
+ verify(re.sub(r'\d+', bump_num, '08.2 -2 23x99y') == '9.3 -3 24x100y')
+ verify(re.sub(r'\d+', bump_num, '08.2 -2 23x99y', 3) == '9.3 -3 23x99y')
- assert re.sub('.', lambda m: r"\n", 'x') == '\\n'
- assert re.sub('.', r"\n", 'x') == '\n'
+ verify(re.sub('.', lambda m: r"\n", 'x') == '\\n')
+ verify(re.sub('.', r"\n", 'x') == '\n')
s = r"\1\1"
- assert re.sub('(.)', s, 'x') == 'xx'
- assert re.sub('(.)', re.escape(s), 'x') == s
- assert re.sub('(.)', lambda m: s, 'x') == s
+ verify(re.sub('(.)', s, 'x') == 'xx')
+ verify(re.sub('(.)', re.escape(s), 'x') == s)
+ verify(re.sub('(.)', lambda m: s, 'x') == s)
- assert re.sub('(?P<a>x)', '\g<a>\g<a>', 'xx') == 'xxxx'
- assert re.sub('(?P<a>x)', '\g<a>\g<1>', 'xx') == 'xxxx'
- assert re.sub('(?P<unk>x)', '\g<unk>\g<unk>', 'xx') == 'xxxx'
- assert re.sub('(?P<unk>x)', '\g<1>\g<1>', 'xx') == 'xxxx'
+ verify(re.sub('(?P<a>x)', '\g<a>\g<a>', 'xx') == 'xxxx')
+ verify(re.sub('(?P<a>x)', '\g<a>\g<1>', 'xx') == 'xxxx')
+ verify(re.sub('(?P<unk>x)', '\g<unk>\g<unk>', 'xx') == 'xxxx')
+ verify(re.sub('(?P<unk>x)', '\g<1>\g<1>', 'xx') == 'xxxx')
- assert re.sub('a', r'\t\n\v\r\f\a\b\B\Z\a\A\w\W\s\S\d\D', 'a') == '\t\n\v\r\f\a\b\\B\\Z\a\\A\\w\\W\\s\\S\\d\\D'
- assert re.sub('a', '\t\n\v\r\f\a', 'a') == '\t\n\v\r\f\a'
- assert re.sub('a', '\t\n\v\r\f\a', 'a') == (chr(9)+chr(10)+chr(11)+chr(13)+chr(12)+chr(7))
+ verify(re.sub('a', r'\t\n\v\r\f\a\b\B\Z\a\A\w\W\s\S\d\D', 'a') == '\t\n\v\r\f\a\b\\B\\Z\a\\A\\w\\W\\s\\S\\d\\D')
+ verify(re.sub('a', '\t\n\v\r\f\a', 'a') == '\t\n\v\r\f\a')
+ verify(re.sub('a', '\t\n\v\r\f\a', 'a') == (chr(9)+chr(10)+chr(11)+chr(13)+chr(12)+chr(7)))
- assert re.sub('^\s*', 'X', 'test') == 'Xtest'
+ verify(re.sub('^\s*', 'X', 'test') == 'Xtest')
except AssertionError:
raise TestFailed, "re.sub"
try:
- assert re.sub('a', 'b', 'aaaaa') == 'bbbbb'
- assert re.sub('a', 'b', 'aaaaa', 1) == 'baaaa'
+ verify(re.sub('a', 'b', 'aaaaa') == 'bbbbb')
+ verify(re.sub('a', 'b', 'aaaaa', 1) == 'baaaa')
except AssertionError:
raise TestFailed, "qualified re.sub"
@@ -132,11 +132,11 @@ if verbose:
print 'Running tests on re.subn'
try:
- assert re.subn("(?i)b+", "x", "bbbb BBBB") == ('x x', 2)
- assert re.subn("b+", "x", "bbbb BBBB") == ('x BBBB', 1)
- assert re.subn("b+", "x", "xyz") == ('xyz', 0)
- assert re.subn("b*", "x", "xyz") == ('xxxyxzx', 4)
- assert re.subn("b*", "x", "xyz", 2) == ('xxxyz', 2)
+ verify(re.subn("(?i)b+", "x", "bbbb BBBB") == ('x x', 2))
+ verify(re.subn("b+", "x", "bbbb BBBB") == ('x BBBB', 1))
+ verify(re.subn("b+", "x", "xyz") == ('xyz', 0))
+ verify(re.subn("b*", "x", "xyz") == ('xxxyxzx', 4))
+ verify(re.subn("b*", "x", "xyz", 2) == ('xxxyz', 2))
except AssertionError:
raise TestFailed, "re.subn"
@@ -144,24 +144,24 @@ if verbose:
print 'Running tests on re.split'
try:
- assert re.split(":", ":a:b::c") == ['', 'a', 'b', '', 'c']
- assert re.split(":*", ":a:b::c") == ['', 'a', 'b', 'c']
- assert re.split("(:*)", ":a:b::c") == ['', ':', 'a', ':', 'b', '::', 'c']
- assert re.split("(?::*)", ":a:b::c") == ['', 'a', 'b', 'c']
- assert re.split("(:)*", ":a:b::c") == ['', ':', 'a', ':', 'b', ':', 'c']
- assert re.split("([b:]+)", ":a:b::c") == ['', ':', 'a', ':b::', 'c']
- assert re.split("(b)|(:+)", ":a:b::c") == \
- ['', None, ':', 'a', None, ':', '', 'b', None, '', None, '::', 'c']
- assert re.split("(?:b)|(?::+)", ":a:b::c") == ['', 'a', '', '', 'c']
+ verify(re.split(":", ":a:b::c") == ['', 'a', 'b', '', 'c'])
+ verify(re.split(":*", ":a:b::c") == ['', 'a', 'b', 'c'])
+ verify(re.split("(:*)", ":a:b::c") == ['', ':', 'a', ':', 'b', '::', 'c'])
+ verify(re.split("(?::*)", ":a:b::c") == ['', 'a', 'b', 'c'])
+ verify(re.split("(:)*", ":a:b::c") == ['', ':', 'a', ':', 'b', ':', 'c'])
+ verify(re.split("([b:]+)", ":a:b::c") == ['', ':', 'a', ':b::', 'c'])
+ verify(re.split("(b)|(:+)", ":a:b::c") == \
+ ['', None, ':', 'a', None, ':', '', 'b', None, '', None, '::', 'c'] )
+ verify(re.split("(?:b)|(?::+)", ":a:b::c") == ['', 'a', '', '', 'c'])
except AssertionError:
raise TestFailed, "re.split"
try:
- assert re.split(":", ":a:b::c", 2) == ['', 'a', 'b::c']
- assert re.split(':', 'a:b:c:d', 2) == ['a', 'b', 'c:d']
+ verify(re.split(":", ":a:b::c", 2) == ['', 'a', 'b::c'])
+ verify(re.split(':', 'a:b:c:d', 2) == ['a', 'b', 'c:d'])
- assert re.split("(:)", ":a:b::c", 2) == ['', ':', 'a', ':', 'b::c']
- assert re.split("(:*)", ":a:b::c", 2) == ['', ':', 'a', ':', 'b::c']
+ verify(re.split("(:)", ":a:b::c", 2) == ['', ':', 'a', ':', 'b::c'])
+ verify(re.split("(:*)", ":a:b::c", 2) == ['', ':', 'a', ':', 'b::c'])
except AssertionError:
raise TestFailed, "qualified re.split"
@@ -169,12 +169,12 @@ if verbose:
print "Running tests on re.findall"
try:
- assert re.findall(":+", "abc") == []
- assert re.findall(":+", "a:b::c:::d") == [":", "::", ":::"]
- assert re.findall("(:+)", "a:b::c:::d") == [":", "::", ":::"]
- assert re.findall("(:)(:*)", "a:b::c:::d") == [(":", ""),
+ verify(re.findall(":+", "abc") == [])
+ verify(re.findall(":+", "a:b::c:::d") == [":", "::", ":::"])
+ verify(re.findall("(:+)", "a:b::c:::d") == [":", "::", ":::"])
+ verify(re.findall("(:)(:*)", "a:b::c:::d") == [(":", ""),
(":", ":"),
- (":", "::")]
+ (":", "::")] )
except AssertionError:
raise TestFailed, "re.findall"
@@ -183,29 +183,31 @@ if verbose:
try:
# No groups at all
- m = re.match('a', 'a') ; assert m.groups() == ()
+ m = re.match('a', 'a') ; verify(m.groups() == ())
# A single group
- m = re.match('(a)', 'a') ; assert m.groups() == ('a',)
+ m = re.match('(a)', 'a') ; verify(m.groups() == ('a',))
pat = re.compile('((a)|(b))(c)?')
- assert pat.match('a').groups() == ('a', 'a', None, None)
- assert pat.match('b').groups() == ('b', None, 'b', None)
- assert pat.match('ac').groups() == ('a', 'a', None, 'c')
- assert pat.match('bc').groups() == ('b', None, 'b', 'c')
- assert pat.match('bc').groups("") == ('b', "", 'b', 'c')
+ verify(pat.match('a').groups() == ('a', 'a', None, None))
+ verify(pat.match('b').groups() == ('b', None, 'b', None))
+ verify(pat.match('ac').groups() == ('a', 'a', None, 'c'))
+ verify(pat.match('bc').groups() == ('b', None, 'b', 'c'))
+ verify(pat.match('bc').groups("") == ('b', "", 'b', 'c'))
except AssertionError:
raise TestFailed, "match .groups() method"
try:
# A single group
m = re.match('(a)', 'a')
- assert m.group(0) == 'a' ; assert m.group(0) == 'a'
- assert m.group(1) == 'a' ; assert m.group(1, 1) == ('a', 'a')
+ verify(m.group(0) == 'a')
+ verify(m.group(0) == 'a')
+ verify(m.group(1) == 'a')
+ verify(m.group(1, 1) == ('a', 'a'))
pat = re.compile('(?:(?P<a1>a)|(?P<b2>b))(?P<c3>c)?')
- assert pat.match('a').group(1, 2, 3) == ('a', None, None)
- assert pat.match('b').group('a1', 'b2', 'c3') == (None, 'b', None)
- assert pat.match('ac').group(1, 'b2', 3) == ('a', None, 'c')
+ verify(pat.match('a').group(1, 2, 3) == ('a', None, None))
+ verify(pat.match('b').group('a1', 'b2', 'c3') == (None, 'b', None))
+ verify(pat.match('ac').group(1, 'b2', 3) == ('a', None, 'c'))
except AssertionError:
raise TestFailed, "match .group() method"
@@ -216,12 +218,12 @@ try:
p=""
for i in range(0, 256):
p = p + chr(i)
- assert re.match(re.escape(chr(i)), chr(i)) is not None
- assert re.match(re.escape(chr(i)), chr(i)).span() == (0,1)
+ verify(re.match(re.escape(chr(i)), chr(i)) is not None)
+ verify(re.match(re.escape(chr(i)), chr(i)).span() == (0,1))
pat=re.compile( re.escape(p) )
- assert pat.match(p) is not None
- assert pat.match(p).span() == (0,256)
+ verify(pat.match(p) is not None)
+ verify(pat.match(p).span() == (0,256))
except AssertionError:
raise TestFailed, "re.escape"
@@ -235,11 +237,11 @@ s = pickle.dumps(pat)
pat = pickle.loads(s)
try:
- assert re.I == re.IGNORECASE
- assert re.L == re.LOCALE
- assert re.M == re.MULTILINE
- assert re.S == re.DOTALL
- assert re.X == re.VERBOSE
+ verify(re.I == re.IGNORECASE)
+ verify(re.L == re.LOCALE)
+ verify(re.M == re.MULTILINE)
+ verify(re.S == re.DOTALL)
+ verify(re.X == re.VERBOSE)
except AssertionError:
raise TestFailed, 're module constants'
@@ -255,7 +257,7 @@ if verbose:
# Try nasty case that overflows the straightforward recursive
# implementation of repeated groups.
try:
- assert re.match('(x)*', 50000*'x').span() == (0, 50000)
+ verify(re.match('(x)*', 50000*'x').span() == (0, 50000))
except RuntimeError, v:
print v
diff --git a/Lib/test/test_regex.py b/Lib/test/test_regex.py
index a324821..a49abea 100644
--- a/Lib/test/test_regex.py
+++ b/Lib/test/test_regex.py
@@ -1,4 +1,4 @@
-from test_support import verbose
+from test_support import verify, verbose
import warnings
warnings.filterwarnings("ignore", "the regex module is deprecated",
DeprecationWarning, __name__)
diff --git a/Lib/test/test_rfc822.py b/Lib/test/test_rfc822.py
index 967b91b..c6df925 100644
--- a/Lib/test/test_rfc822.py
+++ b/Lib/test/test_rfc822.py
@@ -1,4 +1,4 @@
-from test_support import verbose
+from test_support import verify, verbose
import rfc822, sys
try:
from cStringIO import StringIO
diff --git a/Lib/test/test_rgbimg.py b/Lib/test/test_rgbimg.py
index f2622e4..b078d47 100644
--- a/Lib/test/test_rgbimg.py
+++ b/Lib/test/test_rgbimg.py
@@ -2,7 +2,7 @@
import rgbimg, os, uu
-from test_support import verbose, unlink, findfile
+from test_support import verify, verbose, unlink, findfile
class error(Exception):
pass
diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py
index e6f2755..c282c17 100644
--- a/Lib/test/test_sax.py
+++ b/Lib/test/test_sax.py
@@ -12,7 +12,7 @@ from xml.sax.saxutils import XMLGenerator, escape, XMLFilterBase
from xml.sax.expatreader import create_parser
from xml.sax.xmlreader import InputSource, AttributesImpl, AttributesNSImpl
from cStringIO import StringIO
-from test_support import verbose, TestFailed, findfile
+from test_support import verify, verbose, TestFailed, findfile
# ===== Utilities
diff --git a/Lib/test/test_select.py b/Lib/test/test_select.py
index d5bcfd5..be12923 100644
--- a/Lib/test/test_select.py
+++ b/Lib/test/test_select.py
@@ -1,5 +1,5 @@
# Testing select module
-from test_support import verbose
+from test_support import verify, verbose
import select
import os
diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py
index a6c32b4..9d4c277 100644
--- a/Lib/test/test_signal.py
+++ b/Lib/test/test_signal.py
@@ -1,5 +1,5 @@
# Test the signal module
-from test_support import verbose, TestSkipped
+from test_support import verify, verbose, TestSkipped
import signal
import os
import sys
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index fe37936..dab432f 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -8,7 +8,7 @@
# sktobj.shutdown()
-from test_support import verbose, TestFailed
+from test_support import verify, verbose, TestFailed
import socket
import os
import time
diff --git a/Lib/test/test_sre.py b/Lib/test/test_sre.py
index 88c0d62..0aa8349 100644
--- a/Lib/test/test_sre.py
+++ b/Lib/test/test_sre.py
@@ -6,7 +6,7 @@
import sys
sys.path=['.']+sys.path
-from test_support import verbose, TestFailed
+from test_support import verify, verbose, TestFailed
import sre
import sys, os, string, traceback
diff --git a/Lib/test/test_strftime.py b/Lib/test/test_strftime.py
index 7f5cb80..73de2d3 100755
--- a/Lib/test/test_strftime.py
+++ b/Lib/test/test_strftime.py
@@ -3,7 +3,7 @@
# Sanity checker for time.strftime
import time, calendar, sys, string, os, re
-from test_support import verbose
+from test_support import verify, verbose
def main():
global verbose
diff --git a/Lib/test/test_string.py b/Lib/test/test_string.py
index 3574719..fd1cbae 100644
--- a/Lib/test/test_string.py
+++ b/Lib/test/test_string.py
@@ -1,4 +1,4 @@
-from test_support import verbose, TestSkipped
+from test_support import verify, verbose, TestSkipped
import string_tests
import string, sys
diff --git a/Lib/test/test_strop.py b/Lib/test/test_strop.py
index 5770046..d444f3d 100644
--- a/Lib/test/test_strop.py
+++ b/Lib/test/test_strop.py
@@ -1,4 +1,4 @@
-from test_support import verbose
+from test_support import verify, verbose
import strop, sys
def test(name, input, output, *args):
diff --git a/Lib/test/test_sunaudiodev.py b/Lib/test/test_sunaudiodev.py
index af18761..4083c68 100644
--- a/Lib/test/test_sunaudiodev.py
+++ b/Lib/test/test_sunaudiodev.py
@@ -1,4 +1,4 @@
-from test_support import verbose, findfile, TestFailed
+from test_support import verify, verbose, findfile, TestFailed
import sunaudiodev
import os
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py
index a24b3ce..8dcec30 100644
--- a/Lib/test/test_support.py
+++ b/Lib/test/test_support.py
@@ -71,3 +71,15 @@ def findfile(file, here=__file__):
fn = os.path.join(dn, file)
if os.path.exists(fn): return fn
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
diff --git a/Lib/test/test_thread.py b/Lib/test/test_thread.py
index 02da94e..134badf 100644
--- a/Lib/test/test_thread.py
+++ b/Lib/test/test_thread.py
@@ -2,7 +2,7 @@
# Create a bunch of threads, let each do some work, wait until all are done
-from test_support import verbose
+from test_support import verify, verbose
import random
import thread
import time
diff --git a/Lib/test/test_timing.py b/Lib/test/test_timing.py
index 5dbc895..984638e 100644
--- a/Lib/test/test_timing.py
+++ b/Lib/test/test_timing.py
@@ -1,4 +1,4 @@
-from test_support import verbose
+from test_support import verify, verbose
import timing
r = range(100000)
diff --git a/Lib/test/test_tokenize.py b/Lib/test/test_tokenize.py
index a0713d1..52d4300 100644
--- a/Lib/test/test_tokenize.py
+++ b/Lib/test/test_tokenize.py
@@ -1,4 +1,4 @@
-from test_support import verbose, findfile
+from test_support import verify, verbose, findfile
import tokenize, os, sys
if verbose:
diff --git a/Lib/test/test_ucn.py b/Lib/test/test_ucn.py
index f1a6229..92155be 100644
--- a/Lib/test/test_ucn.py
+++ b/Lib/test/test_ucn.py
@@ -5,6 +5,8 @@ Written by Bill Tutt.
(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
"""#"
+from test_support import verify, verbose
+
print 'Testing General Unicode Character Name, and case insensitivity...',
# General and case insensitivity test:
@@ -34,15 +36,15 @@ s = u"\N{LATIN CAPITAL LETTER T}" \
u"\N{LATIN SMALL LETTER E}" \
u"\N{LATIN SMALL LETTER P}" \
u"\N{FULL STOP}"
-assert s == u"The rEd fOx ate the sheep.", s
+verify(s == u"The rEd fOx ate the sheep.", s)
print "done."
# misc. symbol testing
print "Testing misc. symbols for unicode character name expansion....",
-assert u"\N{PILCROW SIGN}" == u"\u00b6"
-assert u"\N{REPLACEMENT CHARACTER}" == u"\uFFFD"
-assert u"\N{HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK}" == u"\uFF9F"
-assert u"\N{FULLWIDTH LATIN SMALL LETTER A}" == u"\uFF41"
+verify(u"\N{PILCROW SIGN}" == u"\u00b6")
+verify(u"\N{REPLACEMENT CHARACTER}" == u"\uFFFD")
+verify(u"\N{HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK}" == u"\uFF9F")
+verify(u"\N{FULLWIDTH LATIN SMALL LETTER A}" == u"\uFF41")
print "done."
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index c71f927..f199828 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -4,8 +4,8 @@ Written by Marc-Andre Lemburg (mal@lemburg.com).
(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
-"""
-from test_support import verbose
+"""#"
+from test_support import verify, verbose
import sys
def test(method, input, output, *args):
@@ -173,15 +173,15 @@ if 0:
# Comparisons:
print 'Testing Unicode comparisons...',
-assert u'abc' == 'abc'
-assert 'abc' == u'abc'
-assert u'abc' == u'abc'
-assert u'abcd' > 'abc'
-assert 'abcd' > u'abc'
-assert u'abcd' > u'abc'
-assert u'abc' < 'abcd'
-assert 'abc' < u'abcd'
-assert u'abc' < u'abcd'
+verify(u'abc' == 'abc')
+verify('abc' == u'abc')
+verify(u'abc' == u'abc')
+verify(u'abcd' > 'abc')
+verify('abcd' > u'abc')
+verify(u'abcd' > u'abc')
+verify(u'abc' < 'abcd')
+verify('abc' < u'abcd')
+verify(u'abc' < u'abcd')
print 'done.'
if 0:
@@ -189,13 +189,13 @@ if 0:
print 'Testing UTF-16 code point order comparisons...',
#No surrogates, no fixup required.
- assert u'\u0061' < u'\u20ac'
+ verify(u'\u0061' < u'\u20ac')
# Non surrogate below surrogate value, no fixup required
- assert u'\u0061' < u'\ud800\udc02'
+ verify(u'\u0061' < u'\ud800\udc02')
# Non surrogate above surrogate value, fixup required
def test_lecmp(s, s2):
- assert 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'
@@ -235,7 +235,7 @@ if 0:
test_fixup(u'\uff61')
# Surrogates on both sides, no fixup required
- assert u'\ud800\udc02' < u'\ud84d\udc56'
+ verify(u'\ud800\udc02' < u'\ud84d\udc56')
print 'done.'
test('ljust', u'abc', u'abc ', 10)
@@ -306,78 +306,78 @@ test('translate', u"abababc", u'iiix', {ord('a'):None, ord('b'):ord('i'), ord('c
# Contains:
print 'Testing Unicode contains method...',
-assert ('a' in u'abdb') == 1
-assert ('a' in u'bdab') == 1
-assert ('a' in u'bdaba') == 1
-assert ('a' in u'bdba') == 1
-assert ('a' in u'bdba') == 1
-assert (u'a' in u'bdba') == 1
-assert (u'a' in u'bdb') == 0
-assert (u'a' in 'bdb') == 0
-assert (u'a' in 'bdba') == 1
-assert (u'a' in ('a',1,None)) == 1
-assert (u'a' in (1,None,'a')) == 1
-assert (u'a' in (1,None,u'a')) == 1
-assert ('a' in ('a',1,None)) == 1
-assert ('a' in (1,None,'a')) == 1
-assert ('a' in (1,None,u'a')) == 1
-assert ('a' in ('x',1,u'y')) == 0
-assert ('a' in ('x',1,None)) == 0
+verify(('a' in u'abdb') == 1)
+verify(('a' in u'bdab') == 1)
+verify(('a' in u'bdaba') == 1)
+verify(('a' in u'bdba') == 1)
+verify(('a' in u'bdba') == 1)
+verify((u'a' in u'bdba') == 1)
+verify((u'a' in u'bdb') == 0)
+verify((u'a' in 'bdb') == 0)
+verify((u'a' in 'bdba') == 1)
+verify((u'a' in ('a',1,None)) == 1)
+verify((u'a' in (1,None,'a')) == 1)
+verify((u'a' in (1,None,u'a')) == 1)
+verify(('a' in ('a',1,None)) == 1)
+verify(('a' in (1,None,'a')) == 1)
+verify(('a' in (1,None,u'a')) == 1)
+verify(('a' in ('x',1,u'y')) == 0)
+verify(('a' in ('x',1,None)) == 0)
print 'done.'
# Formatting:
print 'Testing Unicode formatting strings...',
-assert u"%s, %s" % (u"abc", "abc") == u'abc, abc'
-assert u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", 1, 2, 3) == u'abc, abc, 1, 2.000000, 3.00'
-assert u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", 1, -2, 3) == u'abc, abc, 1, -2.000000, 3.00'
-assert u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", -1, -2, 3.5) == u'abc, abc, -1, -2.000000, 3.50'
-assert u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", -1, -2, 3.57) == u'abc, abc, -1, -2.000000, 3.57'
-assert u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", -1, -2, 1003.57) == u'abc, abc, -1, -2.000000, 1003.57'
-assert u"%c" % (u"a",) == u'a'
-assert u"%c" % ("a",) == u'a'
-assert u"%c" % (34,) == u'"'
-assert u"%c" % (36,) == u'$'
+verify(u"%s, %s" % (u"abc", "abc") == u'abc, abc')
+verify(u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", 1, 2, 3) == u'abc, abc, 1, 2.000000, 3.00')
+verify(u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", 1, -2, 3) == u'abc, abc, 1, -2.000000, 3.00')
+verify(u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", -1, -2, 3.5) == u'abc, abc, -1, -2.000000, 3.50')
+verify(u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", -1, -2, 3.57) == u'abc, abc, -1, -2.000000, 3.57')
+verify(u"%s, %s, %i, %f, %5.2f" % (u"abc", "abc", -1, -2, 1003.57) == u'abc, abc, -1, -2.000000, 1003.57')
+verify(u"%c" % (u"a",) == u'a')
+verify(u"%c" % ("a",) == u'a')
+verify(u"%c" % (34,) == u'"')
+verify(u"%c" % (36,) == u'$')
value = u"%r, %r" % (u"abc", "abc")
if value != u"u'abc', 'abc'":
print '*** formatting failed for "%s"' % 'u"%r, %r" % (u"abc", "abc")'
-assert u"%(x)s, %(y)s" % {'x':u"abc", 'y':"def"} == u'abc, def'
+verify(u"%(x)s, %(y)s" % {'x':u"abc", 'y':"def"} == u'abc, def')
try:
value = u"%(x)s, %(ä)s" % {'x':u"abc", u'ä'.encode('utf-8'):"def"}
except KeyError:
print '*** formatting failed for "%s"' % "u'abc, def'"
else:
- assert value == u'abc, def'
+ verify(value == u'abc, def')
# formatting jobs delegated from the string implementation:
-assert '...%(foo)s...' % {'foo':u"abc"} == u'...abc...'
-assert '...%(foo)s...' % {'foo':"abc"} == '...abc...'
-assert '...%(foo)s...' % {u'foo':"abc"} == '...abc...'
-assert '...%(foo)s...' % {u'foo':u"abc"} == u'...abc...'
-assert '...%(foo)s...' % {u'foo':u"abc",'def':123} == u'...abc...'
-assert '...%(foo)s...' % {u'foo':u"abc",u'def':123} == u'...abc...'
-assert '...%s...%s...%s...%s...' % (1,2,3,u"abc") == u'...1...2...3...abc...'
-assert '...%%...%%s...%s...%s...%s...%s...' % (1,2,3,u"abc") == u'...%...%s...1...2...3...abc...'
-assert '...%s...' % u"abc" == u'...abc...'
+verify('...%(foo)s...' % {'foo':u"abc"} == u'...abc...')
+verify('...%(foo)s...' % {'foo':"abc"} == '...abc...')
+verify('...%(foo)s...' % {u'foo':"abc"} == '...abc...')
+verify('...%(foo)s...' % {u'foo':u"abc"} == u'...abc...')
+verify('...%(foo)s...' % {u'foo':u"abc",'def':123} == u'...abc...')
+verify('...%(foo)s...' % {u'foo':u"abc",u'def':123} == u'...abc...')
+verify('...%s...%s...%s...%s...' % (1,2,3,u"abc") == u'...1...2...3...abc...')
+verify('...%%...%%s...%s...%s...%s...%s...' % (1,2,3,u"abc") == u'...%...%s...1...2...3...abc...')
+verify('...%s...' % u"abc" == u'...abc...')
print 'done.'
# Test builtin codecs
print 'Testing builtin codecs...',
# UTF-8 specific encoding tests:
-assert u'\u20ac'.encode('utf-8') == \
- ''.join((chr(0xe2), chr(0x82), chr(0xac)))
-assert u'\ud800\udc02'.encode('utf-8') == \
- ''.join((chr(0xf0), chr(0x90), chr(0x80), chr(0x82)))
-assert u'\ud84d\udc56'.encode('utf-8') == \
- ''.join((chr(0xf0), chr(0xa3), chr(0x91), chr(0x96)))
+verify(u'\u20ac'.encode('utf-8') == \
+ ''.join((chr(0xe2), chr(0x82), chr(0xac))) )
+verify(u'\ud800\udc02'.encode('utf-8') == \
+ ''.join((chr(0xf0), chr(0x90), chr(0x80), chr(0x82))) )
+verify(u'\ud84d\udc56'.encode('utf-8') == \
+ ''.join((chr(0xf0), chr(0xa3), chr(0x91), chr(0x96))) )
# UTF-8 specific decoding tests
-assert unicode(''.join((chr(0xf0), chr(0xa3), chr(0x91), chr(0x96))),
- 'utf-8') == u'\ud84d\udc56'
-assert unicode(''.join((chr(0xf0), chr(0x90), chr(0x80), chr(0x82))),
- 'utf-8') == u'\ud800\udc02'
-assert unicode(''.join((chr(0xe2), chr(0x82), chr(0xac))),
- 'utf-8') == u'\u20ac'
+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))),
+ 'utf-8') == u'\ud800\udc02' )
+verify(unicode(''.join((chr(0xe2), chr(0x82), chr(0xac))),
+ 'utf-8') == u'\u20ac' )
# Other possible utf-8 test cases:
# * strict decoding testing for all of the
@@ -385,10 +385,10 @@ assert unicode(''.join((chr(0xe2), chr(0x82), chr(0xac))),
-assert unicode('hello','ascii') == u'hello'
-assert unicode('hello','utf-8') == u'hello'
-assert unicode('hello','utf8') == u'hello'
-assert unicode('hello','latin-1') == u'hello'
+verify(unicode('hello','ascii') == u'hello')
+verify(unicode('hello','utf-8') == u'hello')
+verify(unicode('hello','utf8') == u'hello')
+verify(unicode('hello','latin-1') == u'hello')
class String:
x = ''
@@ -398,12 +398,12 @@ class String:
o = String()
o.x = 'abc'
-assert unicode(o) == u'abc'
-assert str(o) == 'abc'
+verify(unicode(o) == u'abc')
+verify(str(o) == 'abc')
o.x = u'abc'
-assert unicode(o) == u'abc'
-assert str(o) == 'abc'
+verify(unicode(o) == u'abc')
+verify(str(o) == 'abc')
try:
u'Andr\202 x'.encode('ascii')
@@ -412,8 +412,8 @@ except ValueError:
pass
else:
raise AssertionError, "u'Andr\202'.encode('ascii') failed to raise an exception"
-assert u'Andr\202 x'.encode('ascii','ignore') == "Andr x"
-assert u'Andr\202 x'.encode('ascii','replace') == "Andr? x"
+verify(u'Andr\202 x'.encode('ascii','ignore') == "Andr x")
+verify(u'Andr\202 x'.encode('ascii','replace') == "Andr? x")
try:
unicode('Andr\202 x','ascii')
@@ -422,27 +422,27 @@ except ValueError:
pass
else:
raise AssertionError, "unicode('Andr\202') failed to raise an exception"
-assert unicode('Andr\202 x','ascii','ignore') == u"Andr x"
-assert unicode('Andr\202 x','ascii','replace') == u'Andr\uFFFD x'
+verify(unicode('Andr\202 x','ascii','ignore') == u"Andr x")
+verify(unicode('Andr\202 x','ascii','replace') == u'Andr\uFFFD x')
-assert u'hello'.encode('ascii') == 'hello'
-assert u'hello'.encode('utf-8') == 'hello'
-assert u'hello'.encode('utf8') == 'hello'
-assert u'hello'.encode('utf-16-le') == 'h\000e\000l\000l\000o\000'
-assert u'hello'.encode('utf-16-be') == '\000h\000e\000l\000l\000o'
-assert u'hello'.encode('latin-1') == 'hello'
+verify(u'hello'.encode('ascii') == 'hello')
+verify(u'hello'.encode('utf-8') == 'hello')
+verify(u'hello'.encode('utf8') == 'hello')
+verify(u'hello'.encode('utf-16-le') == 'h\000e\000l\000l\000o\000')
+verify(u'hello'.encode('utf-16-be') == '\000h\000e\000l\000l\000o')
+verify(u'hello'.encode('latin-1') == 'hello')
u = u''.join(map(unichr, range(1024)))
for encoding in ('utf-8', 'utf-16', 'utf-16-le', 'utf-16-be',
'raw_unicode_escape', 'unicode_escape', 'unicode_internal'):
- assert unicode(u.encode(encoding),encoding) == u
+ verify(unicode(u.encode(encoding),encoding) == u)
u = u''.join(map(unichr, range(256)))
for encoding in (
'latin-1',
):
try:
- assert unicode(u.encode(encoding),encoding) == u
+ verify(unicode(u.encode(encoding),encoding) == u)
except AssertionError:
print '*** codec "%s" failed round-trip' % encoding
except ValueError,why:
@@ -453,7 +453,7 @@ for encoding in (
'ascii',
):
try:
- assert unicode(u.encode(encoding),encoding) == u
+ verify(unicode(u.encode(encoding),encoding) == u)
except AssertionError:
print '*** codec "%s" failed round-trip' % encoding
except ValueError,why:
@@ -487,7 +487,7 @@ for encoding in (
):
try:
- assert unicode(s,encoding).encode(encoding) == s
+ verify(unicode(s,encoding).encode(encoding) == s)
except AssertionError:
print '*** codec "%s" failed round-trip' % encoding
except ValueError,why:
@@ -517,7 +517,7 @@ for encoding in (
):
try:
- assert unicode(s,encoding).encode(encoding) == s
+ verify(unicode(s,encoding).encode(encoding) == s)
except AssertionError:
print '*** codec "%s" failed round-trip' % encoding
except ValueError,why:
@@ -526,9 +526,9 @@ for encoding in (
print 'done.'
print 'Testing Unicode string concatenation...',
-assert (u"abc" u"def") == u"abcdef"
-assert ("abc" u"def") == u"abcdef"
-assert (u"abc" "def") == u"abcdef"
-assert (u"abc" u"def" "ghi") == u"abcdefghi"
-assert ("abc" "def" u"ghi") == u"abcdefghi"
+verify((u"abc" u"def") == u"abcdef")
+verify(("abc" u"def") == u"abcdef")
+verify((u"abc" "def") == u"abcdef")
+verify((u"abc" u"def" "ghi") == u"abcdefghi")
+verify(("abc" "def" u"ghi") == u"abcdefghi")
print 'done.'
diff --git a/Lib/test/test_unicodedata.py b/Lib/test/test_unicodedata.py
index 7e3cf22..db03d35 100644
--- a/Lib/test/test_unicodedata.py
+++ b/Lib/test/test_unicodedata.py
@@ -5,6 +5,7 @@
(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
"""#"
+from test_support import verify, verbose
import sha
encoding = 'utf-8'
@@ -87,38 +88,38 @@ print test_unicodedata()
# Some additional checks of the API:
print 'API:',
-assert unicodedata.digit(u'A',None) is None
-assert unicodedata.digit(u'9') == 9
-assert unicodedata.digit(u'\u215b',None) is None
-assert unicodedata.digit(u'\u2468') == 9
+verify(unicodedata.digit(u'A',None) is None)
+verify(unicodedata.digit(u'9') == 9)
+verify(unicodedata.digit(u'\u215b',None) is None)
+verify(unicodedata.digit(u'\u2468') == 9)
-assert unicodedata.numeric(u'A',None) is None
-assert unicodedata.numeric(u'9') == 9
-assert unicodedata.numeric(u'\u215b') == 0.125
-assert unicodedata.numeric(u'\u2468') == 9.0
+verify(unicodedata.numeric(u'A',None) is None)
+verify(unicodedata.numeric(u'9') == 9)
+verify(unicodedata.numeric(u'\u215b') == 0.125)
+verify(unicodedata.numeric(u'\u2468') == 9.0)
-assert unicodedata.decimal(u'A',None) is None
-assert unicodedata.decimal(u'9') == 9
-assert unicodedata.decimal(u'\u215b',None) is None
-assert unicodedata.decimal(u'\u2468',None) is None
+verify(unicodedata.decimal(u'A',None) is None)
+verify(unicodedata.decimal(u'9') == 9)
+verify(unicodedata.decimal(u'\u215b',None) is None)
+verify(unicodedata.decimal(u'\u2468',None) is None)
-assert unicodedata.category(u'\uFFFE') == 'Cn'
-assert unicodedata.category(u'a') == 'Ll'
-assert unicodedata.category(u'A') == 'Lu'
+verify(unicodedata.category(u'\uFFFE') == 'Cn')
+verify(unicodedata.category(u'a') == 'Ll')
+verify(unicodedata.category(u'A') == 'Lu')
-assert unicodedata.bidirectional(u'\uFFFE') == ''
-assert unicodedata.bidirectional(u' ') == 'WS'
-assert unicodedata.bidirectional(u'A') == 'L'
+verify(unicodedata.bidirectional(u'\uFFFE') == '')
+verify(unicodedata.bidirectional(u' ') == 'WS')
+verify(unicodedata.bidirectional(u'A') == 'L')
-assert unicodedata.decomposition(u'\uFFFE') == ''
-assert unicodedata.decomposition(u'\u00bc') == '<fraction> 0031 2044 0034'
+verify(unicodedata.decomposition(u'\uFFFE') == '')
+verify(unicodedata.decomposition(u'\u00bc') == '<fraction> 0031 2044 0034')
-assert unicodedata.mirrored(u'\uFFFE') == 0
-assert unicodedata.mirrored(u'a') == 0
-assert unicodedata.mirrored(u'\u2201') == 1
+verify(unicodedata.mirrored(u'\uFFFE') == 0)
+verify(unicodedata.mirrored(u'a') == 0)
+verify(unicodedata.mirrored(u'\u2201') == 1)
-assert unicodedata.combining(u'\uFFFE') == 0
-assert unicodedata.combining(u'a') == 0
-assert unicodedata.combining(u'\u20e1') == 230
+verify(unicodedata.combining(u'\uFFFE') == 0)
+verify(unicodedata.combining(u'a') == 0)
+verify(unicodedata.combining(u'\u20e1') == 230)
print 'ok'
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
index 81533e1..d2d5d63 100644
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -1,4 +1,5 @@
# Minimal test of the quote function
+from test_support import verify, verbose
import urllib
chars = 'abcdefghijklmnopqrstuvwxyz'\
@@ -11,20 +12,20 @@ chars = 'abcdefghijklmnopqrstuvwxyz'\
expected = 'abcdefghijklmnopqrstuvwxyz%df%e0%e1%e2%e3%e4%e5%e6%e7%e8%e9%ea%eb%ec%ed%ee%ef%f0%f1%f2%f3%f4%f5%f6%f8%f9%fa%fb%fc%fd%fe%ffABCDEFGHIJKLMNOPQRSTUVWXYZ%c0%c1%c2%c3%c4%c5%c6%c7%c8%c9%ca%cb%cc%cd%ce%cf%d0%d1%d2%d3%d4%d5%d6%d8%d9%da%db%dc%dd%de'
test = urllib.quote(chars)
-assert test == expected, "urllib.quote problem"
+verify(test == expected, "urllib.quote problem")
test2 = urllib.unquote(expected)
-assert test2 == chars
+verify(test2 == chars)
in1 = "abc/def"
out1_1 = "abc/def"
out1_2 = "abc%2fdef"
-assert urllib.quote(in1) == out1_1, "urllib.quote problem"
-assert urllib.quote(in1, '') == out1_2, "urllib.quote problem"
+verify(urllib.quote(in1) == out1_1, "urllib.quote problem")
+verify(urllib.quote(in1, '') == out1_2, "urllib.quote problem")
in2 = "abc?def"
out2_1 = "abc%3fdef"
out2_2 = "abc?def"
-assert urllib.quote(in2) == out2_1, "urllib.quote problem"
-assert urllib.quote(in2, '?') == out2_2, "urllib.quote problem"
+verify(urllib.quote(in2) == out2_1, "urllib.quote problem")
+verify(urllib.quote(in2, '?') == out2_2, "urllib.quote problem")
diff --git a/Lib/test/test_userdict.py b/Lib/test/test_userdict.py
index 63632f7..08b7a13 100644
--- a/Lib/test/test_userdict.py
+++ b/Lib/test/test_userdict.py
@@ -1,5 +1,6 @@
# Check every path through every method of UserDict
+from test_support import verify, verbose
from UserDict import UserDict
d0 = {}
@@ -20,26 +21,26 @@ uu2 = UserDict(u2)
# Test __repr__
-assert str(u0) == str(d0)
-assert repr(u1) == repr(d1)
-assert `u2` == `d2`
+verify(str(u0) == str(d0))
+verify(repr(u1) == repr(d1))
+verify(`u2` == `d2`)
# Test __cmp__ and __len__
all = [d0, d1, d2, u, u0, u1, u2, uu, uu0, uu1, uu2]
for a in all:
for b in all:
- assert cmp(a, b) == cmp(len(a), len(b))
+ verify(cmp(a, b) == cmp(len(a), len(b)))
# Test __getitem__
-assert u2["one"] == 1
+verify(u2["one"] == 1)
try:
u1["two"]
except KeyError:
pass
else:
- assert 0, "u1['two'] shouldn't exist"
+ verify(0, "u1['two'] shouldn't exist")
# Test __setitem__
@@ -55,47 +56,47 @@ try:
except KeyError:
pass
else:
- assert 0, "u3['three'] shouldn't exist"
+ verify(0, "u3['three'] shouldn't exist")
# Test clear
u3.clear()
-assert u3 == {}
+verify(u3 == {})
# Test copy()
u2a = u2.copy()
-assert u2a == u2
+verify(u2a == u2)
class MyUserDict(UserDict):
def display(self): print self
m2 = MyUserDict(u2)
m2a = m2.copy()
-assert m2a == m2
+verify(m2a == m2)
# Test keys, items, values
-assert u2.keys() == d2.keys()
-assert u2.items() == d2.items()
-assert u2.values() == d2.values()
+verify(u2.keys() == d2.keys())
+verify(u2.items() == d2.items())
+verify(u2.values() == d2.values())
# Test has_key
for i in u2.keys():
- assert u2.has_key(i) == 1
- assert u1.has_key(i) == d1.has_key(i)
- assert u0.has_key(i) == d0.has_key(i)
+ verify(u2.has_key(i) == 1)
+ verify(u1.has_key(i) == d1.has_key(i))
+ verify(u0.has_key(i) == d0.has_key(i))
# Test update
t = UserDict()
t.update(u2)
-assert t == u2
+verify(t == u2)
# Test get
for i in u2.keys():
- assert u2.get(i) == u2[i]
- assert u1.get(i) == d1.get(i)
- assert u0.get(i) == d0.get(i)
+ verify(u2.get(i) == u2[i])
+ verify(u1.get(i) == d1.get(i))
+ verify(u0.get(i) == d0.get(i))
diff --git a/Lib/test/test_userlist.py b/Lib/test/test_userlist.py
index e8d9cb0..da866cc 100644
--- a/Lib/test/test_userlist.py
+++ b/Lib/test/test_userlist.py
@@ -3,7 +3,7 @@
from UserList import UserList
from test_support import TestFailed
-# Use check instead of assert so -O doesn't render the
+# Use check instead of verify(so -O doesn't render the)
# test useless.
def check(predicate, msg):
if not predicate:
diff --git a/Lib/test/test_userstring.py b/Lib/test/test_userstring.py
index a47bfdd..4f54db2 100755
--- a/Lib/test/test_userstring.py
+++ b/Lib/test/test_userstring.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
import sys, string
-from test_support import verbose
+from test_support import verify, verbose
import string_tests
# UserString is a wrapper around the native builtin string type.
# UserString instances should behave similar to builtin string objects.
diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py
index f3d5cdf..20df7de 100644
--- a/Lib/test/test_winreg.py
+++ b/Lib/test/test_winreg.py
@@ -31,11 +31,11 @@ def WriteTestData(root_key):
# Check we wrote as many items as we thought.
nkeys, nvalues, since_mod = QueryInfoKey(key)
- assert nkeys==1, "Not the correct number of sub keys"
- assert nvalues==1, "Not the correct number of values"
+ verify(nkeys==1, "Not the correct number of sub keys")
+ verify(nvalues==1, "Not the correct number of values")
nkeys, nvalues, since_mod = QueryInfoKey(sub_key)
- assert nkeys==0, "Not the correct number of sub keys"
- assert nvalues==len(test_data), "Not the correct number of values"
+ verify(nkeys==0, "Not the correct number of sub keys")
+ verify(nvalues==len(test_data), "Not the correct number of values")
# Close this key this way...
# (but before we do, copy the key as an integer - this allows
# us to test that the key really gets closed).
@@ -58,7 +58,7 @@ def WriteTestData(root_key):
def ReadTestData(root_key):
# Check we can get default value for this key.
val = QueryValue(root_key, test_key_name)
- assert val=="Default value", "Registry didn't give back the correct value"
+ verify(val=="Default value", "Registry didn't give back the correct value")
key = OpenKey(root_key, test_key_name)
# Read the sub-keys
@@ -70,21 +70,21 @@ def ReadTestData(root_key):
data = EnumValue(sub_key, index)
except EnvironmentError:
break
- assert data in test_data, "Didn't read back the correct test data"
+ verify(data in test_data, "Didn't read back the correct test data")
index = index + 1
- assert index==len(test_data), "Didn't read the correct number of items"
+ verify(index==len(test_data), "Didn't read the correct number of items")
# Check I can directly access each item
for value_name, value_data, value_type in test_data:
read_val, read_typ = QueryValueEx(sub_key, value_name)
- assert read_val==value_data and read_typ == value_type, \
- "Could not directly read the value"
+ verify(read_val==value_data and read_typ == value_type, \
+ "Could not directly read the value" )
sub_key.Close()
# Enumerate our main key.
read_val = EnumKey(key, 0)
- assert read_val == "sub_key", "Read subkey value wrong"
+ verify(read_val == "sub_key", "Read subkey value wrong")
try:
EnumKey(key, 1)
- assert 0, "Was able to get a second key when I only have one!"
+ verify(0, "Was able to get a second key when I only have one!")
except EnvironmentError:
pass
@@ -100,14 +100,14 @@ def DeleteTestData(root_key):
DeleteValue(sub_key, value_name)
nkeys, nvalues, since_mod = QueryInfoKey(sub_key)
- assert nkeys==0 and nvalues==0, "subkey not empty before delete"
+ verify(nkeys==0 and nvalues==0, "subkey not empty before delete")
sub_key.Close()
DeleteKey(key, "sub_key")
try:
# Shouldnt be able to delete it twice!
DeleteKey(key, "sub_key")
- assert 0, "Deleting the key twice succeeded"
+ verify(0, "Deleting the key twice succeeded")
except EnvironmentError:
pass
key.Close()
@@ -115,7 +115,7 @@ def DeleteTestData(root_key):
# Opening should now fail!
try:
key = OpenKey(root_key, test_key_name)
- assert 0, "Could open the non-existent key"
+ verify(0, "Could open the non-existent key")
except WindowsError: # Use this error name this time
pass
diff --git a/Lib/test/test_xmllib.py b/Lib/test/test_xmllib.py
index 62803b5..32f6b85 100644
--- a/Lib/test/test_xmllib.py
+++ b/Lib/test/test_xmllib.py
@@ -2,7 +2,7 @@
Sjoerd Mullender
'''
-from test_support import verbose
+from test_support import verify, verbose
testdoc = """\
<?xml version="1.0" encoding="UTF-8" standalone='yes' ?>