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
@@ -933,20 +933,36 @@ class C:
933
933
C .a = X ()
934
934
C .a = X ()
935
935
936
+ @cpython_only
936
937
def test_detach_materialized_dict_no_memory (self ):
937
- import _testcapi
938
- class A :
939
- def __init__ (self ):
940
- self .a = 1
941
- self .b = 2
942
- a = A ()
943
- d = a .__dict__
944
- with test .support .catch_unraisable_exception () as ex :
945
- _testcapi .set_nomemory (0 , 1 )
946
- del a
947
- self .assertEqual (ex .unraisable .exc_type , MemoryError )
948
- with self .assertRaises (KeyError ):
949
- d ["a" ]
938
+ # Skip test if _testcapi is not available:
939
+ import_helper .import_module ('_testcapi' )
940
+
941
+ code = """if 1:
942
+ import test.support
943
+ import _testcapi
944
+
945
+ class A:
946
+ def __init__(self):
947
+ self.a = 1
948
+ self.b = 2
949
+ a = A()
950
+ d = a.__dict__
951
+ with test.support.catch_unraisable_exception() as ex:
952
+ _testcapi.set_nomemory(0, 1)
953
+ del a
954
+ assert ex.unraisable.exc_type is MemoryError
955
+ try:
956
+ d["a"]
957
+ except KeyError:
958
+ pass
959
+ else:
960
+ assert False, "KeyError not raised"
961
+ """
962
+ rc , out , err = script_helper .assert_python_ok ("-c" , code )
963
+ self .assertEqual (rc , 0 )
964
+ self .assertFalse (out , msg = out .decode ('utf-8' ))
965
+ self .assertFalse (err , msg = err .decode ('utf-8' ))
950
966
951
967
if __name__ == '__main__' :
952
968
unittest .main ()
You can’t perform that action at this time.
0 commit comments