File tree 1 file changed +30
-14
lines changed
1 file changed +30
-14
lines changed Original file line number Diff line number Diff line change 1
1
"Test the functionality of Python classes implementing operators."
2
2
3
3
import unittest
4
- import test .support
4
+ from test .support import cpython_only , import_helper , script_helper
5
5
6
6
testmeths = [
7
7
@@ -920,20 +920,36 @@ class C:
920
920
C .a = X ()
921
921
C .a = X ()
922
922
923
+ @cpython_only
923
924
def test_detach_materialized_dict_no_memory (self ):
924
- import _testcapi
925
- class A :
926
- def __init__ (self ):
927
- self .a = 1
928
- self .b = 2
929
- a = A ()
930
- d = a .__dict__
931
- with test .support .catch_unraisable_exception () as ex :
932
- _testcapi .set_nomemory (0 , 1 )
933
- del a
934
- self .assertEqual (ex .unraisable .exc_type , MemoryError )
935
- with self .assertRaises (KeyError ):
936
- d ["a" ]
925
+ # Skip test if _testcapi is not available:
926
+ import_helper .import_module ('_testcapi' )
927
+
928
+ code = """if 1:
929
+ import test.support
930
+ import _testcapi
931
+
932
+ class A:
933
+ def __init__(self):
934
+ self.a = 1
935
+ self.b = 2
936
+ a = A()
937
+ d = a.__dict__
938
+ with test.support.catch_unraisable_exception() as ex:
939
+ _testcapi.set_nomemory(0, 1)
940
+ del a
941
+ assert ex.unraisable.exc_type is MemoryError
942
+ try:
943
+ d["a"]
944
+ except KeyError:
945
+ pass
946
+ else:
947
+ assert False, "KeyError not raised"
948
+ """
949
+ rc , out , err = script_helper .assert_python_ok ("-c" , code )
950
+ self .assertEqual (rc , 0 )
951
+ self .assertFalse (out , msg = out .decode ('utf-8' ))
952
+ self .assertFalse (err , msg = err .decode ('utf-8' ))
937
953
938
954
if __name__ == '__main__' :
939
955
unittest .main ()
You can’t perform that action at this time.
0 commit comments