cpython/Lib/test/test_capi/test_build.py
Victor Stinner 1de946cf6a
[3.14] gh-158445: Add C API tests on build information functions (#159515) (#159525)
[3.15] gh-158445: Add C API tests on build information functions (#159515)

* gh-158445: Add C API tests on build information functions (#158603)

Add tests on functions:

* Py_GetBuildInfo()
* Py_GetCompiler()
* Py_GetCopyright()
* Py_GetPlatform()
* Py_GetVersion()

Changes:

* Add Modules/_testlimitedcapi.c and
  Lib/test/test_capi/test_build.py files.
* Add internal _Py_GetBuiltWithAssert() function.
* Reimplemenet support.built_with_c_assertions() using
  _Py_GetBuiltWithAssert() to cover more cases like buildbots using
  CFLAGS=-UNDEBUG in release mode.

(cherry picked from commit a831abba14)

* gh-155742: Add support.built_with_c_assertions() (#156776)


(cherry picked from commit c700121b15)

---------


(cherry picked from commit cb7a629f4d)

Co-authored-by: Stan Ulbrych <stan@python.org>
2026-10-16 12:03:56 +00:00

39 lines
1.2 KiB
Python

import sys
import unittest
from test.support import import_helper
_testlimitedcapi = import_helper.import_module('_testlimitedcapi')
class CAPITest(unittest.TestCase):
# Test Py_GetVersion()
def test_getversion(self):
self.assertEqual(_testlimitedcapi.py_getversion(), sys.version)
# Test Py_GetPlatform()
def test_getplatform(self):
self.assertEqual(_testlimitedcapi.py_getplatform(), sys.platform)
# Test Py_GetCopyright()
def test_getcopyright(self):
self.assertEqual(_testlimitedcapi.py_getcopyright(), sys.copyright)
# Test Py_GetCompiler()
def test_getcompiler(self):
compiler = _testlimitedcapi.py_getcompiler()
self.assertIsInstance(compiler, str)
self.assertNotEqual(compiler, '')
# Test Py_GetBuildInfo()
def test_getbuildinfo(self):
buildinfo = _testlimitedcapi.py_getbuildinfo()
self.assertIsInstance(buildinfo, str)
self.assertNotEqual(buildinfo, '')
# Test internal _Py_GetBuiltWithAssert()
def test__getbuiltwithassert(self):
self.assertIn(_testlimitedcapi._py_getbuiltwithassert(), (0, 1))
if __name__ == "__main__":
unittest.main()