mirror of
https://github.com/python/cpython.git
synced 2025-08-18 15:51:23 +00:00
Merged revisions 77871,77910,77913 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r77871 | ezio.melotti | 2010-01-31 13:46:54 +0200 (Sun, 31 Jan 2010) | 1 line #7092: silence more -3 and -Wd warnings ........ r77910 | ezio.melotti | 2010-02-02 10:37:35 +0200 (Tue, 02 Feb 2010) | 1 line #7092: silence py3k warnings for bsddb. Patch by Florent Xicluna. ........ r77913 | ezio.melotti | 2010-02-02 19:34:37 +0200 (Tue, 02 Feb 2010) | 1 line #7092: Silence py3k warnings in test_exceptions and test_pep352. Patch by Florent Xicluna. ........
This commit is contained in:
parent
9c4fbdbc55
commit
38a5800cdc
15 changed files with 162 additions and 182 deletions
|
@ -332,7 +332,7 @@ class bsdTableDB :
|
||||||
except db.DBError, dberror:
|
except db.DBError, dberror:
|
||||||
if txn:
|
if txn:
|
||||||
txn.abort()
|
txn.abort()
|
||||||
if sys.version_info[0] < 3 :
|
if sys.version_info < (2, 6) :
|
||||||
raise TableDBError, dberror[1]
|
raise TableDBError, dberror[1]
|
||||||
else :
|
else :
|
||||||
raise TableDBError, dberror.args[1]
|
raise TableDBError, dberror.args[1]
|
||||||
|
@ -416,7 +416,7 @@ class bsdTableDB :
|
||||||
except db.DBError, dberror:
|
except db.DBError, dberror:
|
||||||
if txn:
|
if txn:
|
||||||
txn.abort()
|
txn.abort()
|
||||||
if sys.version_info[0] < 3 :
|
if sys.version_info < (2, 6) :
|
||||||
raise TableDBError, dberror[1]
|
raise TableDBError, dberror[1]
|
||||||
else :
|
else :
|
||||||
raise TableDBError, dberror.args[1]
|
raise TableDBError, dberror.args[1]
|
||||||
|
@ -499,7 +499,7 @@ class bsdTableDB :
|
||||||
if txn:
|
if txn:
|
||||||
txn.abort()
|
txn.abort()
|
||||||
self.db.delete(_rowid_key(table, rowid))
|
self.db.delete(_rowid_key(table, rowid))
|
||||||
if sys.version_info[0] < 3 :
|
if sys.version_info < (2, 6) :
|
||||||
raise TableDBError, dberror[1], info[2]
|
raise TableDBError, dberror[1], info[2]
|
||||||
else :
|
else :
|
||||||
raise TableDBError, dberror.args[1], info[2]
|
raise TableDBError, dberror.args[1], info[2]
|
||||||
|
@ -554,7 +554,7 @@ class bsdTableDB :
|
||||||
raise
|
raise
|
||||||
|
|
||||||
except db.DBError, dberror:
|
except db.DBError, dberror:
|
||||||
if sys.version_info[0] < 3 :
|
if sys.version_info < (2, 6) :
|
||||||
raise TableDBError, dberror[1]
|
raise TableDBError, dberror[1]
|
||||||
else :
|
else :
|
||||||
raise TableDBError, dberror.args[1]
|
raise TableDBError, dberror.args[1]
|
||||||
|
@ -598,7 +598,7 @@ class bsdTableDB :
|
||||||
txn.abort()
|
txn.abort()
|
||||||
raise
|
raise
|
||||||
except db.DBError, dberror:
|
except db.DBError, dberror:
|
||||||
if sys.version_info[0] < 3 :
|
if sys.version_info < (2, 6) :
|
||||||
raise TableDBError, dberror[1]
|
raise TableDBError, dberror[1]
|
||||||
else :
|
else :
|
||||||
raise TableDBError, dberror.args[1]
|
raise TableDBError, dberror.args[1]
|
||||||
|
@ -621,7 +621,7 @@ class bsdTableDB :
|
||||||
columns = self.__tablecolumns[table]
|
columns = self.__tablecolumns[table]
|
||||||
matching_rowids = self.__Select(table, columns, conditions)
|
matching_rowids = self.__Select(table, columns, conditions)
|
||||||
except db.DBError, dberror:
|
except db.DBError, dberror:
|
||||||
if sys.version_info[0] < 3 :
|
if sys.version_info < (2, 6) :
|
||||||
raise TableDBError, dberror[1]
|
raise TableDBError, dberror[1]
|
||||||
else :
|
else :
|
||||||
raise TableDBError, dberror.args[1]
|
raise TableDBError, dberror.args[1]
|
||||||
|
@ -677,7 +677,7 @@ class bsdTableDB :
|
||||||
# leave all unknown condition callables alone as equals
|
# leave all unknown condition callables alone as equals
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if sys.version_info[0] < 3 :
|
if sys.version_info < (2, 6) :
|
||||||
conditionlist = conditions.items()
|
conditionlist = conditions.items()
|
||||||
conditionlist.sort(cmp_conditions)
|
conditionlist.sort(cmp_conditions)
|
||||||
else : # Insertion Sort. Please, improve
|
else : # Insertion Sort. Please, improve
|
||||||
|
@ -749,7 +749,7 @@ class bsdTableDB :
|
||||||
rowdata[column] = self.db.get(
|
rowdata[column] = self.db.get(
|
||||||
_data_key(table, column, rowid))
|
_data_key(table, column, rowid))
|
||||||
except db.DBError, dberror:
|
except db.DBError, dberror:
|
||||||
if sys.version_info[0] < 3 :
|
if sys.version_info < (2, 6) :
|
||||||
if dberror[0] != db.DB_NOTFOUND:
|
if dberror[0] != db.DB_NOTFOUND:
|
||||||
raise
|
raise
|
||||||
else :
|
else :
|
||||||
|
|
|
@ -139,10 +139,6 @@ class BasicTestCase(unittest.TestCase):
|
||||||
try:
|
try:
|
||||||
d.delete('abcd')
|
d.delete('abcd')
|
||||||
except db.DBNotFoundError, val:
|
except db.DBNotFoundError, val:
|
||||||
import sys
|
|
||||||
if sys.version_info[0] < 3 :
|
|
||||||
self.assertEqual(val[0], db.DB_NOTFOUND)
|
|
||||||
else :
|
|
||||||
self.assertEqual(val.args[0], db.DB_NOTFOUND)
|
self.assertEqual(val.args[0], db.DB_NOTFOUND)
|
||||||
if verbose: print val
|
if verbose: print val
|
||||||
else:
|
else:
|
||||||
|
@ -162,10 +158,6 @@ class BasicTestCase(unittest.TestCase):
|
||||||
try:
|
try:
|
||||||
d.put('abcd', 'this should fail', flags=db.DB_NOOVERWRITE)
|
d.put('abcd', 'this should fail', flags=db.DB_NOOVERWRITE)
|
||||||
except db.DBKeyExistError, val:
|
except db.DBKeyExistError, val:
|
||||||
import sys
|
|
||||||
if sys.version_info[0] < 3 :
|
|
||||||
self.assertEqual(val[0], db.DB_KEYEXIST)
|
|
||||||
else :
|
|
||||||
self.assertEqual(val.args[0], db.DB_KEYEXIST)
|
self.assertEqual(val.args[0], db.DB_KEYEXIST)
|
||||||
if verbose: print val
|
if verbose: print val
|
||||||
else:
|
else:
|
||||||
|
@ -301,10 +293,6 @@ class BasicTestCase(unittest.TestCase):
|
||||||
rec = c.next()
|
rec = c.next()
|
||||||
except db.DBNotFoundError, val:
|
except db.DBNotFoundError, val:
|
||||||
if get_raises_error:
|
if get_raises_error:
|
||||||
import sys
|
|
||||||
if sys.version_info[0] < 3 :
|
|
||||||
self.assertEqual(val[0], db.DB_NOTFOUND)
|
|
||||||
else :
|
|
||||||
self.assertEqual(val.args[0], db.DB_NOTFOUND)
|
self.assertEqual(val.args[0], db.DB_NOTFOUND)
|
||||||
if verbose: print val
|
if verbose: print val
|
||||||
rec = None
|
rec = None
|
||||||
|
@ -326,10 +314,6 @@ class BasicTestCase(unittest.TestCase):
|
||||||
rec = c.prev()
|
rec = c.prev()
|
||||||
except db.DBNotFoundError, val:
|
except db.DBNotFoundError, val:
|
||||||
if get_raises_error:
|
if get_raises_error:
|
||||||
import sys
|
|
||||||
if sys.version_info[0] < 3 :
|
|
||||||
self.assertEqual(val[0], db.DB_NOTFOUND)
|
|
||||||
else :
|
|
||||||
self.assertEqual(val.args[0], db.DB_NOTFOUND)
|
self.assertEqual(val.args[0], db.DB_NOTFOUND)
|
||||||
if verbose: print val
|
if verbose: print val
|
||||||
rec = None
|
rec = None
|
||||||
|
@ -353,10 +337,6 @@ class BasicTestCase(unittest.TestCase):
|
||||||
try:
|
try:
|
||||||
n = c.set('bad key')
|
n = c.set('bad key')
|
||||||
except db.DBNotFoundError, val:
|
except db.DBNotFoundError, val:
|
||||||
import sys
|
|
||||||
if sys.version_info[0] < 3 :
|
|
||||||
self.assertEqual(val[0], db.DB_NOTFOUND)
|
|
||||||
else :
|
|
||||||
self.assertEqual(val.args[0], db.DB_NOTFOUND)
|
self.assertEqual(val.args[0], db.DB_NOTFOUND)
|
||||||
if verbose: print val
|
if verbose: print val
|
||||||
else:
|
else:
|
||||||
|
@ -371,10 +351,6 @@ class BasicTestCase(unittest.TestCase):
|
||||||
try:
|
try:
|
||||||
n = c.get_both('0404', 'bad data')
|
n = c.get_both('0404', 'bad data')
|
||||||
except db.DBNotFoundError, val:
|
except db.DBNotFoundError, val:
|
||||||
import sys
|
|
||||||
if sys.version_info[0] < 3 :
|
|
||||||
self.assertEqual(val[0], db.DB_NOTFOUND)
|
|
||||||
else :
|
|
||||||
self.assertEqual(val.args[0], db.DB_NOTFOUND)
|
self.assertEqual(val.args[0], db.DB_NOTFOUND)
|
||||||
if verbose: print val
|
if verbose: print val
|
||||||
else:
|
else:
|
||||||
|
@ -404,10 +380,6 @@ class BasicTestCase(unittest.TestCase):
|
||||||
rec = c.current()
|
rec = c.current()
|
||||||
except db.DBKeyEmptyError, val:
|
except db.DBKeyEmptyError, val:
|
||||||
if get_raises_error:
|
if get_raises_error:
|
||||||
import sys
|
|
||||||
if sys.version_info[0] < 3 :
|
|
||||||
self.assertEqual(val[0], db.DB_KEYEMPTY)
|
|
||||||
else :
|
|
||||||
self.assertEqual(val.args[0], db.DB_KEYEMPTY)
|
self.assertEqual(val.args[0], db.DB_KEYEMPTY)
|
||||||
if verbose: print val
|
if verbose: print val
|
||||||
else:
|
else:
|
||||||
|
@ -451,12 +423,8 @@ class BasicTestCase(unittest.TestCase):
|
||||||
print "attempting to use a closed cursor's %s method" % \
|
print "attempting to use a closed cursor's %s method" % \
|
||||||
method
|
method
|
||||||
# a bug may cause a NULL pointer dereference...
|
# a bug may cause a NULL pointer dereference...
|
||||||
apply(getattr(c, method), args)
|
getattr(c, method)(*args)
|
||||||
except db.DBError, val:
|
except db.DBError, val:
|
||||||
import sys
|
|
||||||
if sys.version_info[0] < 3 :
|
|
||||||
self.assertEqual(val[0], 0)
|
|
||||||
else :
|
|
||||||
self.assertEqual(val.args[0], 0)
|
self.assertEqual(val.args[0], 0)
|
||||||
if verbose: print val
|
if verbose: print val
|
||||||
else:
|
else:
|
||||||
|
@ -710,10 +678,10 @@ class BasicTransactionTestCase(BasicTestCase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
statDict = self.env.log_stat(0);
|
statDict = self.env.log_stat(0);
|
||||||
self.assert_(statDict.has_key('magic'))
|
self.assertTrue('magic' in statDict)
|
||||||
self.assert_(statDict.has_key('version'))
|
self.assertTrue('version' in statDict)
|
||||||
self.assert_(statDict.has_key('cur_file'))
|
self.assertTrue('cur_file' in statDict)
|
||||||
self.assert_(statDict.has_key('region_nowait'))
|
self.assertTrue('region_nowait' in statDict)
|
||||||
|
|
||||||
# must have at least one log file present:
|
# must have at least one log file present:
|
||||||
logs = self.env.log_archive(db.DB_ARCH_ABS | db.DB_ARCH_LOG)
|
logs = self.env.log_archive(db.DB_ARCH_ABS | db.DB_ARCH_LOG)
|
||||||
|
|
|
@ -30,7 +30,7 @@ class ComparatorTests (unittest.TestCase):
|
||||||
data = expected_data[:]
|
data = expected_data[:]
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
if sys.version_info[0] < 3 :
|
if sys.version_info[:3] < (2, 6, 0):
|
||||||
if sys.version_info[:3] < (2, 4, 0):
|
if sys.version_info[:3] < (2, 4, 0):
|
||||||
data.sort(comparator)
|
data.sort(comparator)
|
||||||
else :
|
else :
|
||||||
|
@ -47,7 +47,7 @@ class ComparatorTests (unittest.TestCase):
|
||||||
data2.append(i)
|
data2.append(i)
|
||||||
data = data2
|
data = data2
|
||||||
|
|
||||||
self.failUnless (data == expected_data,
|
self.assertEqual (data, expected_data,
|
||||||
"comparator `%s' is not right: %s vs. %s"
|
"comparator `%s' is not right: %s vs. %s"
|
||||||
% (comparator, expected_data, data))
|
% (comparator, expected_data, data))
|
||||||
def test_lexical_comparator (self):
|
def test_lexical_comparator (self):
|
||||||
|
@ -115,14 +115,14 @@ class AbstractBtreeKeyCompareTestCase (unittest.TestCase):
|
||||||
rec = curs.first ()
|
rec = curs.first ()
|
||||||
while rec:
|
while rec:
|
||||||
key, ignore = rec
|
key, ignore = rec
|
||||||
self.failUnless (index < len (expected),
|
self.assertTrue (index < len (expected),
|
||||||
"to many values returned from cursor")
|
"to many values returned from cursor")
|
||||||
self.failUnless (expected[index] == key,
|
self.assertEqual (expected[index], key,
|
||||||
"expected value `%s' at %d but got `%s'"
|
"expected value `%s' at %d but got `%s'"
|
||||||
% (expected[index], index, key))
|
% (expected[index], index, key))
|
||||||
index = index + 1
|
index = index + 1
|
||||||
rec = curs.next ()
|
rec = curs.next ()
|
||||||
self.failUnless (index == len (expected),
|
self.assertEqual (index, len (expected),
|
||||||
"not enough values returned from cursor")
|
"not enough values returned from cursor")
|
||||||
finally:
|
finally:
|
||||||
curs.close ()
|
curs.close ()
|
||||||
|
|
|
@ -27,7 +27,7 @@ class dbobjTestCase(unittest.TestCase):
|
||||||
def put(self, key, *args, **kwargs):
|
def put(self, key, *args, **kwargs):
|
||||||
key = key.upper()
|
key = key.upper()
|
||||||
# call our parent classes put method with an upper case key
|
# call our parent classes put method with an upper case key
|
||||||
return apply(dbobj.DB.put, (self, key) + args, kwargs)
|
return dbobj.DB.put(self, key, *args, **kwargs)
|
||||||
self.env = TestDBEnv()
|
self.env = TestDBEnv()
|
||||||
self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL)
|
self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL)
|
||||||
self.db = TestDB(self.env)
|
self.db = TestDB(self.env)
|
||||||
|
|
|
@ -5,6 +5,7 @@ TestCases for checking dbShelve objects.
|
||||||
import os, string
|
import os, string
|
||||||
import random
|
import random
|
||||||
import unittest
|
import unittest
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
|
||||||
from test_all import db, dbshelve, test_support, verbose, \
|
from test_all import db, dbshelve, test_support, verbose, \
|
||||||
|
@ -117,15 +118,11 @@ class DBShelveTestCase(unittest.TestCase):
|
||||||
|
|
||||||
dbvalues = d.values()
|
dbvalues = d.values()
|
||||||
self.assertEqual(len(dbvalues), len(d.keys()))
|
self.assertEqual(len(dbvalues), len(d.keys()))
|
||||||
import sys
|
with warnings.catch_warnings():
|
||||||
if sys.version_info[0] < 3 :
|
warnings.filterwarnings('ignore',
|
||||||
values.sort()
|
'comparing unequal types not supported',
|
||||||
dbvalues.sort()
|
DeprecationWarning)
|
||||||
self.assertEqual(values, dbvalues)
|
self.assertEqual(sorted(values), sorted(dbvalues))
|
||||||
else : # XXX: Convert all to strings. Please, improve
|
|
||||||
values.sort(key=lambda x : str(x))
|
|
||||||
dbvalues.sort(key=lambda x : str(x))
|
|
||||||
self.assertEqual(repr(values), repr(dbvalues))
|
|
||||||
|
|
||||||
items = d.items()
|
items = d.items()
|
||||||
self.assertEqual(len(items), len(values))
|
self.assertEqual(len(items), len(values))
|
||||||
|
|
|
@ -51,13 +51,13 @@ class JoinTestCase(unittest.TestCase):
|
||||||
# create and populate primary index
|
# create and populate primary index
|
||||||
priDB = db.DB(self.env)
|
priDB = db.DB(self.env)
|
||||||
priDB.open(self.filename, "primary", db.DB_BTREE, db.DB_CREATE)
|
priDB.open(self.filename, "primary", db.DB_BTREE, db.DB_CREATE)
|
||||||
map(lambda t, priDB=priDB: apply(priDB.put, t), ProductIndex)
|
map(lambda t, priDB=priDB: priDB.put(*t), ProductIndex)
|
||||||
|
|
||||||
# create and populate secondary index
|
# create and populate secondary index
|
||||||
secDB = db.DB(self.env)
|
secDB = db.DB(self.env)
|
||||||
secDB.set_flags(db.DB_DUP | db.DB_DUPSORT)
|
secDB.set_flags(db.DB_DUP | db.DB_DUPSORT)
|
||||||
secDB.open(self.filename, "secondary", db.DB_BTREE, db.DB_CREATE)
|
secDB.open(self.filename, "secondary", db.DB_BTREE, db.DB_CREATE)
|
||||||
map(lambda t, secDB=secDB: apply(secDB.put, t), ColorIndex)
|
map(lambda t, secDB=secDB: secDB.put(*t), ColorIndex)
|
||||||
|
|
||||||
sCursor = None
|
sCursor = None
|
||||||
jCursor = None
|
jCursor = None
|
||||||
|
|
|
@ -60,10 +60,6 @@ class SimpleRecnoTestCase(unittest.TestCase):
|
||||||
try:
|
try:
|
||||||
data = d[0] # This should raise a KeyError!?!?!
|
data = d[0] # This should raise a KeyError!?!?!
|
||||||
except db.DBInvalidArgError, val:
|
except db.DBInvalidArgError, val:
|
||||||
import sys
|
|
||||||
if sys.version_info[0] < 3 :
|
|
||||||
self.assertEqual(val[0], db.EINVAL)
|
|
||||||
else :
|
|
||||||
self.assertEqual(val.args[0], db.EINVAL)
|
self.assertEqual(val.args[0], db.EINVAL)
|
||||||
if verbose: print val
|
if verbose: print val
|
||||||
else:
|
else:
|
||||||
|
@ -269,10 +265,6 @@ class SimpleRecnoTestCase(unittest.TestCase):
|
||||||
try: # this one will fail
|
try: # this one will fail
|
||||||
d.append('bad' * 20)
|
d.append('bad' * 20)
|
||||||
except db.DBInvalidArgError, val:
|
except db.DBInvalidArgError, val:
|
||||||
import sys
|
|
||||||
if sys.version_info[0] < 3 :
|
|
||||||
self.assertEqual(val[0], db.EINVAL)
|
|
||||||
else :
|
|
||||||
self.assertEqual(val.args[0], db.EINVAL)
|
self.assertEqual(val.args[0], db.EINVAL)
|
||||||
if verbose: print val
|
if verbose: print val
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -172,7 +172,7 @@ def parse(fp=None, environ=os.environ, keep_blank_values=0, strict_parsing=0):
|
||||||
else:
|
else:
|
||||||
qs = ""
|
qs = ""
|
||||||
environ['QUERY_STRING'] = qs # XXX Shouldn't, really
|
environ['QUERY_STRING'] = qs # XXX Shouldn't, really
|
||||||
return parse_qs(qs, keep_blank_values, strict_parsing)
|
return urlparse.parse_qs(qs, keep_blank_values, strict_parsing)
|
||||||
|
|
||||||
|
|
||||||
# parse query string function called from urlparse,
|
# parse query string function called from urlparse,
|
||||||
|
|
|
@ -7,7 +7,13 @@ import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
from test.test_support import requires, verbose, run_unittest, unlink, rmtree
|
from test.test_support import (requires, verbose, run_unittest, unlink, rmtree,
|
||||||
|
import_module)
|
||||||
|
|
||||||
|
# Skip test if _bsddb module was not built.
|
||||||
|
import_module('_bsddb')
|
||||||
|
# Silence Py3k warning
|
||||||
|
import_module('bsddb', deprecated=True)
|
||||||
|
|
||||||
# When running as a script instead of within the regrtest framework, skip the
|
# When running as a script instead of within the regrtest framework, skip the
|
||||||
# requires test, since it's obvious we want to run them.
|
# requires test, since it's obvious we want to run them.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from test.test_support import run_unittest
|
from test.test_support import run_unittest, check_warnings
|
||||||
import cgi
|
import cgi
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
@ -102,11 +102,6 @@ parse_strict_test_cases = [
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
|
|
||||||
def norm(list):
|
|
||||||
if type(list) == type([]):
|
|
||||||
list.sort()
|
|
||||||
return list
|
|
||||||
|
|
||||||
def first_elts(list):
|
def first_elts(list):
|
||||||
return map(lambda x:x[0], list)
|
return map(lambda x:x[0], list)
|
||||||
|
|
||||||
|
@ -141,18 +136,18 @@ class CgiTests(unittest.TestCase):
|
||||||
if type(expect) == type({}):
|
if type(expect) == type({}):
|
||||||
# test dict interface
|
# test dict interface
|
||||||
self.assertEqual(len(expect), len(fcd))
|
self.assertEqual(len(expect), len(fcd))
|
||||||
self.assertEqual(norm(expect.keys()), norm(fcd.keys()))
|
self.assertEqual(sorted(expect.keys()), sorted(fcd.keys()))
|
||||||
self.assertEqual(norm(expect.values()), norm(fcd.values()))
|
self.assertEqual(sorted(expect.values()), sorted(fcd.values()))
|
||||||
self.assertEqual(norm(expect.items()), norm(fcd.items()))
|
self.assertEqual(sorted(expect.items()), sorted(fcd.items()))
|
||||||
self.assertEqual(fcd.get("nonexistent field", "default"), "default")
|
self.assertEqual(fcd.get("nonexistent field", "default"), "default")
|
||||||
self.assertEqual(len(sd), len(fs))
|
self.assertEqual(len(sd), len(fs))
|
||||||
self.assertEqual(norm(sd.keys()), norm(fs.keys()))
|
self.assertEqual(sorted(sd.keys()), sorted(fs.keys()))
|
||||||
self.assertEqual(fs.getvalue("nonexistent field", "default"), "default")
|
self.assertEqual(fs.getvalue("nonexistent field", "default"), "default")
|
||||||
# test individual fields
|
# test individual fields
|
||||||
for key in expect.keys():
|
for key in expect.keys():
|
||||||
expect_val = expect[key]
|
expect_val = expect[key]
|
||||||
self.assert_(fcd.has_key(key))
|
self.assert_(fcd.has_key(key))
|
||||||
self.assertEqual(norm(fcd[key]), norm(expect[key]))
|
self.assertEqual(sorted(fcd[key]), sorted(expect[key]))
|
||||||
self.assertEqual(fcd.get(key, "default"), fcd[key])
|
self.assertEqual(fcd.get(key, "default"), fcd[key])
|
||||||
self.assert_(fs.has_key(key))
|
self.assert_(fs.has_key(key))
|
||||||
if len(expect_val) > 1:
|
if len(expect_val) > 1:
|
||||||
|
@ -168,12 +163,12 @@ class CgiTests(unittest.TestCase):
|
||||||
self.assert_(single_value)
|
self.assert_(single_value)
|
||||||
self.assertEqual(val, expect_val[0])
|
self.assertEqual(val, expect_val[0])
|
||||||
self.assertEqual(fs.getvalue(key), expect_val[0])
|
self.assertEqual(fs.getvalue(key), expect_val[0])
|
||||||
self.assertEqual(norm(sd.getlist(key)), norm(expect_val))
|
self.assertEqual(sorted(sd.getlist(key)), sorted(expect_val))
|
||||||
if single_value:
|
if single_value:
|
||||||
self.assertEqual(norm(sd.values()),
|
self.assertEqual(sorted(sd.values()),
|
||||||
first_elts(norm(expect.values())))
|
sorted(first_elts(expect.values())))
|
||||||
self.assertEqual(norm(sd.items()),
|
self.assertEqual(sorted(sd.items()),
|
||||||
first_second_elts(norm(expect.items())))
|
sorted(first_second_elts(expect.items())))
|
||||||
|
|
||||||
def test_weird_formcontentdict(self):
|
def test_weird_formcontentdict(self):
|
||||||
# Test the weird FormContentDict classes
|
# Test the weird FormContentDict classes
|
||||||
|
@ -184,7 +179,7 @@ class CgiTests(unittest.TestCase):
|
||||||
self.assertEqual(d[k], v)
|
self.assertEqual(d[k], v)
|
||||||
for k, v in d.items():
|
for k, v in d.items():
|
||||||
self.assertEqual(expect[k], v)
|
self.assertEqual(expect[k], v)
|
||||||
self.assertEqual(norm(expect.values()), norm(d.values()))
|
self.assertEqual(sorted(expect.values()), sorted(d.values()))
|
||||||
|
|
||||||
def test_log(self):
|
def test_log(self):
|
||||||
cgi.log("Testing")
|
cgi.log("Testing")
|
||||||
|
@ -345,11 +340,13 @@ this is the content of the fake file
|
||||||
self.assertEqual(result, v)
|
self.assertEqual(result, v)
|
||||||
|
|
||||||
def test_deprecated_parse_qs(self):
|
def test_deprecated_parse_qs(self):
|
||||||
|
with check_warnings():
|
||||||
# this func is moved to urlparse, this is just a sanity check
|
# this func is moved to urlparse, this is just a sanity check
|
||||||
self.assertEqual({'a': ['A1'], 'B': ['B3'], 'b': ['B2']},
|
self.assertEqual({'a': ['A1'], 'B': ['B3'], 'b': ['B2']},
|
||||||
cgi.parse_qs('a=A1&b=B2&B=B3'))
|
cgi.parse_qs('a=A1&b=B2&B=B3'))
|
||||||
|
|
||||||
def test_deprecated_parse_qsl(self):
|
def test_deprecated_parse_qsl(self):
|
||||||
|
with check_warnings():
|
||||||
# this func is moved to urlparse, this is just a sanity check
|
# this func is moved to urlparse, this is just a sanity check
|
||||||
self.assertEqual([('a', 'A1'), ('b', 'B2'), ('B', 'B3')],
|
self.assertEqual([('a', 'A1'), ('b', 'B2'), ('B', 'B3')],
|
||||||
cgi.parse_qsl('a=A1&b=B2&B=B3'))
|
cgi.parse_qsl('a=A1&b=B2&B=B3'))
|
||||||
|
|
|
@ -223,8 +223,10 @@ def process_infix_results():
|
||||||
infix_results[key] = res
|
infix_results[key] = res
|
||||||
|
|
||||||
|
|
||||||
|
with warnings.catch_warnings():
|
||||||
process_infix_results()
|
warnings.filterwarnings("ignore", "classic int division",
|
||||||
|
DeprecationWarning)
|
||||||
|
process_infix_results()
|
||||||
# now infix_results has two lists of results for every pairing.
|
# now infix_results has two lists of results for every pairing.
|
||||||
|
|
||||||
prefix_binops = [ 'divmod' ]
|
prefix_binops = [ 'divmod' ]
|
||||||
|
@ -337,10 +339,11 @@ class CoercionTest(unittest.TestCase):
|
||||||
raise exc
|
raise exc
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
warnings.filterwarnings("ignore",
|
with warnings.catch_warnings():
|
||||||
r'complex divmod\(\), // and % are deprecated',
|
warnings.filterwarnings("ignore", "complex divmod.., // and % "
|
||||||
DeprecationWarning,
|
"are deprecated", DeprecationWarning)
|
||||||
r'test.test_coercion$')
|
warnings.filterwarnings("ignore", "classic (int|long) division",
|
||||||
|
DeprecationWarning)
|
||||||
run_unittest(CoercionTest)
|
run_unittest(CoercionTest)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -7,9 +7,14 @@ be run.
|
||||||
|
|
||||||
import distutils.tests
|
import distutils.tests
|
||||||
import test.test_support
|
import test.test_support
|
||||||
|
import warnings
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
|
with warnings.catch_warnings():
|
||||||
|
warnings.filterwarnings("ignore",
|
||||||
|
"distutils.sysconfig.\w+ is deprecated",
|
||||||
|
DeprecationWarning)
|
||||||
test.test_support.run_unittest(distutils.tests.test_suite())
|
test.test_support.run_unittest(distutils.tests.test_suite())
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import pickle, cPickle
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
from test.test_support import TESTFN, unlink, run_unittest, captured_output
|
from test.test_support import TESTFN, unlink, run_unittest, captured_output
|
||||||
from test.test_pep352 import ignore_message_warning
|
from test.test_pep352 import ignore_deprecation_warnings
|
||||||
|
|
||||||
# XXX This is not really enough, each *operation* should be tested!
|
# XXX This is not really enough, each *operation* should be tested!
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ class ExceptionTests(unittest.TestCase):
|
||||||
# Reloading the built-in exceptions module failed prior to Py2.2, while it
|
# Reloading the built-in exceptions module failed prior to Py2.2, while it
|
||||||
# should act the same as reloading built-in sys.
|
# should act the same as reloading built-in sys.
|
||||||
try:
|
try:
|
||||||
|
from imp import reload
|
||||||
import exceptions
|
import exceptions
|
||||||
reload(exceptions)
|
reload(exceptions)
|
||||||
except ImportError, e:
|
except ImportError, e:
|
||||||
|
@ -108,11 +109,11 @@ class ExceptionTests(unittest.TestCase):
|
||||||
self.assertRaises(ValueError, chr, 10000)
|
self.assertRaises(ValueError, chr, 10000)
|
||||||
|
|
||||||
self.raise_catch(ZeroDivisionError, "ZeroDivisionError")
|
self.raise_catch(ZeroDivisionError, "ZeroDivisionError")
|
||||||
try: x = 1/0
|
try: x = 1 // 0
|
||||||
except ZeroDivisionError: pass
|
except ZeroDivisionError: pass
|
||||||
|
|
||||||
self.raise_catch(Exception, "Exception")
|
self.raise_catch(Exception, "Exception")
|
||||||
try: x = 1/0
|
try: x = 1 // 0
|
||||||
except Exception, e: pass
|
except Exception, e: pass
|
||||||
|
|
||||||
def testSyntaxErrorMessage(self):
|
def testSyntaxErrorMessage(self):
|
||||||
|
@ -197,6 +198,7 @@ class ExceptionTests(unittest.TestCase):
|
||||||
self.failUnlessEqual(WindowsError(1001, "message").errno, 22)
|
self.failUnlessEqual(WindowsError(1001, "message").errno, 22)
|
||||||
self.failUnlessEqual(WindowsError(1001, "message").winerror, 1001)
|
self.failUnlessEqual(WindowsError(1001, "message").winerror, 1001)
|
||||||
|
|
||||||
|
@ignore_deprecation_warnings
|
||||||
def testAttributes(self):
|
def testAttributes(self):
|
||||||
# test that exception attributes are happy
|
# test that exception attributes are happy
|
||||||
|
|
||||||
|
@ -274,8 +276,6 @@ class ExceptionTests(unittest.TestCase):
|
||||||
except NameError:
|
except NameError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
with warnings.catch_warnings():
|
|
||||||
ignore_message_warning()
|
|
||||||
for exc, args, expected in exceptionList:
|
for exc, args, expected in exceptionList:
|
||||||
try:
|
try:
|
||||||
raise exc(*args)
|
raise exc(*args)
|
||||||
|
@ -329,6 +329,7 @@ class ExceptionTests(unittest.TestCase):
|
||||||
del exc.message
|
del exc.message
|
||||||
self.assertRaises(AttributeError, getattr, exc, "message")
|
self.assertRaises(AttributeError, getattr, exc, "message")
|
||||||
|
|
||||||
|
@ignore_deprecation_warnings
|
||||||
def testPickleMessageAttribute(self):
|
def testPickleMessageAttribute(self):
|
||||||
# Pickling with message attribute must work, as well.
|
# Pickling with message attribute must work, as well.
|
||||||
e = Exception("foo")
|
e = Exception("foo")
|
||||||
|
@ -336,18 +337,18 @@ class ExceptionTests(unittest.TestCase):
|
||||||
f.message = "bar"
|
f.message = "bar"
|
||||||
for p in pickle, cPickle:
|
for p in pickle, cPickle:
|
||||||
ep = p.loads(p.dumps(e))
|
ep = p.loads(p.dumps(e))
|
||||||
with warnings.catch_warnings():
|
|
||||||
ignore_message_warning()
|
|
||||||
self.assertEqual(ep.message, "foo")
|
self.assertEqual(ep.message, "foo")
|
||||||
fp = p.loads(p.dumps(f))
|
fp = p.loads(p.dumps(f))
|
||||||
self.assertEqual(fp.message, "bar")
|
self.assertEqual(fp.message, "bar")
|
||||||
|
|
||||||
|
@ignore_deprecation_warnings
|
||||||
def testSlicing(self):
|
def testSlicing(self):
|
||||||
# Test that you can slice an exception directly instead of requiring
|
# Test that you can slice an exception directly instead of requiring
|
||||||
# going through the 'args' attribute.
|
# going through the 'args' attribute.
|
||||||
args = (1, 2, 3)
|
args = (1, 2, 3)
|
||||||
exc = BaseException(*args)
|
exc = BaseException(*args)
|
||||||
self.failUnlessEqual(exc[:], args)
|
self.failUnlessEqual(exc[:], args)
|
||||||
|
self.assertEqual(exc.args[:], args)
|
||||||
|
|
||||||
def testKeywordArgs(self):
|
def testKeywordArgs(self):
|
||||||
# test that builtin exception don't take keyword args,
|
# test that builtin exception don't take keyword args,
|
||||||
|
|
|
@ -4,14 +4,27 @@ import exceptions
|
||||||
import warnings
|
import warnings
|
||||||
from test.test_support import run_unittest
|
from test.test_support import run_unittest
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
from platform import system as platform_system
|
from platform import system as platform_system
|
||||||
|
|
||||||
def ignore_message_warning():
|
DEPRECATION_WARNINGS = ["BaseException.message has been deprecated"]
|
||||||
"""Ignore the DeprecationWarning for BaseException.message."""
|
|
||||||
warnings.resetwarnings()
|
|
||||||
warnings.filterwarnings("ignore", "BaseException.message",
|
|
||||||
DeprecationWarning)
|
|
||||||
|
|
||||||
|
if sys.py3kwarning:
|
||||||
|
DEPRECATION_WARNINGS.extend(
|
||||||
|
["exceptions must derive from BaseException",
|
||||||
|
"catching classes that don't inherit from BaseException is not allowed",
|
||||||
|
"__get(item|slice)__ not supported for exception classes"])
|
||||||
|
|
||||||
|
# Silence Py3k and other deprecation warnings
|
||||||
|
def ignore_deprecation_warnings(func):
|
||||||
|
"""Ignore the known DeprecationWarnings."""
|
||||||
|
def wrapper(*args, **kw):
|
||||||
|
with warnings.catch_warnings():
|
||||||
|
warnings.resetwarnings()
|
||||||
|
for text in DEPRECATION_WARNINGS:
|
||||||
|
warnings.filterwarnings("ignore", text, DeprecationWarning)
|
||||||
|
return func(*args, **kw)
|
||||||
|
return wrapper
|
||||||
|
|
||||||
class ExceptionClassTests(unittest.TestCase):
|
class ExceptionClassTests(unittest.TestCase):
|
||||||
|
|
||||||
|
@ -21,12 +34,10 @@ class ExceptionClassTests(unittest.TestCase):
|
||||||
def test_builtins_new_style(self):
|
def test_builtins_new_style(self):
|
||||||
self.failUnless(issubclass(Exception, object))
|
self.failUnless(issubclass(Exception, object))
|
||||||
|
|
||||||
|
@ignore_deprecation_warnings
|
||||||
def verify_instance_interface(self, ins):
|
def verify_instance_interface(self, ins):
|
||||||
with warnings.catch_warnings():
|
for attr in ("args", "message", "__str__", "__repr__", "__getitem__"):
|
||||||
ignore_message_warning()
|
self.assertTrue(hasattr(ins, attr),
|
||||||
for attr in ("args", "message", "__str__", "__repr__",
|
|
||||||
"__getitem__"):
|
|
||||||
self.failUnless(hasattr(ins, attr),
|
|
||||||
"%s missing %s attribute" %
|
"%s missing %s attribute" %
|
||||||
(ins.__class__.__name__, attr))
|
(ins.__class__.__name__, attr))
|
||||||
|
|
||||||
|
@ -91,26 +102,23 @@ class ExceptionClassTests(unittest.TestCase):
|
||||||
self.failUnlessEqual(given, expected, "%s: %s != %s" % (test_name,
|
self.failUnlessEqual(given, expected, "%s: %s != %s" % (test_name,
|
||||||
given, expected))
|
given, expected))
|
||||||
|
|
||||||
|
@ignore_deprecation_warnings
|
||||||
def test_interface_single_arg(self):
|
def test_interface_single_arg(self):
|
||||||
# Make sure interface works properly when given a single argument
|
# Make sure interface works properly when given a single argument
|
||||||
arg = "spam"
|
arg = "spam"
|
||||||
exc = Exception(arg)
|
exc = Exception(arg)
|
||||||
with warnings.catch_warnings():
|
results = ([len(exc.args), 1], [exc.args[0], arg], [exc.message, arg],
|
||||||
ignore_message_warning()
|
|
||||||
results = ([len(exc.args), 1], [exc.args[0], arg],
|
|
||||||
[exc.message, arg],
|
|
||||||
[str(exc), str(arg)], [unicode(exc), unicode(arg)],
|
[str(exc), str(arg)], [unicode(exc), unicode(arg)],
|
||||||
[repr(exc), exc.__class__.__name__ + repr(exc.args)], [exc[0],
|
[repr(exc), exc.__class__.__name__ + repr(exc.args)],
|
||||||
arg])
|
[exc[0], arg])
|
||||||
self.interface_test_driver(results)
|
self.interface_test_driver(results)
|
||||||
|
|
||||||
|
@ignore_deprecation_warnings
|
||||||
def test_interface_multi_arg(self):
|
def test_interface_multi_arg(self):
|
||||||
# Make sure interface correct when multiple arguments given
|
# Make sure interface correct when multiple arguments given
|
||||||
arg_count = 3
|
arg_count = 3
|
||||||
args = tuple(range(arg_count))
|
args = tuple(range(arg_count))
|
||||||
exc = Exception(*args)
|
exc = Exception(*args)
|
||||||
with warnings.catch_warnings():
|
|
||||||
ignore_message_warning()
|
|
||||||
results = ([len(exc.args), arg_count], [exc.args, args],
|
results = ([len(exc.args), arg_count], [exc.args, args],
|
||||||
[exc.message, ''], [str(exc), str(args)],
|
[exc.message, ''], [str(exc), str(args)],
|
||||||
[unicode(exc), unicode(args)],
|
[unicode(exc), unicode(args)],
|
||||||
|
@ -118,11 +126,10 @@ class ExceptionClassTests(unittest.TestCase):
|
||||||
[exc[-1], args[-1]])
|
[exc[-1], args[-1]])
|
||||||
self.interface_test_driver(results)
|
self.interface_test_driver(results)
|
||||||
|
|
||||||
|
@ignore_deprecation_warnings
|
||||||
def test_interface_no_arg(self):
|
def test_interface_no_arg(self):
|
||||||
# Make sure that with no args that interface is correct
|
# Make sure that with no args that interface is correct
|
||||||
exc = Exception()
|
exc = Exception()
|
||||||
with warnings.catch_warnings():
|
|
||||||
ignore_message_warning()
|
|
||||||
results = ([len(exc.args), 0], [exc.args, tuple()],
|
results = ([len(exc.args), 0], [exc.args, tuple()],
|
||||||
[exc.message, ''],
|
[exc.message, ''],
|
||||||
[str(exc), ''], [unicode(exc), u''],
|
[str(exc), ''], [unicode(exc), u''],
|
||||||
|
@ -179,6 +186,7 @@ class UsageTests(unittest.TestCase):
|
||||||
self.fail("TypeError expected when catching %s as specified in a "
|
self.fail("TypeError expected when catching %s as specified in a "
|
||||||
"tuple" % type(object_))
|
"tuple" % type(object_))
|
||||||
|
|
||||||
|
@ignore_deprecation_warnings
|
||||||
def test_raise_classic(self):
|
def test_raise_classic(self):
|
||||||
# Raising a classic class is okay (for now).
|
# Raising a classic class is okay (for now).
|
||||||
class ClassicClass:
|
class ClassicClass:
|
||||||
|
@ -194,7 +202,7 @@ class UsageTests(unittest.TestCase):
|
||||||
except ClassicClass:
|
except ClassicClass:
|
||||||
pass
|
pass
|
||||||
except:
|
except:
|
||||||
self.fail("unable to raise class class instance")
|
self.fail("unable to raise classic class instance")
|
||||||
|
|
||||||
def test_raise_new_style_non_exception(self):
|
def test_raise_new_style_non_exception(self):
|
||||||
# You cannot raise a new-style class that does not inherit from
|
# You cannot raise a new-style class that does not inherit from
|
||||||
|
|
|
@ -136,7 +136,10 @@ class MutableStringTest(UserStringTest):
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
with warnings.catch_warnings():
|
with warnings.catch_warnings():
|
||||||
warnings.filterwarnings("ignore", ".*MutableString",
|
warnings.filterwarnings("ignore", ".*MutableString has been removed",
|
||||||
|
DeprecationWarning)
|
||||||
|
warnings.filterwarnings("ignore",
|
||||||
|
".*__(get|set|del)slice__ has been removed",
|
||||||
DeprecationWarning)
|
DeprecationWarning)
|
||||||
test_support.run_unittest(UserStringTest, MutableStringTest)
|
test_support.run_unittest(UserStringTest, MutableStringTest)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue