[Python-checkins] CVS: python/dist/src/Lib/test test_descr.py,1.1.2.2,1.1.2.3
Guido van Rossum
gvanrossum@users.sourceforge.net
Mon, 30 Apr 2001 09:44:58 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv25488
Modified Files:
Tag: descr-branch
test_descr.py
Log Message:
Add more tests: for dicts, ints, longs and floats.
The dicts test revealed a problem: DictType.__repr__ is the __repr__
for type objects, bound to DictType. This is surprising, since I
expected it to be the unbound __repr__ for dictionary objects!
Not sure how I'll fix this.
Index: test_descr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/Attic/test_descr.py,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -C2 -r1.1.2.2 -r1.1.2.3
*** test_descr.py 2001/04/29 22:17:01 1.1.2.2
--- test_descr.py 2001/04/30 16:44:56 1.1.2.3
***************
*** 85,101 ****
verify(dict['a'] == res)
! testbinop([1], [2], [1,2], "a+b", "__add__")
! testbinop([1,2,3], 2, 1, "b in a", "__contains__")
! testbinop([1,2,3], 4, 0, "b in a", "__contains__")
! testbinop([1,2,3], 1, 2, "a[b]", "__getitem__")
! testternop([1,2,3], 0, 2, [1,2], "a[b:c]", "__getslice__")
! testsetop([1], [2], [1,2], "a+=b", "__iadd__")
! testsetop([1,2], 3, [1,2,1,2,1,2], "a*=b", "__imul__")
! testunop([1,2,3], 3, "len(a)", "__len__")
! testbinop([1,2], 3, [1,2,1,2,1,2], "a*b", "__mul__")
! testbinop([1], [2], [2,1], "b+a", "__radd__")
! testbinop([1,2], 3, [1,2,1,2,1,2], "b*a", "__rmul__")
! testset2op([1,2], 1, 3, [1,3], "a[b]=c", "__setitem__")
! testset3op([1,2,3,4], 1, 3, [5,6], [1,5,6,4], "a[b:c]=d", "__setslice__")
! if verbose: print __name__, "OK"
--- 85,207 ----
verify(dict['a'] == res)
! def lists():
! if verbose: print "Testing list operations..."
! testbinop([1], [2], [1,2], "a+b", "__add__")
! testbinop([1,2,3], 2, 1, "b in a", "__contains__")
! testbinop([1,2,3], 4, 0, "b in a", "__contains__")
! testbinop([1,2,3], 1, 2, "a[b]", "__getitem__")
! testternop([1,2,3], 0, 2, [1,2], "a[b:c]", "__getslice__")
! testsetop([1], [2], [1,2], "a+=b", "__iadd__")
! testsetop([1,2], 3, [1,2,1,2,1,2], "a*=b", "__imul__")
! testunop([1,2,3], 3, "len(a)", "__len__")
! testbinop([1,2], 3, [1,2,1,2,1,2], "a*b", "__mul__")
! testbinop([1], [2], [2,1], "b+a", "__radd__")
! testbinop([1,2], 3, [1,2,1,2,1,2], "b*a", "__rmul__")
! testset2op([1,2], 1, 3, [1,3], "a[b]=c", "__setitem__")
! testset3op([1,2,3,4], 1, 3, [5,6], [1,5,6,4], "a[b:c]=d", "__setslice__")
! def dicts():
! if verbose: print "Testing dict operations..."
! testbinop({1:2}, {2:1}, -1, "cmp(a,b)", "__cmp__")
! testbinop({1:2,3:4}, 1, 1, "b in a", "__contains__")
! testbinop({1:2,3:4}, 2, 0, "b in a", "__contains__")
! testbinop({1:2,3:4}, 1, 2, "a[b]", "__getitem__")
! d = {1:2,3:4}
! l1 = []
! for i in d.keys(): l1.append(i)
! l = []
! for i in iter(d): l.append(i)
! verify(l == l1)
! l = []
! for i in d.__iter__(): l.append(i)
! verify(l == l1)
! l = []
! for i in type({}).__iter__(d): l.append(i)
! verify(l == l1)
! testunop({1:2,3:4}, 2, "len(a)", "__len__")
! ##testunop({1:2,3:4}, "{3: 4, 1: 2}", "repr(a)", "__repr__")
! testset2op({1:2,3:4}, 2, 3, {1:2,2:3,3:4}, "a[b]=c", "__setitem__")
!
! binops = {
! 'add': '+',
! 'sub': '-',
! 'mul': '*',
! 'div': '/',
! 'mod': '%',
! 'divmod': 'divmod',
! 'pow': '**',
! 'lshift': '<<',
! 'rshift': '>>',
! 'and': '&',
! 'xor': '^',
! 'or': '|',
! 'cmp': 'cmp',
! 'lt': '<',
! 'le': '<=',
! 'eq': '==',
! 'ne': '!=',
! 'gt': '>',
! 'ge': '>=',
! }
!
! for name, expr in binops.items():
! if expr.islower():
! expr = expr + "(a, b)"
! else:
! expr = 'a %s b' % expr
! binops[name] = expr
!
! unops = {
! 'pos': '+',
! 'neg': '-',
! 'abs': 'abs',
! 'invert': '~',
! 'int': 'int',
! 'long': 'long',
! 'float': 'float',
! 'oct': 'oct',
! 'hex': 'hex',
! }
!
! for name, expr in unops.items():
! if expr.islower():
! expr = expr + "(a)"
! else:
! expr = '%s a' % expr
! unops[name] = expr
!
! def numops(a, b):
! dict = {'a': a, 'b': b}
! for name, expr in binops.items():
! name = "__%s__" % name
! if hasattr(a, name):
! res = eval(expr, dict)
! testbinop(a, b, res, expr, name)
! for name, expr in unops.items():
! name = "__%s__" % name
! if hasattr(a, name):
! res = eval(expr, dict)
! testunop(a, res, expr, name)
!
! def ints():
! if verbose: print "Testing int operations..."
! numops(100, 3)
!
! def longs():
! if verbose: print "Testing long operations..."
! numops(100L, 3L)
!
! def floats():
! if verbose: print "Testing float operations..."
! numops(100.0, 3.0)
!
! def all():
! lists()
! dicts()
! ints()
! longs()
! floats()
!
! all()
!
! if verbose: print "All OK"