File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11"Test the functionality of Python classes implementing operators."
22
33import unittest
4- import test .support
4+ from test .support import cpython_only
5+ from test .support import import_helper , script_helper
56
67testmeths = [
78
@@ -933,20 +934,36 @@ class C:
933934 C .a = X ()
934935 C .a = X ()
935936
937+ @cpython_only
936938 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" ]
939+ # Skip test if _testcapi is not available:
940+ import_helper .import_module ('_testcapi' )
941+
942+ code = """if 1:
943+ import test.support
944+ import _testcapi
945+
946+ class A:
947+ def __init__(self):
948+ self.a = 1
949+ self.b = 2
950+ a = A()
951+ d = a.__dict__
952+ with test.support.catch_unraisable_exception() as ex:
953+ _testcapi.set_nomemory(0, 1)
954+ del a
955+ assert ex.unraisable.exc_type is MemoryError
956+ try:
957+ d["a"]
958+ except KeyError:
959+ pass
960+ else:
961+ assert False, "KeyError not raised"
962+ """
963+ rc , out , err = script_helper .assert_python_ok ("-c" , code )
964+ self .assertEqual (rc , 0 )
965+ self .assertFalse (out , msg = out .decode ('utf-8' ))
966+ self .assertFalse (err , msg = err .decode ('utf-8' ))
950967
951968if __name__ == '__main__' :
952969 unittest .main ()
You can’t perform that action at this time.
0 commit comments