Commits

Philip Jenvey committed c81479f

add _testcapi skips from default + others

Comments (0)

Files changed (5)

lib-python/3/test/test_code.py

 
 import unittest
 import weakref
-import _testcapi
+try:
+    import _testcapi
+except ImportError:
+    _testcapi = None
 from test import support
 
 
 
 class CodeTest(unittest.TestCase):
 
+    @unittest.skipUnless(_testcapi, 'Requires _testcapi')
     def test_newempty(self):
         co = _testcapi.code_newempty("filename", "funcname", 15)
         self.assertEqual(co.co_filename, "filename")

lib-python/3/test/test_codecs.py

 import unittest
 import codecs
 import locale
-import sys, _testcapi, io
+import sys, io
+try:
+    import _testcapi
+except ImportError:
+    _testcapi = None
 
 class Queue(object):
     """
                     decodedresult += reader.read()
                 self.assertEqual(decodedresult, s, "%r != %r (encoding=%r)" % (decodedresult, s, encoding))
 
-            if encoding not in broken_incremental_coders:
+            if encoding not in broken_incremental_coders and _testcapi:
                 # check incremental decoder/encoder (fetched via the Python
                 # and C API) and iterencode()/iterdecode()
                 try:

lib-python/3/test/test_exceptions.py

 import pickle
 import weakref
 import errno
+try:
+    import _testcapi
+except ImportError:
+    _testcapi = None
 
 from test.support import (TESTFN, unlink, run_unittest, captured_output,
                           gc_collect, cpython_only)
         self.assertIn("maximum recursion depth exceeded", str(v))
 
 
+    @unittest.skipUnless(_testcapi, 'Requires _testcapi')
     def test_MemoryError(self):
         # PyErr_NoMemory always raises the same exception instance.
         # Check that the traceback is not doubled.
         self.assertEqual(error5.a, 1)
         self.assertEqual(error5.__doc__, "")
 
+    @unittest.skipUnless(_testcapi, 'Requires _testcapi')
     def test_memory_error_cleanup(self):
         # Issue #5437: preallocated MemoryError instances should not keep
         # traceback objects alive.

lib-python/3/test/test_traceback.py

 """Test cases for traceback module"""
 
-from _testcapi import traceback_print, exception_print
+try:
+    import _testcapi
+except ImportError:
+    _testcapi = None
 from io import StringIO
 import sys
 import unittest
 
 class TracebackFormatTests(unittest.TestCase):
 
+    @unittest.skipUnless(_testcapi, 'Requires _testcapi')
     def test_traceback_format(self):
         try:
             raise KeyError('blah')
             traceback_fmt = 'Traceback (most recent call last):\n' + \
                             ''.join(traceback.format_tb(tb))
             file_ = StringIO()
-            traceback_print(tb, file_)
+            _testcapi.traceback_print(tb, file_)
             python_fmt  = file_.getvalue()
         else:
             raise Error("unable to create test traceback string")
     # This checks built-in reporting by the interpreter.
     #
 
+    @unittest.skipUnless(_testcapi, 'Requires _testcapi')
     def get_report(self, e):
         e = self.get_exception(e)
         with captured_output("stderr") as s:
-            exception_print(e)
+            _testcapi.exception_print(e)
         return s.getvalue()
 
 

lib-python/3/test/test_unicode.py

 import warnings
 from test import support, string_tests
 import _string
+try:
+    import _testcapi
+except ImportError:
+    _testcapi = None
 
 # decorator to skip tests on narrow builds
 requires_wide_build = unittest.skipIf(sys.maxunicode == 65535,
         self.assertEqual(text, 'repr=abc\ufffd')
 
     # Test PyUnicode_AsWideChar()
+    @unittest.skipUnless(_testcapi, 'Requires _testcapi')
     def test_aswidechar(self):
         from _testcapi import unicode_aswidechar
         support.import_module('ctypes')
         self.assertEqual(wchar, nonbmp + '\0')
 
     # Test PyUnicode_AsWideCharString()
+    @unittest.skipUnless(_testcapi, 'Requires _testcapi')
     def test_aswidecharstring(self):
         from _testcapi import unicode_aswidecharstring
         support.import_module('ctypes')
             ]])
         self.assertRaises(TypeError, _string.formatter_field_name_split, 1)
 
+    @unittest.skipUnless(_testcapi, 'Requires _testcapi')
     def test_encode_decimal(self):
         from _testcapi import unicode_encodedecimal
         self.assertEqual(unicode_encodedecimal('123'),
         self.assertEqual(unicode_encodedecimal("123\u20ac\u0660", "replace"),
                          b'123?0')
 
+    @unittest.skipUnless(_testcapi, 'Requires _testcapi')
     def test_transform_decimal(self):
         from _testcapi import unicode_transformdecimaltoascii as transform_decimal
         self.assertEqual(transform_decimal('123'),