From 4570455813b2fca60a659b1ac0aa324e28f87619 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Mon, 8 Oct 2001 16:35:45 +0000 Subject: [PATCH] Change all occurrences of verify(x == y) into vereq(x, y), since when this type of test fails, vereq() does a better job of reporting than verify(). Change vereq(x, y) to use "not x == y" rather than "x != y" -- it makes a difference is some overloading tests. --- Lib/test/test_descr.py | 750 +++++++++++++++++++++-------------------- 1 file changed, 376 insertions(+), 374 deletions(-) diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index a6d527ec106..25232f357a6 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -4,95 +4,95 @@ from test_support import verify, verbose, TestFailed, TESTFN from copy import deepcopy def vereq(a, b): - if a != b: - raise TestFailed, "%r != %r" % (a, b) + if not (a == b): + raise TestFailed, "%r == %r" % (a, b) def testunop(a, res, expr="len(a)", meth="__len__"): if verbose: print "checking", expr dict = {'a': a} - verify(eval(expr, dict) == res) + vereq(eval(expr, dict), res) t = type(a) m = getattr(t, meth) - verify(m == t.__dict__[meth]) - verify(m(a) == res) + vereq(m, t.__dict__[meth]) + vereq(m(a), res) bm = getattr(a, meth) - verify(bm() == res) + vereq(bm(), res) def testbinop(a, b, res, expr="a+b", meth="__add__"): if verbose: print "checking", expr dict = {'a': a, 'b': b} - verify(eval(expr, dict) == res) + vereq(eval(expr, dict), res) t = type(a) m = getattr(t, meth) - verify(m == t.__dict__[meth]) - verify(m(a, b) == res) + vereq(m, t.__dict__[meth]) + vereq(m(a, b), res) bm = getattr(a, meth) - verify(bm(b) == res) + vereq(bm(b), res) def testternop(a, b, c, res, expr="a[b:c]", meth="__getslice__"): if verbose: print "checking", expr dict = {'a': a, 'b': b, 'c': c} - verify(eval(expr, dict) == res) + vereq(eval(expr, dict), res) t = type(a) m = getattr(t, meth) - verify(m == t.__dict__[meth]) - verify(m(a, b, c) == res) + vereq(m, t.__dict__[meth]) + vereq(m(a, b, c), res) bm = getattr(a, meth) - verify(bm(b, c) == res) + vereq(bm(b, c), res) def testsetop(a, b, res, stmt="a+=b", meth="__iadd__"): if verbose: print "checking", stmt dict = {'a': deepcopy(a), 'b': b} exec stmt in dict - verify(dict['a'] == res) + vereq(dict['a'], res) t = type(a) m = getattr(t, meth) - verify(m == t.__dict__[meth]) + vereq(m, t.__dict__[meth]) dict['a'] = deepcopy(a) m(dict['a'], b) - verify(dict['a'] == res) + vereq(dict['a'], res) dict['a'] = deepcopy(a) bm = getattr(dict['a'], meth) bm(b) - verify(dict['a'] == res) + vereq(dict['a'], res) def testset2op(a, b, c, res, stmt="a[b]=c", meth="__setitem__"): if verbose: print "checking", stmt dict = {'a': deepcopy(a), 'b': b, 'c': c} exec stmt in dict - verify(dict['a'] == res) + vereq(dict['a'], res) t = type(a) m = getattr(t, meth) - verify(m == t.__dict__[meth]) + vereq(m, t.__dict__[meth]) dict['a'] = deepcopy(a) m(dict['a'], b, c) - verify(dict['a'] == res) + vereq(dict['a'], res) dict['a'] = deepcopy(a) bm = getattr(dict['a'], meth) bm(b, c) - verify(dict['a'] == res) + vereq(dict['a'], res) def testset3op(a, b, c, d, res, stmt="a[b:c]=d", meth="__setslice__"): if verbose: print "checking", stmt dict = {'a': deepcopy(a), 'b': b, 'c': c, 'd': d} exec stmt in dict - verify(dict['a'] == res) + vereq(dict['a'], res) t = type(a) m = getattr(t, meth) - verify(m == t.__dict__[meth]) + vereq(m, t.__dict__[meth]) dict['a'] = deepcopy(a) m(dict['a'], b, c, d) - verify(dict['a'] == res) + vereq(dict['a'], res) dict['a'] = deepcopy(a) bm = getattr(dict['a'], meth) bm(b, c, d) - verify(dict['a'] == res) + vereq(dict['a'], res) def class_docstrings(): class Classic: "A classic docstring." - verify(Classic.__doc__ == "A classic docstring.") - verify(Classic.__dict__['__doc__'] == "A classic docstring.") + vereq(Classic.__doc__, "A classic docstring.") + vereq(Classic.__dict__['__doc__'], "A classic docstring.") class Classic2: pass @@ -101,8 +101,8 @@ def class_docstrings(): class NewStatic(object): "Another docstring." __dynamic__ = 0 - verify(NewStatic.__doc__ == "Another docstring.") - verify(NewStatic.__dict__['__doc__'] == "Another docstring.") + vereq(NewStatic.__doc__, "Another docstring.") + vereq(NewStatic.__dict__['__doc__'], "Another docstring.") class NewStatic2(object): __dynamic__ = 0 @@ -112,8 +112,8 @@ def class_docstrings(): class NewDynamic(object): "Another docstring." __dynamic__ = 1 - verify(NewDynamic.__doc__ == "Another docstring.") - verify(NewDynamic.__dict__['__doc__'] == "Another docstring.") + vereq(NewDynamic.__doc__, "Another docstring.") + vereq(NewDynamic.__dict__['__doc__'], "Another docstring.") class NewDynamic2(object): __dynamic__ = 1 @@ -146,30 +146,30 @@ def dicts(): for i in d.keys(): l1.append(i) l = [] for i in iter(d): l.append(i) - verify(l == l1) + vereq(l, l1) l = [] for i in d.__iter__(): l.append(i) - verify(l == l1) + vereq(l, l1) l = [] for i in dictionary.__iter__(d): l.append(i) - verify(l == l1) + vereq(l, l1) d = {1:2, 3:4} testunop(d, 2, "len(a)", "__len__") - verify(eval(repr(d), {}) == d) - verify(eval(d.__repr__(), {}) == d) + vereq(eval(repr(d), {}), d) + vereq(eval(d.__repr__(), {}), d) testset2op({1:2,3:4}, 2, 3, {1:2,2:3,3:4}, "a[b]=c", "__setitem__") def dict_constructor(): if verbose: print "Testing dictionary constructor ..." d = dictionary() - verify(d == {}) + vereq(d, {}) d = dictionary({}) - verify(d == {}) + vereq(d, {}) d = dictionary(mapping={}) - verify(d == {}) + vereq(d, {}) d = dictionary({1: 2, 'a': 'b'}) - verify(d == {1: 2, 'a': 'b'}) + vereq(d, {1: 2, 'a': 'b'}) for badarg in 0, 0L, 0j, "0", [0], (0,): try: dictionary(badarg) @@ -206,13 +206,13 @@ def dict_constructor(): Mapping.keys = lambda self: self.dict.keys() d = dictionary(mapping=Mapping()) - verify(d == Mapping.dict) + vereq(d, Mapping.dict) def test_dir(): if verbose: print "Testing dir() ..." junk = 12 - verify(dir() == ['junk']) + vereq(dir(), ['junk']) del junk # Just make sure these don't blow up! @@ -225,15 +225,15 @@ def test_dir(): def Cmethod(self): pass cstuff = ['Cdata', 'Cmethod', '__doc__', '__module__'] - verify(dir(C) == cstuff) + vereq(dir(C), cstuff) verify('im_self' in dir(C.Cmethod)) c = C() # c.__doc__ is an odd thing to see here; ditto c.__module__. - verify(dir(c) == cstuff) + vereq(dir(c), cstuff) c.cdata = 2 c.cmethod = lambda self: 0 - verify(dir(c) == cstuff + ['cdata', 'cmethod']) + vereq(dir(c), cstuff + ['cdata', 'cmethod']) verify('im_self' in dir(c.Cmethod)) class A(C): @@ -241,14 +241,14 @@ def test_dir(): def Amethod(self): pass astuff = ['Adata', 'Amethod'] + cstuff - verify(dir(A) == astuff) + vereq(dir(A), astuff) verify('im_self' in dir(A.Amethod)) a = A() - verify(dir(a) == astuff) + vereq(dir(a), astuff) verify('im_self' in dir(a.Amethod)) a.adata = 42 a.amethod = lambda self: 3 - verify(dir(a) == astuff + ['adata', 'amethod']) + vereq(dir(a), astuff + ['adata', 'amethod']) # The same, but with new-style classes. Since these have object as a # base class, a lot more gets sucked in. @@ -260,15 +260,15 @@ def test_dir(): def Cmethod(self): pass cstuff = ['Cdata', 'Cmethod'] - verify(interesting(dir(C)) == cstuff) + vereq(interesting(dir(C)), cstuff) c = C() - verify(interesting(dir(c)) == cstuff) + vereq(interesting(dir(c)), cstuff) verify('im_self' in dir(C.Cmethod)) c.cdata = 2 c.cmethod = lambda self: 0 - verify(interesting(dir(c)) == cstuff + ['cdata', 'cmethod']) + vereq(interesting(dir(c)), cstuff + ['cdata', 'cmethod']) verify('im_self' in dir(c.Cmethod)) class A(C): @@ -276,13 +276,13 @@ def test_dir(): def Amethod(self): pass astuff = ['Adata', 'Amethod'] + cstuff - verify(interesting(dir(A)) == astuff) + vereq(interesting(dir(A)), astuff) verify('im_self' in dir(A.Amethod)) a = A() - verify(interesting(dir(a)) == astuff) + vereq(interesting(dir(a)), astuff) a.adata = 42 a.amethod = lambda self: 3 - verify(interesting(dir(a)) == astuff + ['adata', 'amethod']) + vereq(interesting(dir(a)), astuff + ['adata', 'amethod']) verify('im_self' in dir(a.Amethod)) # Try a module subclass. @@ -292,7 +292,7 @@ def test_dir(): minstance = M() minstance.b = 2 minstance.a = 1 - verify(dir(minstance) == ['a', 'b']) + vereq(dir(minstance), ['a', 'b']) class M2(M): def getdict(self): @@ -302,7 +302,7 @@ def test_dir(): m2instance = M2() m2instance.b = 2 m2instance.a = 1 - verify(m2instance.__dict__ == "Not a dict!") + vereq(m2instance.__dict__, "Not a dict!") try: dir(m2instance) except TypeError: @@ -401,16 +401,16 @@ def complexes(): __str__ = __repr__ a = Number(3.14, prec=6) - verify(`a` == "3.14") - verify(a.prec == 6) + vereq(`a`, "3.14") + vereq(a.prec, 6) a = Number(a, prec=2) - verify(`a` == "3.1") - verify(a.prec == 2) + vereq(`a`, "3.1") + vereq(a.prec, 2) a = Number(234.5) - verify(`a` == "234.5") - verify(a.prec == 12) + vereq(`a`, "234.5") + vereq(a.prec, 12) def spamlists(): if verbose: print "Testing spamlist operations..." @@ -440,13 +440,13 @@ def spamlists(): class C(spam.spamlist): def foo(self): return 1 a = C() - verify(a == []) - verify(a.foo() == 1) + vereq(a, []) + vereq(a.foo(), 1) a.append(100) - verify(a == [100]) - verify(a.getstate() == 0) + vereq(a, [100]) + vereq(a.getstate(), 0) a.setstate(42) - verify(a.getstate() == 42) + vereq(a.getstate(), 42) def spamdicts(): if verbose: print "Testing spamdict operations..." @@ -468,13 +468,13 @@ def spamdicts(): for i in d.keys(): l1.append(i) l = [] for i in iter(d): l.append(i) - verify(l == l1) + vereq(l, l1) l = [] for i in d.__iter__(): l.append(i) - verify(l == l1) + vereq(l, l1) l = [] for i in type(spamdict({})).__iter__(d): l.append(i) - verify(l == l1) + vereq(l, l1) straightd = {1:2, 3:4} spamd = spamdict(straightd) testunop(spamd, 2, "len(a)", "__len__") @@ -485,20 +485,20 @@ def spamdicts(): class C(spam.spamdict): def foo(self): return 1 a = C() - verify(a.items() == []) - verify(a.foo() == 1) + vereq(a.items(), []) + vereq(a.foo(), 1) a['foo'] = 'bar' - verify(a.items() == [('foo', 'bar')]) - verify(a.getstate() == 0) + vereq(a.items(), [('foo', 'bar')]) + vereq(a.getstate(), 0) a.setstate(100) - verify(a.getstate() == 100) + vereq(a.getstate(), 100) def pydicts(): if verbose: print "Testing Python subclass of dict..." verify(issubclass(dictionary, dictionary)) verify(isinstance({}, dictionary)) d = dictionary() - verify(d == {}) + vereq(d, {}) verify(d.__class__ is dictionary) verify(isinstance(d, dictionary)) class C(dictionary): @@ -520,21 +520,21 @@ def pydicts(): return self.state verify(issubclass(C, dictionary)) a1 = C(12) - verify(a1.state == 12) + vereq(a1.state, 12) a2 = C(foo=1, bar=2) - verify(a2[1] == 'foo' and a2[2] == 'bar') + vereq(a2[1] == 'foo' and a2[2], 'bar') a = C() - verify(a.state == -1) - verify(a.getstate() == -1) + vereq(a.state, -1) + vereq(a.getstate(), -1) a.setstate(0) - verify(a.state == 0) - verify(a.getstate() == 0) + vereq(a.state, 0) + vereq(a.getstate(), 0) a.setstate(10) - verify(a.state == 10) - verify(a.getstate() == 10) - verify(a[42] == 0) + vereq(a.state, 10) + vereq(a.getstate(), 10) + vereq(a[42], 0) a[42] = 24 - verify(a[42] == 24) + vereq(a[42], 24) if verbose: print "pydict stress test ..." N = 50 for i in range(N): @@ -543,7 +543,7 @@ def pydicts(): a[i][j] = i*j for i in range(N): for j in range(N): - verify(a[i][j] == i*j) + vereq(a[i][j], i*j) def pylists(): if verbose: print "Testing Python subclass of list..." @@ -554,10 +554,10 @@ def pylists(): return (i, j) a = C() a.extend([0,1,2]) - verify(a[0] == 100) - verify(a[1] == 101) - verify(a[2] == 102) - verify(a[100:200] == (100,200)) + vereq(a[0], 100) + vereq(a[1], 101) + vereq(a[2], 102) + vereq(a[100:200], (100,200)) def metaclass(): if verbose: print "Testing __metaclass__..." @@ -570,13 +570,13 @@ def metaclass(): def setstate(self, state): self.__state = state a = C() - verify(a.getstate() == 0) + vereq(a.getstate(), 0) a.setstate(10) - verify(a.getstate() == 10) + vereq(a.getstate(), 10) class D: class __metaclass__(type): def myself(cls): return cls - verify(D.myself() == D) + vereq(D.myself(), D) d = D() verify(d.__class__ is D) class M1(type): @@ -585,9 +585,9 @@ def metaclass(): return type.__new__(cls, name, bases, dict) class C: __metaclass__ = M1 - verify(C.__spam__ == 1) + vereq(C.__spam__, 1) c = C() - verify(c.__spam__ == 1) + vereq(c.__spam__, 1) class _instance(object): pass @@ -611,11 +611,11 @@ def metaclass(): __metaclass__ = M2 def spam(self): return 42 - verify(C.name == 'C') - verify(C.bases == ()) + vereq(C.name, 'C') + vereq(C.bases, ()) verify('spam' in C.dict) c = C() - verify(c.spam() == 42) + vereq(c.spam(), 42) # More metaclass examples @@ -650,11 +650,11 @@ def metaclass(): class D(C, B): def meth(self): return "D" + self.__super.meth() - verify(D().meth() == "DCBA") + vereq(D().meth(), "DCBA") class E(B, C): def meth(self): return "E" + self.__super.meth() - verify(E().meth() == "EBCA") + vereq(E().meth(), "EBCA") class autoproperty(type): # Automatically create property attributes when methods @@ -685,8 +685,8 @@ def metaclass(): a = A() verify(not hasattr(a, "x")) a.x = 12 - verify(a.x == 12) - verify(a._A__x == -12) + vereq(a.x, 12) + vereq(a._A__x, -12) class multimetaclass(autoproperty, autosuper): # Merge of multiple cooperating metaclasses @@ -704,7 +704,7 @@ def metaclass(): class D(C, B): def _get_x(self): return "D" + self.__super._get_x() - verify(D().x == "DCBA") + vereq(D().x, "DCBA") def pymods(): if verbose: print "Testing Python subclass of module..." @@ -727,9 +727,9 @@ def pymods(): a.foo = 12 x = a.foo del a.foo - verify(log == [("setattr", "foo", 12), - ("getattr", "foo"), - ("delattr", "foo")], log) + vereq(log, [("setattr", "foo", 12), + ("getattr", "foo"), + ("delattr", "foo")]) def multi(): if verbose: print "Testing multiple inheritance..." @@ -741,22 +741,22 @@ def multi(): def setstate(self, state): self.__state = state a = C() - verify(a.getstate() == 0) + vereq(a.getstate(), 0) a.setstate(10) - verify(a.getstate() == 10) + vereq(a.getstate(), 10) class D(dictionary, C): def __init__(self): type({}).__init__(self) C.__init__(self) d = D() - verify(d.keys() == []) + vereq(d.keys(), []) d["hello"] = "world" - verify(d.items() == [("hello", "world")]) - verify(d["hello"] == "world") - verify(d.getstate() == 0) + vereq(d.items(), [("hello", "world")]) + vereq(d["hello"], "world") + vereq(d.getstate(), 0) d.setstate(10) - verify(d.getstate() == 10) - verify(D.__mro__ == (D, dictionary, C, object)) + vereq(d.getstate(), 10) + vereq(D.__mro__, (D, dictionary, C, object)) # SF bug #442833 class Node(object): @@ -767,46 +767,47 @@ def multi(): class Frag(Node, list): def foo(self): return "42" - verify(Node().__int__() == 23) - verify(int(Node()) == 23) - verify(Frag().__int__() == 42) - verify(int(Frag()) == 42) + vereq(Node().__int__(), 23) + vereq(int(Node()), 23) + vereq(Frag().__int__(), 42) + vereq(int(Frag()), 42) def diamond(): if verbose: print "Testing multiple inheritance special cases..." class A(object): def spam(self): return "A" - verify(A().spam() == "A") + vereq(A().spam(), "A") class B(A): def boo(self): return "B" def spam(self): return "B" - verify(B().spam() == "B") - verify(B().boo() == "B") + vereq(B().spam(), "B") + vereq(B().boo(), "B") class C(A): def boo(self): return "C" - verify(C().spam() == "A") - verify(C().boo() == "C") + vereq(C().spam(), "A") + vereq(C().boo(), "C") class D(B, C): pass - verify(D().spam() == "B") - verify(D().boo() == "B") - verify(D.__mro__ == (D, B, C, A, object)) + vereq(D().spam(), "B") + vereq(D().boo(), "B") + vereq(D.__mro__, (D, B, C, A, object)) class E(C, B): pass - verify(E().spam() == "B") - verify(E().boo() == "C") - verify(E.__mro__ == (E, C, B, A, object)) + vereq(E().spam(), "B") + vereq(E().boo(), "C") + vereq(E.__mro__, (E, C, B, A, object)) class F(D, E): pass - verify(F().spam() == "B") - verify(F().boo() == "B") - verify(F.__mro__ == (F, D, E, B, C, A, object)) + vereq(F().spam(), "B") + vereq(F().boo(), "B") + vereq(F.__mro__, (F, D, E, B, C, A, object)) class G(E, D): pass - verify(G().spam() == "B") - verify(G().boo() == "C") - verify(G.__mro__ == (G, E, D, C, B, A, object)) + vereq(G().spam(), "B") + vereq(G().boo(), "C") + vereq(G.__mro__, (G, E, D, C, B, A, object)) def objects(): if verbose: print "Testing object class..." a = object() - verify(a.__class__ == object == type(a)) + vereq(a.__class__, object) + vereq(type(a), object) b = object() verify(a is not b) verify(not hasattr(a, "foo")) @@ -821,10 +822,10 @@ def objects(): class Cdict(object): pass x = Cdict() - verify(x.__dict__ == {}) + vereq(x.__dict__, {}) x.foo = 1 - verify(x.foo == 1) - verify(x.__dict__ == {'foo': 1}) + vereq(x.foo, 1) + vereq(x.__dict__, {'foo': 1}) def slots(): if verbose: print "Testing __slots__..." @@ -838,11 +839,11 @@ def slots(): __slots__ = ['a'] x = C1() verify(not hasattr(x, "__dict__")) - verify(x.a == None) + vereq(x.a, None) x.a = 1 - verify(x.a == 1) + vereq(x.a, 1) del x.a - verify(x.a == None) + vereq(x.a, None) class C3(object): __slots__ = ['a', 'b', 'c'] @@ -854,30 +855,30 @@ def slots(): x.a = 1 x.b = 2 x.c = 3 - verify(x.a == 1) - verify(x.b == 2) - verify(x.c == 3) + vereq(x.a, 1) + vereq(x.b, 2) + vereq(x.c, 3) def dynamics(): if verbose: print "Testing __dynamic__..." - verify(object.__dynamic__ == 0) - verify(list.__dynamic__ == 0) + vereq(object.__dynamic__, 0) + vereq(list.__dynamic__, 0) class S1: __metaclass__ = type __dynamic__ = 0 - verify(S1.__dynamic__ == 0) + vereq(S1.__dynamic__, 0) class S(object): __dynamic__ = 0 - verify(S.__dynamic__ == 0) + vereq(S.__dynamic__, 0) class D(object): __dynamic__ = 1 - verify(D.__dynamic__ == 1) + vereq(D.__dynamic__, 1) class E(D, S): pass - verify(E.__dynamic__ == 1) + vereq(E.__dynamic__, 1) class F(S, D): pass - verify(F.__dynamic__ == 1) + vereq(F.__dynamic__, 1) try: S.foo = 1 except (AttributeError, TypeError): @@ -885,14 +886,14 @@ def dynamics(): else: verify(0, "assignment to a static class attribute should be illegal") D.foo = 1 - verify(D.foo == 1) + vereq(D.foo, 1) # Test that dynamic attributes are inherited - verify(E.foo == 1) - verify(F.foo == 1) + vereq(E.foo, 1) + vereq(F.foo, 1) class SS(D): __dynamic__ = 0 - verify(SS.__dynamic__ == 0) - verify(SS.foo == 1) + vereq(SS.__dynamic__, 0) + vereq(SS.foo, 1) try: SS.foo = 1 except (AttributeError, TypeError): @@ -910,23 +911,23 @@ def dynamics(): a = C() verify(not hasattr(a, "foobar")) C.foobar = 2 - verify(a.foobar == 2) + vereq(a.foobar, 2) C.method = lambda self: 42 - verify(a.method() == 42) + vereq(a.method(), 42) C.__repr__ = lambda self: "C()" - verify(repr(a) == "C()") + vereq(repr(a), "C()") C.__int__ = lambda self: 100 - verify(int(a) == 100) - verify(a.foobar == 2) + vereq(int(a), 100) + vereq(a.foobar, 2) verify(not hasattr(a, "spam")) def mygetattr(self, name): if name == "spam": return "spam" raise AttributeError C.__getattr__ = mygetattr - verify(a.spam == "spam") + vereq(a.spam, "spam") a.new = 12 - verify(a.new == 12) + vereq(a.new, 12) def mysetattr(self, name, value): if name == "spam": raise AttributeError @@ -938,30 +939,30 @@ def dynamics(): pass else: verify(0, "expected AttributeError") - verify(a.spam == "spam") + vereq(a.spam, "spam") class D(C): pass d = D() d.foo = 1 - verify(d.foo == 1) + vereq(d.foo, 1) # Test handling of int*seq and seq*int class I(int): __dynamic__ = 1 - verify("a"*I(2) == "aa") - verify(I(2)*"a" == "aa") - verify(2*I(3) == 6) - verify(I(3)*2 == 6) - verify(I(3)*I(2) == 6) + vereq("a"*I(2), "aa") + vereq(I(2)*"a", "aa") + vereq(2*I(3), 6) + vereq(I(3)*2, 6) + vereq(I(3)*I(2), 6) # Test handling of long*seq and seq*long class L(long): __dynamic__ = 1 - verify("a"*L(2L) == "aa") - verify(L(2L)*"a" == "aa") - verify(2*L(3) == 6) - verify(L(3)*2 == 6) - verify(L(3)*L(2) == 6) + vereq("a"*L(2L), "aa") + vereq(L(2L)*"a", "aa") + vereq(2*L(3), 6) + vereq(L(3)*2, 6) + vereq(L(3)*L(2), 6) # Test comparison of classes with dynamic metaclasses class dynamicmetaclass(type): @@ -1029,16 +1030,16 @@ def classmethods(): def foo(*a): return a goo = classmethod(foo) c = C() - verify(C.goo(1) == (C, 1)) - verify(c.goo(1) == (C, 1)) - verify(c.foo(1) == (c, 1)) + vereq(C.goo(1), (C, 1)) + vereq(c.goo(1), (C, 1)) + vereq(c.foo(1), (c, 1)) class D(C): pass d = D() - verify(D.goo(1) == (D, 1)) - verify(d.goo(1) == (D, 1)) - verify(d.foo(1) == (d, 1)) - verify(D.foo(d, 1) == (d, 1)) + vereq(D.goo(1), (D, 1)) + vereq(d.goo(1), (D, 1)) + vereq(d.foo(1), (d, 1)) + vereq(D.foo(d, 1), (d, 1)) def staticmethods(): if verbose: print "Testing static methods..." @@ -1046,16 +1047,16 @@ def staticmethods(): def foo(*a): return a goo = staticmethod(foo) c = C() - verify(C.goo(1) == (1,)) - verify(c.goo(1) == (1,)) - verify(c.foo(1) == (c, 1,)) + vereq(C.goo(1), (1,)) + vereq(c.goo(1), (1,)) + vereq(c.foo(1), (c, 1,)) class D(C): pass d = D() - verify(D.goo(1) == (1,)) - verify(d.goo(1) == (1,)) - verify(d.foo(1) == (d, 1)) - verify(D.foo(d, 1) == (d, 1)) + vereq(D.goo(1), (1,)) + vereq(d.goo(1), (1,)) + vereq(d.foo(1), (d, 1)) + vereq(D.foo(d, 1), (d, 1)) def classic(): if verbose: print "Testing classic classes..." @@ -1063,19 +1064,19 @@ def classic(): def foo(*a): return a goo = classmethod(foo) c = C() - verify(C.goo(1) == (C, 1)) - verify(c.goo(1) == (C, 1)) - verify(c.foo(1) == (c, 1)) + vereq(C.goo(1), (C, 1)) + vereq(c.goo(1), (C, 1)) + vereq(c.foo(1), (c, 1)) class D(C): pass d = D() - verify(D.goo(1) == (D, 1)) - verify(d.goo(1) == (D, 1)) - verify(d.foo(1) == (d, 1)) - verify(D.foo(d, 1) == (d, 1)) + vereq(D.goo(1), (D, 1)) + vereq(d.goo(1), (D, 1)) + vereq(d.foo(1), (d, 1)) + vereq(D.foo(d, 1), (d, 1)) class E: # *not* subclassing from C foo = C.foo - verify(E().foo == C.foo) # i.e., unbound + vereq(E().foo, C.foo) # i.e., unbound verify(repr(C.foo.__get__(C())).startswith("= 0) - verify(str(c1) == repr(c1)) + vereq(str(c1), repr(c1)) verify(-1 not in c1) for i in range(10): verify(i in c1) @@ -1257,16 +1259,16 @@ def specials(): d1 = D() d2 = D() verify(not not d1) - verify(hash(d1) == id(d1)) - verify(cmp(d1, d2) == cmp(id(d1), id(d2))) - verify(d1 == d1) + vereq(hash(d1), id(d1)) + vereq(cmp(d1, d2), cmp(id(d1), id(d2))) + vereq(d1, d1) verify(d1 != d2) verify(not d1 != d1) verify(not d1 == d2) # Note that the module name appears in str/repr, and that varies # depending on whether this test is run standalone or from a framework. verify(str(d1).find('D object at ') >= 0) - verify(str(d1) == repr(d1)) + vereq(str(d1), repr(d1)) verify(-1 not in d1) for i in range(10): verify(i in d1) @@ -1296,16 +1298,16 @@ def specials(): p_1 = Proxy(-1) verify(not p0) verify(not not p1) - verify(hash(p0) == hash(0)) - verify(p0 == p0) + vereq(hash(p0), hash(0)) + vereq(p0, p0) verify(p0 != p1) verify(not p0 != p0) - verify(not p0 == p1) - verify(cmp(p0, p1) == -1) - verify(cmp(p0, p0) == 0) - verify(cmp(p0, p_1) == 1) - verify(str(p0) == "Proxy:0") - verify(repr(p0) == "Proxy(0)") + vereq(not p0, p1) + vereq(cmp(p0, p1), -1) + vereq(cmp(p0, p0), 0) + vereq(cmp(p0, p_1), 1) + vereq(str(p0), "Proxy:0") + vereq(repr(p0), "Proxy(0)") p10 = Proxy(range(10)) verify(-1 not in p10) for i in range(10): @@ -1337,16 +1339,16 @@ def specials(): p_1 = DProxy(-1) verify(not p0) verify(not not p1) - verify(hash(p0) == hash(0)) - verify(p0 == p0) + vereq(hash(p0), hash(0)) + vereq(p0, p0) verify(p0 != p1) verify(not p0 != p0) - verify(not p0 == p1) - verify(cmp(p0, p1) == -1) - verify(cmp(p0, p0) == 0) - verify(cmp(p0, p_1) == 1) - verify(str(p0) == "DProxy:0") - verify(repr(p0) == "DProxy(0)") + vereq(not p0, p1) + vereq(cmp(p0, p1), -1) + vereq(cmp(p0, p0), 0) + vereq(cmp(p0, p_1), 1) + vereq(str(p0), "DProxy:0") + vereq(repr(p0), "DProxy(0)") p10 = DProxy(range(10)) verify(-1 not in p10) for i in range(10): @@ -1410,13 +1412,13 @@ def properties(): a = C() verify(not hasattr(a, "x")) a.x = 42 - verify(a._C__x == 42) - verify(a.x == 42) + vereq(a._C__x, 42) + vereq(a.x, 42) del a.x verify(not hasattr(a, "x")) verify(not hasattr(a, "_C__x")) C.x.__set__(a, 100) - verify(C.x.__get__(a) == 100) + vereq(C.x.__get__(a), 100) ## C.x.__set__(a) ## verify(not hasattr(a, "x")) @@ -1429,7 +1431,7 @@ def properties(): verify("fset" in attrs) verify("fdel" in attrs) - verify(raw.__doc__ == "I'm the x property.") + vereq(raw.__doc__, "I'm the x property.") verify(raw.fget is C.__dict__['getx']) verify(raw.fset is C.__dict__['setx']) verify(raw.fdel is C.__dict__['delx']) @@ -1453,7 +1455,7 @@ def supers(): def meth(self, a): return "A(%r)" % a - verify(A().meth(1) == "A(1)") + vereq(A().meth(1), "A(1)") class B(A): def __init__(self): @@ -1461,7 +1463,7 @@ def supers(): def meth(self, a): return "B(%r)" % a + self.__super.meth(a) - verify(B().meth(2) == "B(2)A(2)") + vereq(B().meth(2), "B(2)A(2)") class C(A): __dynamic__ = 1 @@ -1469,7 +1471,7 @@ def supers(): return "C(%r)" % a + self.__super.meth(a) C._C__super = super(C) - verify(C().meth(3) == "C(3)A(3)") + vereq(C().meth(3), "C(3)A(3)") class D(C, B): def meth(self, a): @@ -1487,13 +1489,13 @@ def inherits(): return hexint(int.__add__(self, other)) # (Note that overriding __radd__ doesn't work, # because the int type gets first dibs.) - verify(repr(hexint(7) + 9) == "0x10") - verify(repr(hexint(1000) + 7) == "0x3ef") + vereq(repr(hexint(7) + 9), "0x10") + vereq(repr(hexint(1000) + 7), "0x3ef") a = hexint(12345) - verify(a == 12345) - verify(int(a) == 12345) + vereq(a, 12345) + vereq(int(a), 12345) verify(int(a).__class__ is int) - verify(hash(a) == hash(12345)) + vereq(hash(a), hash(12345)) verify((+a).__class__ is int) verify((a >> 0).__class__ is int) verify((a << 0).__class__ is int) @@ -1510,14 +1512,14 @@ def inherits(): def __add__(self, other): return self.__class__(super(octlong, self).__add__(other)) __radd__ = __add__ - verify(str(octlong(3) + 5) == "010") + vereq(str(octlong(3) + 5), "010") # (Note that overriding __radd__ here only seems to work # because the example uses a short int left argument.) - verify(str(5 + octlong(3000)) == "05675") + vereq(str(5 + octlong(3000)), "05675") a = octlong(12345) - verify(a == 12345L) - verify(long(a) == 12345L) - verify(hash(a) == hash(12345L)) + vereq(a, 12345L) + vereq(long(a), 12345L) + vereq(hash(a), hash(12345L)) verify(long(a).__class__ is long) verify((+a).__class__ is long) verify((-a).__class__ is long) @@ -1551,12 +1553,12 @@ def inherits(): float.__init__(value) def __repr__(self): return "%.*g" % (self.prec, self) - verify(repr(precfloat(1.1)) == "1.1") + vereq(repr(precfloat(1.1)), "1.1") a = precfloat(12345) - verify(a == 12345.0) - verify(float(a) == 12345.0) + vereq(a, 12345.0) + vereq(float(a), 12345.0) verify(float(a).__class__ is float) - verify(hash(a) == hash(12345.0)) + vereq(hash(a), hash(12345.0)) verify((+a).__class__ is float) class madcomplex(complex): @@ -1564,27 +1566,27 @@ def inherits(): def __repr__(self): return "%.17gj%+.17g" % (self.imag, self.real) a = madcomplex(-3, 4) - verify(repr(a) == "4j-3") + vereq(repr(a), "4j-3") base = complex(-3, 4) verify(base.__class__ is complex) - verify(a == base) - verify(complex(a) == base) + vereq(a, base) + vereq(complex(a), base) verify(complex(a).__class__ is complex) a = madcomplex(a) # just trying another form of the constructor - verify(repr(a) == "4j-3") - verify(a == base) - verify(complex(a) == base) + vereq(repr(a), "4j-3") + vereq(a, base) + vereq(complex(a), base) verify(complex(a).__class__ is complex) - verify(hash(a) == hash(base)) + vereq(hash(a), hash(base)) verify((+a).__class__ is complex) verify((a + 0).__class__ is complex) - verify(a + 0 == base) + vereq(a + 0, base) verify((a - 0).__class__ is complex) - verify(a - 0 == base) + vereq(a - 0, base) verify((a * 1).__class__ is complex) - verify(a * 1 == base) + vereq(a * 1, base) verify((a / 1).__class__ is complex) - verify(a / 1 == base) + vereq(a / 1, base) class madtuple(tuple): _rev = None @@ -1596,24 +1598,24 @@ def inherits(): self._rev = self.__class__(L) return self._rev a = madtuple((1,2,3,4,5,6,7,8,9,0)) - verify(a == (1,2,3,4,5,6,7,8,9,0)) - verify(a.rev() == madtuple((0,9,8,7,6,5,4,3,2,1))) - verify(a.rev().rev() == madtuple((1,2,3,4,5,6,7,8,9,0))) + vereq(a, (1,2,3,4,5,6,7,8,9,0)) + vereq(a.rev(), madtuple((0,9,8,7,6,5,4,3,2,1))) + vereq(a.rev().rev(), madtuple((1,2,3,4,5,6,7,8,9,0))) for i in range(512): t = madtuple(range(i)) u = t.rev() v = u.rev() - verify(v == t) + vereq(v, t) a = madtuple((1,2,3,4,5)) - verify(tuple(a) == (1,2,3,4,5)) + vereq(tuple(a), (1,2,3,4,5)) verify(tuple(a).__class__ is tuple) - verify(hash(a) == hash((1,2,3,4,5))) + vereq(hash(a), hash((1,2,3,4,5))) verify(a[:].__class__ is tuple) verify((a * 1).__class__ is tuple) verify((a * 0).__class__ is tuple) verify((a + ()).__class__ is tuple) a = madtuple(()) - verify(tuple(a) == ()) + vereq(tuple(a), ()) verify(tuple(a).__class__ is tuple) verify((a + a).__class__ is tuple) verify((a * 0).__class__ is tuple) @@ -1631,72 +1633,72 @@ def inherits(): self._rev = self.__class__("".join(L)) return self._rev s = madstring("abcdefghijklmnopqrstuvwxyz") - verify(s == "abcdefghijklmnopqrstuvwxyz") - verify(s.rev() == madstring("zyxwvutsrqponmlkjihgfedcba")) - verify(s.rev().rev() == madstring("abcdefghijklmnopqrstuvwxyz")) + vereq(s, "abcdefghijklmnopqrstuvwxyz") + vereq(s.rev(), madstring("zyxwvutsrqponmlkjihgfedcba")) + vereq(s.rev().rev(), madstring("abcdefghijklmnopqrstuvwxyz")) for i in range(256): s = madstring("".join(map(chr, range(i)))) t = s.rev() u = t.rev() - verify(u == s) + vereq(u, s) s = madstring("12345") - verify(str(s) == "12345") + vereq(str(s), "12345") verify(str(s).__class__ is str) base = "\x00" * 5 s = madstring(base) - verify(s == base) - verify(str(s) == base) + vereq(s, base) + vereq(str(s), base) verify(str(s).__class__ is str) - verify(hash(s) == hash(base)) - verify({s: 1}[base] == 1) - verify({base: 1}[s] == 1) + vereq(hash(s), hash(base)) + vereq({s: 1}[base], 1) + vereq({base: 1}[s], 1) verify((s + "").__class__ is str) - verify(s + "" == base) + vereq(s + "", base) verify(("" + s).__class__ is str) - verify("" + s == base) + vereq("" + s, base) verify((s * 0).__class__ is str) - verify(s * 0 == "") + vereq(s * 0, "") verify((s * 1).__class__ is str) - verify(s * 1 == base) + vereq(s * 1, base) verify((s * 2).__class__ is str) - verify(s * 2 == base + base) + vereq(s * 2, base + base) verify(s[:].__class__ is str) - verify(s[:] == base) + vereq(s[:], base) verify(s[0:0].__class__ is str) - verify(s[0:0] == "") + vereq(s[0:0], "") verify(s.strip().__class__ is str) - verify(s.strip() == base) + vereq(s.strip(), base) verify(s.lstrip().__class__ is str) - verify(s.lstrip() == base) + vereq(s.lstrip(), base) verify(s.rstrip().__class__ is str) - verify(s.rstrip() == base) + vereq(s.rstrip(), base) identitytab = ''.join([chr(i) for i in range(256)]) verify(s.translate(identitytab).__class__ is str) - verify(s.translate(identitytab) == base) + vereq(s.translate(identitytab), base) verify(s.translate(identitytab, "x").__class__ is str) - verify(s.translate(identitytab, "x") == base) - verify(s.translate(identitytab, "\x00") == "") + vereq(s.translate(identitytab, "x"), base) + vereq(s.translate(identitytab, "\x00"), "") verify(s.replace("x", "x").__class__ is str) - verify(s.replace("x", "x") == base) + vereq(s.replace("x", "x"), base) verify(s.ljust(len(s)).__class__ is str) - verify(s.ljust(len(s)) == base) + vereq(s.ljust(len(s)), base) verify(s.rjust(len(s)).__class__ is str) - verify(s.rjust(len(s)) == base) + vereq(s.rjust(len(s)), base) verify(s.center(len(s)).__class__ is str) - verify(s.center(len(s)) == base) + vereq(s.center(len(s)), base) verify(s.lower().__class__ is str) - verify(s.lower() == base) + vereq(s.lower(), base) s = madstring("x y") - verify(s == "x y") + vereq(s, "x y") verify(intern(s).__class__ is str) verify(intern(s) is intern("x y")) - verify(intern(s) == "x y") + vereq(intern(s), "x y") i = intern("y x") s = madstring("y x") - verify(s == i) + vereq(s, i) verify(intern(s).__class__ is str) verify(intern(s) is i) @@ -1714,54 +1716,54 @@ def inherits(): self._rev = self.__class__(u"".join(L)) return self._rev u = madunicode("ABCDEF") - verify(u == u"ABCDEF") - verify(u.rev() == madunicode(u"FEDCBA")) - verify(u.rev().rev() == madunicode(u"ABCDEF")) + vereq(u, u"ABCDEF") + vereq(u.rev(), madunicode(u"FEDCBA")) + vereq(u.rev().rev(), madunicode(u"ABCDEF")) base = u"12345" u = madunicode(base) - verify(unicode(u) == base) + vereq(unicode(u), base) verify(unicode(u).__class__ is unicode) - verify(hash(u) == hash(base)) - verify({u: 1}[base] == 1) - verify({base: 1}[u] == 1) + vereq(hash(u), hash(base)) + vereq({u: 1}[base], 1) + vereq({base: 1}[u], 1) verify(u.strip().__class__ is unicode) - verify(u.strip() == base) + vereq(u.strip(), base) verify(u.lstrip().__class__ is unicode) - verify(u.lstrip() == base) + vereq(u.lstrip(), base) verify(u.rstrip().__class__ is unicode) - verify(u.rstrip() == base) + vereq(u.rstrip(), base) verify(u.replace(u"x", u"x").__class__ is unicode) - verify(u.replace(u"x", u"x") == base) + vereq(u.replace(u"x", u"x"), base) verify(u.replace(u"xy", u"xy").__class__ is unicode) - verify(u.replace(u"xy", u"xy") == base) + vereq(u.replace(u"xy", u"xy"), base) verify(u.center(len(u)).__class__ is unicode) - verify(u.center(len(u)) == base) + vereq(u.center(len(u)), base) verify(u.ljust(len(u)).__class__ is unicode) - verify(u.ljust(len(u)) == base) + vereq(u.ljust(len(u)), base) verify(u.rjust(len(u)).__class__ is unicode) - verify(u.rjust(len(u)) == base) + vereq(u.rjust(len(u)), base) verify(u.lower().__class__ is unicode) - verify(u.lower() == base) + vereq(u.lower(), base) verify(u.upper().__class__ is unicode) - verify(u.upper() == base) + vereq(u.upper(), base) verify(u.capitalize().__class__ is unicode) - verify(u.capitalize() == base) + vereq(u.capitalize(), base) verify(u.title().__class__ is unicode) - verify(u.title() == base) + vereq(u.title(), base) verify((u + u"").__class__ is unicode) - verify(u + u"" == base) + vereq(u + u"", base) verify((u"" + u).__class__ is unicode) - verify(u"" + u == base) + vereq(u"" + u, base) verify((u * 0).__class__ is unicode) - verify(u * 0 == u"") + vereq(u * 0, u"") verify((u * 1).__class__ is unicode) - verify(u * 1 == base) + vereq(u * 1, base) verify((u * 2).__class__ is unicode) - verify(u * 2 == base + base) + vereq(u * 2, base + base) verify(u[:].__class__ is unicode) - verify(u[:] == base) + vereq(u[:], base) verify(u[0:0].__class__ is unicode) - verify(u[0:0] == u"") + vereq(u[0:0], u"") class CountedInput(file): """Counts lines read by self.readline(). @@ -1795,9 +1797,9 @@ def inherits(): f = CountedInput(TESTFN) for (i, expected) in zip(range(1, 5) + [4], lines + 2 * [""]): got = f.readline() - verify(expected == got) - verify(f.lineno == i) - verify(f.ateof == (i > len(lines))) + vereq(expected, got) + vereq(f.lineno, i) + vereq(f.ateof, (i > len(lines))) f.close() finally: try: @@ -1813,15 +1815,15 @@ def inherits(): def keywords(): if verbose: print "Testing keyword args to basic type constructors ..." - verify(int(x=1) == 1) - verify(float(x=2) == 2.0) - verify(long(x=3) == 3L) - verify(complex(imag=42, real=666) == complex(666, 42)) - verify(str(object=500) == '500') - verify(unicode(string='abc', errors='strict') == u'abc') - verify(tuple(sequence=range(3)) == (0, 1, 2)) - verify(list(sequence=(0, 1, 2)) == range(3)) - verify(dictionary(mapping={1: 2}) == {1: 2}) + vereq(int(x=1), 1) + vereq(float(x=2), 2.0) + vereq(long(x=3), 3L) + vereq(complex(imag=42, real=666), complex(666, 42)) + vereq(str(object=500), '500') + vereq(unicode(string='abc', errors='strict'), u'abc') + vereq(tuple(sequence=range(3)), (0, 1, 2)) + vereq(list(sequence=(0, 1, 2)), range(3)) + vereq(dictionary(mapping={1: 2}), {1: 2}) for constructor in (int, float, long, complex, str, unicode, tuple, list, dictionary, file): @@ -1896,16 +1898,16 @@ def str_subclass_as_dict_key(): def __hash__(self): return self.hashcode - verify(cistr('ABC') == 'abc') - verify('aBc' == cistr('ABC')) - verify(str(cistr('ABC')) == 'ABC') + vereq(cistr('ABC'), 'abc') + vereq('aBc', cistr('ABC')) + vereq(str(cistr('ABC')), 'ABC') d = {cistr('one'): 1, cistr('two'): 2, cistr('tHree'): 3} - verify(d[cistr('one')] == 1) - verify(d[cistr('tWo')] == 2) - verify(d[cistr('THrEE')] == 3) + vereq(d[cistr('one')], 1) + vereq(d[cistr('tWo')], 2) + vereq(d[cistr('THrEE')], 3) verify(cistr('ONe') in d) - verify(d.get(cistr('thrEE')) == 3) + vereq(d.get(cistr('thrEE')), 3) def classic_comparisons(): if verbose: print "Testing classic comparisons..." @@ -1925,7 +1927,7 @@ def classic_comparisons(): c1 = C(1) c2 = C(2) c3 = C(3) - verify(c1 == 1) + vereq(c1, 1) c = {1: c1, 2: c2, 3: c3} for x in 1, 2, 3: for y in 1, 2, 3: @@ -1942,8 +1944,8 @@ def rich_comparisons(): class Z(complex): __dynamic__ = 0 z = Z(1) - verify(z == 1+0j) - verify(1+0j == z) + vereq(z, 1+0j) + vereq(1+0j, z) class ZZ(complex): __dynamic__ = 0 def __eq__(self, other): @@ -1952,8 +1954,8 @@ def rich_comparisons(): except: return NotImplemented zz = ZZ(1.0000003) - verify(zz == 1+0j) - verify(1+0j == zz) + vereq(zz, 1+0j) + vereq(1+0j, zz) class classic: pass @@ -2003,7 +2005,7 @@ def rich_comparisons(): c1 = C(1) c2 = C(2) c3 = C(3) - verify(c1 == 1) + vereq(c1, 1) c = {1: c1, 2: c2, 3: c3} for x in 1, 2, 3: for y in 1, 2, 3: @@ -2046,7 +2048,7 @@ def coercions(): def descrdoc(): if verbose: print "Testing descriptor doc strings..." def check(descr, what): - verify(descr.__doc__ == what, repr(descr.__doc__)) + vereq(descr.__doc__, what) check(file.closed, "flag set if the file is closed") # getset descriptor check(file.name, "file name") # member descriptor @@ -2170,17 +2172,17 @@ def copies(): a = C() a.foo = 12 b = copy.copy(a) - verify(b.__dict__ == a.__dict__) + vereq(b.__dict__, a.__dict__) a.bar = [1,2,3] c = copy.copy(a) - verify(c.bar == a.bar) + vereq(c.bar, a.bar) verify(c.bar is a.bar) d = copy.deepcopy(a) - verify(d.__dict__ == a.__dict__) + vereq(d.__dict__, a.__dict__) a.bar.append(4) - verify(d.bar == [1,2,3]) + vereq(d.bar, [1,2,3]) def binopoverride(): if verbose: print "Testing overrides of binary operations..."