summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2003-02-11 18:44:42 (GMT)
committerGuido van Rossum <guido@python.org>2003-02-11 18:44:42 (GMT)
commitb6e5a0c6587420ba666d5402a8aefd20b9f8c507 (patch)
tree0534e16d21d244db518e0c7de7ec22ba79f54c54 /Lib
parent6bae46d8c14fc312f38a1087803c559b119c9bb5 (diff)
downloadcpython-b6e5a0c6587420ba666d5402a8aefd20b9f8c507.zip
cpython-b6e5a0c6587420ba666d5402a8aefd20b9f8c507.tar.gz
cpython-b6e5a0c6587420ba666d5402a8aefd20b9f8c507.tar.bz2
Put proper tests in classmethod_get(). Remove the type argument to
descr_check(); it wasn't useful. Change the type argument of the various _get() methods to PyObject * because the call signature of tp_descr_get doesn't guarantee its type.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_descr.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index d7368d3..f481205 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -3733,6 +3733,45 @@ def dict_type_with_metaclass():
__metaclass__ = M
veris(type(C.__dict__), type(B.__dict__))
+def meth_class_get():
+ # Full coverage of descrobject.c::classmethod_get()
+ if verbose: print "Testing __get__ method of METH_CLASS C methods..."
+ # Baseline
+ arg = [1, 2, 3]
+ res = {1: None, 2: None, 3: None}
+ vereq(dict.fromkeys(arg), res)
+ vereq({}.fromkeys(arg), res)
+ # Now get the descriptor
+ descr = dict.__dict__["fromkeys"]
+ # More baseline using the descriptor directly
+ vereq(descr.__get__(None, dict)(arg), res)
+ vereq(descr.__get__({})(arg), res)
+ # Now check various error cases
+ try:
+ descr.__get__(None, None)
+ except TypeError:
+ pass
+ else:
+ raise TestFailed, "shouldn't have allowed descr.__get__(None, None)"
+ try:
+ descr.__get__(42)
+ except TypeError:
+ pass
+ else:
+ raise TestFailed, "shouldn't have allowed descr.__get__(42)"
+ try:
+ descr.__get__(None, 42)
+ except TypeError:
+ pass
+ else:
+ raise TestFailed, "shouldn't have allowed descr.__get__(None, 42)"
+ try:
+ descr.__get__(None, int)
+ except TypeError:
+ pass
+ else:
+ raise TestFailed, "shouldn't have allowed descr.__get__(None, int)"
+
def test_main():
do_this_first()
@@ -3819,6 +3858,7 @@ def test_main():
mutable_names()
subclass_right_op()
dict_type_with_metaclass()
+ meth_class_get()
if verbose: print "All OK"