[Python-checkins] python/nondist/sandbox/parrotbench b5.py, 1.1,
1.2 out5, 1.1, 1.2
gvanrossum at users.sourceforge.net
gvanrossum at users.sourceforge.net
Wed Dec 31 01:16:49 EST 2003
Update of /cvsroot/python/python/nondist/sandbox/parrotbench
In directory sc8-pr-cvs1:/tmp/cvs-serv20090
Modified Files:
b5.py out5
Log Message:
More fun with classes.
Index: b5.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/parrotbench/b5.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** b5.py 31 Dec 2003 05:39:55 -0000 1.1
--- b5.py 31 Dec 2003 06:16:46 -0000 1.2
***************
*** 14,21 ****
f(*args)
except exc:
! pass
else:
raise AssertionError("%s not raised by %s%r",
! exc.__name, f.__name__, args)
def check_functions():
--- 14,23 ----
f(*args)
except exc:
! if __debug__:
! if show:
! print "%s%r raised %s" % (f.__name__, args, exc.__name__)
else:
raise AssertionError("%s not raised by %s%r",
! exc.__name__, f.__name__, args)
def check_functions():
***************
*** 160,163 ****
--- 162,176 ----
check(type(object), type)
check(type(lambda: None), type(check_functions))
+ class C(object):
+ pass
+ class MC(type):
+ pass
+ class D:
+ __metaclass__ = MC
+ class E(object):
+ __metaclass__ = MC
+ check(type(C), type)
+ check(type(D), MC)
+ check(type(E), MC)
check(unicode("abc"), u"abc")
***************
*** 176,192 ****
def check_descriptors():
! class C(object):
def getx(self):
! return self._x
def setx(self, x):
! self._x = x
def delx(self):
! del self._x
x = property(getx, setx, delx)
xx = property(getx)
! def f(*args):
! return list(args)
fc = classmethod(f)
fs = staticmethod(f)
--- 189,238 ----
def check_descriptors():
! class C0(object):
!
! def __getattribute__(self, name):
! if name == "spam":
! raise IndexError("no way")
! return super(C0, self).__getattribute__(name)
!
! class C(C0):
!
! hello = 42
!
! def __new__(cls, *args):
! if args:
! return None
! return super(C, cls).__new__(cls)
!
! def __init__(self):
! self.__dict__["foo"] = 42
! self.spam = 42
!
! def __setattr__(self, name, value):
! if name == "foo":
! raise RuntimeError("forget it")
! super(C, self).__setattr__(name, value)
!
! def __getattr__(self, name):
! if name == "bar":
! return self.foo
! raise AttributeError(name)
!
! def __getattribute__(self, name):
! if name == "hello":
! return "booh"
! return super(C, self).__getattribute__(name)
def getx(self):
! return self.__x
def setx(self, x):
! self.__x = x
def delx(self):
! del self.__x
x = property(getx, setx, delx)
xx = property(getx)
! def f(*args, **kwds):
! return list(args), dict(kwds)
fc = classmethod(f)
fs = staticmethod(f)
***************
*** 199,220 ****
return s
! c1 = C()
! exception(AttributeError, getattr, c1, "x")
! exception(AttributeError, getattr, c1, "xx")
! exception(AttributeError, setattr, c1, "xx", 42)
! setattr(c1, "x", 42)
! check(c1.x, 42)
! check(c1._x, 42)
! check(c1.xx, 42)
! exception(AttributeError, delattr, c1, "xx")
! del c1.x
! exception(AttributeError, getattr, c1, "x")
! exception(AttributeError, getattr, c1, "xx")
! exception(AttributeError, delattr, c1, "x")
! check(c1.f(42), [c1, 42])
! check(c1.fc(42), [C, 42])
! check(c1.fs(42), [42])
! check(repr(c1), "<C object>")
def main():
--- 245,312 ----
return s
! def checks():
! check(C(1), None)
! c1 = C()
! exception(AttributeError, getattr, c1, 'booh')
! exception(AttributeError, getattr, c1, "x")
! exception(AttributeError, getattr, c1, "xx")
! exception(AttributeError, setattr, c1, "xx", 42)
! setattr(c1, "x", 42)
! check(c1.x, 42)
! check(c1._C__x, 42)
! check(c1.xx, 42)
! exception(AttributeError, delattr, c1, "xx")
! del c1.x
! exception(AttributeError, getattr, c1, "x")
! exception(AttributeError, getattr, c1, "xx")
! check(getattr(c1, "x", None), None)
! check(getattr(c1, "xx", None), None)
! exception(AttributeError, delattr, c1, "x")
! check(c1.f(42), ([c1, 42], {}))
! check(c1.fc(42, foo=42), ([C, 42], {"foo": 42}))
! check(c1.fs(42, a=1, b=2), ([42], {'a': 1, 'b': 2}))
! check(repr(c1), "<C object>")
!
! check(getattr(c1, 'foo'), 42)
! check(getattr(c1, 'bar'), 42)
! exception(RuntimeError, setattr, c1, "foo", 42)
! c1.bar = "hello"
! check(c1.bar, "hello")
! exception(IndexError, getattr, c1, "spam")
! check(getattr(c1, "hello"), "booh")
! B = C.__bases__[-1]
! save = B.__getattribute__
! del B.__getattribute__
! check(c1.spam, 42)
! check(getattr(c1, "hello"), "booh")
! save2 = C.__getattribute__
! del C.__getattribute__
! check(c1.hello, 42)
! C.__getattribute__ = save2
! B.__getattribute__ = save
! exception(IndexError, getattr, c1, "spam")
! exception(IndexError, getattr, c1, "spam", None)
! check(getattr(c1, "hello"), "booh")
!
! checks()
! checks()
! class A(object):
! pass
! class B(object):
! def __getattribute__(self, name):
! if name == "spam":
! raise IndexError("no way")
! return super(B, self).__getattribute__(name)
! C.__bases__ = (A, B)
! checks()
!
! c2 = C()
! c2.x = 42
! check(c2.x, 42)
! check(c2._C__x, 42)
! c2.__class__ = C0
! check(getattr(c2, 'x', None), None)
! check(c2._C__x, 42)
def main():
Index: out5
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/parrotbench/out5,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** out5 31 Dec 2003 05:39:55 -0000 1.1
--- out5 31 Dec 2003 06:16:46 -0000 1.2
***************
*** 116,132 ****
<type 'type'> == <type 'type'>
<type 'function'> == <type 'function'>
u'abc' == u'abc'
u'abc' == u'abc'
u'abc\xff' == u'abc\xff'
u'abc\xff' == u'abc\xff'
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[('a', 'd'), ('b', 'e'), ('c', 'f')] == [('a', 'd'), ('b', 'e'), ('c', 'f')]
[('a', 'd', 'g'), ('b', 'e', 'h'), ('c', 'f', 'i')] == [('a', 'd', 'g'), ('b', 'e', 'h'), ('c', 'f', 'i')]
42 == 42
42 == 42
42 == 42
! [<C object>, 42] == [<C object>, 42]
! [<class '__main__.C'>, 42] == [<class '__main__.C'>, 42]
! [42] == [42]
'<C object>' == '<C object>'
OK.
--- 116,217 ----
<type 'type'> == <type 'type'>
<type 'function'> == <type 'function'>
+ <type 'type'> == <type 'type'>
+ <class '__main__.MC'> == <class '__main__.MC'>
+ <class '__main__.MC'> == <class '__main__.MC'>
u'abc' == u'abc'
u'abc' == u'abc'
u'abc\xff' == u'abc\xff'
u'abc\xff' == u'abc\xff'
+ unicode('abc\xff', 'ascii') raised UnicodeError
+ unicode('abc\xff', 'utf-8') raised UnicodeError
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[('a', 'd'), ('b', 'e'), ('c', 'f')] == [('a', 'd'), ('b', 'e'), ('c', 'f')]
[('a', 'd', 'g'), ('b', 'e', 'h'), ('c', 'f', 'i')] == [('a', 'd', 'g'), ('b', 'e', 'h'), ('c', 'f', 'i')]
+ None == None
+ getattr(<C object>, 'booh') raised AttributeError
+ getattr(<C object>, 'x') raised AttributeError
+ getattr(<C object>, 'xx') raised AttributeError
+ setattr(<C object>, 'xx', 42) raised AttributeError
42 == 42
42 == 42
42 == 42
! delattr(<C object>, 'xx') raised AttributeError
! getattr(<C object>, 'x') raised AttributeError
! getattr(<C object>, 'xx') raised AttributeError
! None == None
! None == None
! delattr(<C object>, 'x') raised AttributeError
! ([<C object>, 42], {}) == ([<C object>, 42], {})
! ([<class '__main__.C'>, 42], {'foo': 42}) == ([<class '__main__.C'>, 42], {'foo': 42})
! ([42], {'a': 1, 'b': 2}) == ([42], {'a': 1, 'b': 2})
'<C object>' == '<C object>'
+ 42 == 42
+ 42 == 42
+ setattr(<C object>, 'foo', 42) raised RuntimeError
+ 'hello' == 'hello'
+ getattr(<C object>, 'spam') raised IndexError
+ 'booh' == 'booh'
+ 42 == 42
+ 'booh' == 'booh'
+ 42 == 42
+ getattr(<C object>, 'spam') raised IndexError
+ 'booh' == 'booh'
+ None == None
+ getattr(<C object>, 'booh') raised AttributeError
+ getattr(<C object>, 'x') raised AttributeError
+ getattr(<C object>, 'xx') raised AttributeError
+ setattr(<C object>, 'xx', 42) raised AttributeError
+ 42 == 42
+ 42 == 42
+ 42 == 42
+ delattr(<C object>, 'xx') raised AttributeError
+ getattr(<C object>, 'x') raised AttributeError
+ getattr(<C object>, 'xx') raised AttributeError
+ None == None
+ None == None
+ delattr(<C object>, 'x') raised AttributeError
+ ([<C object>, 42], {}) == ([<C object>, 42], {})
+ ([<class '__main__.C'>, 42], {'foo': 42}) == ([<class '__main__.C'>, 42], {'foo': 42})
+ ([42], {'a': 1, 'b': 2}) == ([42], {'a': 1, 'b': 2})
+ '<C object>' == '<C object>'
+ 42 == 42
+ 42 == 42
+ setattr(<C object>, 'foo', 42) raised RuntimeError
+ 'hello' == 'hello'
+ getattr(<C object>, 'spam') raised IndexError
+ 'booh' == 'booh'
+ 42 == 42
+ 'booh' == 'booh'
+ 42 == 42
+ getattr(<C object>, 'spam') raised IndexError
+ 'booh' == 'booh'
+ None == None
+ getattr(<C object>, 'booh') raised AttributeError
+ getattr(<C object>, 'x') raised AttributeError
+ getattr(<C object>, 'xx') raised AttributeError
+ setattr(<C object>, 'xx', 42) raised AttributeError
+ 42 == 42
+ 42 == 42
+ 42 == 42
+ delattr(<C object>, 'xx') raised AttributeError
+ getattr(<C object>, 'x') raised AttributeError
+ getattr(<C object>, 'xx') raised AttributeError
+ None == None
+ None == None
+ delattr(<C object>, 'x') raised AttributeError
+ ([<C object>, 42], {}) == ([<C object>, 42], {})
+ ([<class '__main__.C'>, 42], {'foo': 42}) == ([<class '__main__.C'>, 42], {'foo': 42})
+ ([42], {'a': 1, 'b': 2}) == ([42], {'a': 1, 'b': 2})
+ '<C object>' == '<C object>'
+ 42 == 42
+ 42 == 42
+ setattr(<C object>, 'foo', 42) raised RuntimeError
+ 'hello' == 'hello'
+ getattr(<C object>, 'spam') raised IndexError
+ 'booh' == 'booh'
+ 42 == 42
+ 'booh' == 'booh'
+ 42 == 42
+ getattr(<C object>, 'spam') raised IndexError
+ 'booh' == 'booh'
OK.
More information about the Python-checkins
mailing list