[Python-checkins] python/dist/src/Lib/test test___all__.py,1.30,1.31 test_builtin.py,1.19,1.20 test_glob.py,1.4,1.5 test_pyclbr.py,1.17,1.18 test_userdict.py,1.15,1.16 test_weakref.py,1.23,1.24
rhettinger@users.sourceforge.net
rhettinger@users.sourceforge.net
Fri, 02 May 2003 02:06:36 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv14447
Modified Files:
test___all__.py test_builtin.py test_glob.py test_pyclbr.py
test_userdict.py test_weakref.py
Log Message:
Used sets.Set() to compare unordered sequences.
Improves clarity and brevity.
Index: test___all__.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test___all__.py,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** test___all__.py 1 May 2003 17:45:31 -0000 1.30
--- test___all__.py 2 May 2003 09:06:23 -0000 1.31
***************
*** 3,6 ****
--- 3,7 ----
from test.test_support import verify, verbose
+ from sets import Set
import sys
import warnings
***************
*** 43,50 ****
if names.has_key("__builtins__"):
del names["__builtins__"]
! keys = names.keys()
! keys.sort()
! all = list(sys.modules[modname].__all__) # in case it's a tuple
! all.sort()
verify(keys==all, "%s != %s" % (keys, all))
--- 44,49 ----
if names.has_key("__builtins__"):
del names["__builtins__"]
! keys = Set(names)
! all = Set(sys.modules[modname].__all__)
verify(keys==all, "%s != %s" % (keys, all))
Index: test_builtin.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_builtin.py,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** test_builtin.py 1 May 2003 17:45:33 -0000 1.19
--- test_builtin.py 2 May 2003 09:06:25 -0000 1.20
***************
*** 3,6 ****
--- 3,7 ----
import test.test_support, unittest
from test.test_support import fcmp, have_unicode, TESTFN, unlink
+ from sets import Set
import sys, warnings, cStringIO
***************
*** 1160,1175 ****
def test_vars(self):
! a = b = None
! a = vars().keys()
! b = dir()
! a.sort()
! b.sort()
! self.assertEqual(a, b)
import sys
! a = vars(sys).keys()
! b = dir(sys)
! a.sort()
! b.sort()
! self.assertEqual(a, b)
self.assertEqual(self.get_vars_f0(), {})
self.assertEqual(self.get_vars_f2(), {'a': 1, 'b': 2})
--- 1161,1167 ----
def test_vars(self):
! self.assertEqual(Set(vars()), Set(dir()))
import sys
! self.assertEqual(Set(vars(sys)), Set(dir(sys)))
self.assertEqual(self.get_vars_f0(), {})
self.assertEqual(self.get_vars_f2(), {'a': 1, 'b': 2})
Index: test_glob.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_glob.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** test_glob.py 23 Jul 2002 19:03:54 -0000 1.4
--- test_glob.py 2 May 2003 09:06:26 -0000 1.5
***************
*** 3,6 ****
--- 3,7 ----
import glob
import os
+ from sets import Set
def mkdirs(fname):
***************
*** 62,70 ****
def assertSequencesEqual_noorder(self, l1, l2):
! l1 = list(l1)
! l2 = list(l2)
! l1.sort()
! l2.sort()
! self.assertEqual(l1, l2)
def test_glob_literal(self):
--- 63,67 ----
def assertSequencesEqual_noorder(self, l1, l2):
! self.assertEqual(Set(l1), Set(l2))
def test_glob_literal(self):
Index: test_pyclbr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_pyclbr.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** test_pyclbr.py 30 Dec 2002 07:21:32 -0000 1.17
--- test_pyclbr.py 2 May 2003 09:06:26 -0000 1.18
***************
*** 8,11 ****
--- 8,12 ----
import pyclbr
from unittest import TestCase
+ from sets import Set
# This next line triggers an error on old versions of pyclbr.
***************
*** 24,38 ****
def assertListEq(self, l1, l2, ignore):
''' succeed iff {l1} - {ignore} == {l2} - {ignore} '''
! l1.sort()
! l2.sort()
! try:
! for p1, p2 in (l1, l2), (l2, l1):
! for item in p1:
! ok = (item in p2) or (item in ignore)
! if not ok:
! self.fail("%r missing" % item)
! except:
print >>sys.stderr, "l1=%r\nl2=%r\nignore=%r" % (l1, l2, ignore)
! raise
def assertHasattr(self, obj, attr, ignore):
--- 25,32 ----
def assertListEq(self, l1, l2, ignore):
''' succeed iff {l1} - {ignore} == {l2} - {ignore} '''
! missing = (Set(l1) ^ Set(l2)) - Set(ignore)
! if missing:
print >>sys.stderr, "l1=%r\nl2=%r\nignore=%r" % (l1, l2, ignore)
! self.fail("%r missing" % missing.pop())
def assertHasattr(self, obj, attr, ignore):
Index: test_userdict.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_userdict.py,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** test_userdict.py 1 May 2003 17:45:54 -0000 1.15
--- test_userdict.py 2 May 2003 09:06:27 -0000 1.16
***************
*** 2,5 ****
--- 2,6 ----
import test.test_support, unittest
+ from sets import Set
import UserDict
***************
*** 69,76 ****
self.assert_(hasattr(iter, '__iter__'))
x = list(iter)
! x.sort()
! lst.sort()
! ref.sort()
! self.assert_(x==lst==ref)
check_iterandlist(d.iterkeys(), d.keys(), self.reference.keys())
check_iterandlist(iter(d), d.keys(), self.reference.keys())
--- 70,74 ----
self.assert_(hasattr(iter, '__iter__'))
x = list(iter)
! self.assert_(Set(x)==Set(lst)==Set(ref))
check_iterandlist(d.iterkeys(), d.keys(), self.reference.keys())
check_iterandlist(iter(d), d.keys(), self.reference.keys())
***************
*** 244,251 ****
for k in u2:
ikeys.append(k)
- ikeys.sort()
keys = u2.keys()
! keys.sort()
! self.assertEqual(ikeys, keys)
# Test setdefault
--- 242,247 ----
for k in u2:
ikeys.append(k)
keys = u2.keys()
! self.assertEqual(Set(ikeys), Set(keys))
# Test setdefault
Index: test_weakref.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_weakref.py,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** test_weakref.py 1 May 2003 17:45:55 -0000 1.23
--- test_weakref.py 2 May 2003 09:06:28 -0000 1.24
***************
*** 5,8 ****
--- 5,9 ----
from test import test_support
+ from sets import Set
***************
*** 341,347 ****
items1 = dict.items()
items2 = dict.copy().items()
! items1.sort()
! items2.sort()
! self.assert_(items1 == items2,
"cloning of weak-keyed dictionary did not work!")
del items1, items2
--- 342,346 ----
items1 = dict.items()
items2 = dict.copy().items()
! self.assert_(Set(items1) == Set(items2),
"cloning of weak-keyed dictionary did not work!")
del items1, items2