|
9 | 9 | import textwrap
|
10 | 10 | from copy import copy
|
11 | 11 |
|
| 12 | +from test import support |
12 | 13 | from test.support import (
|
13 | 14 | captured_stdout,
|
14 | 15 | is_android,
|
@@ -455,20 +456,20 @@ def test_library(self):
|
455 | 456 | library = sysconfig.get_config_var('LIBRARY')
|
456 | 457 | ldlibrary = sysconfig.get_config_var('LDLIBRARY')
|
457 | 458 | major, minor = sys.version_info[:2]
|
458 |
| - if sys.platform == 'win32': |
459 |
| - self.assertTrue(library.startswith(f'python{major}{minor}')) |
460 |
| - self.assertTrue(library.endswith('.dll')) |
| 459 | + abiflags = sysconfig.get_config_var('ABIFLAGS') |
| 460 | + if sys.platform.startswith('win'): |
| 461 | + self.assertEqual(library, f'python{major}{minor}{abiflags}.dll') |
461 | 462 | self.assertEqual(library, ldlibrary)
|
462 | 463 | elif is_apple_mobile:
|
463 | 464 | framework = sysconfig.get_config_var('PYTHONFRAMEWORK')
|
464 | 465 | self.assertEqual(ldlibrary, f"{framework}.framework/{framework}")
|
465 | 466 | else:
|
466 |
| - self.assertTrue(library.startswith(f'libpython{major}.{minor}')) |
467 |
| - self.assertTrue(library.endswith('.a')) |
| 467 | + self.assertStartsWith(library, f'libpython{major}.{minor}') |
| 468 | + self.assertEndsWith(library, '.a') |
468 | 469 | if sys.platform == 'darwin' and sys._framework:
|
469 | 470 | self.skipTest('gh-110824: skip LDLIBRARY test for framework build')
|
470 | 471 | else:
|
471 |
| - self.assertTrue(ldlibrary.startswith(f'libpython{major}.{minor}')) |
| 472 | + self.assertStartsWith(ldlibrary, f'libpython{major}.{minor}') |
472 | 473 |
|
473 | 474 | @unittest.skipUnless(sys.platform == "darwin", "test only relevant on MacOSX")
|
474 | 475 | @requires_subprocess()
|
@@ -592,6 +593,63 @@ def test_osx_ext_suffix(self):
|
592 | 593 | suffix = sysconfig.get_config_var('EXT_SUFFIX')
|
593 | 594 | self.assertTrue(suffix.endswith('-darwin.so'), suffix)
|
594 | 595 |
|
| 596 | + def test_always_set_py_debug(self): |
| 597 | + self.assertIn('Py_DEBUG', sysconfig.get_config_vars()) |
| 598 | + Py_DEBUG = sysconfig.get_config_var('Py_DEBUG') |
| 599 | + self.assertIn(Py_DEBUG, (0, 1)) |
| 600 | + self.assertEqual(Py_DEBUG, support.Py_DEBUG) |
| 601 | + |
| 602 | + def test_always_set_py_gil_disabled(self): |
| 603 | + self.assertIn('Py_GIL_DISABLED', sysconfig.get_config_vars()) |
| 604 | + Py_GIL_DISABLED = sysconfig.get_config_var('Py_GIL_DISABLED') |
| 605 | + self.assertIn(Py_GIL_DISABLED, (0, 1)) |
| 606 | + self.assertEqual(Py_GIL_DISABLED, support.Py_GIL_DISABLED) |
| 607 | + |
| 608 | + def test_abiflags(self): |
| 609 | + # If this test fails on some platforms, maintainers should update the |
| 610 | + # test to make it pass, rather than changing the definition of ABIFLAGS. |
| 611 | + self.assertIn('abiflags', sysconfig.get_config_vars()) |
| 612 | + self.assertIn('ABIFLAGS', sysconfig.get_config_vars()) |
| 613 | + abiflags = sysconfig.get_config_var('abiflags') |
| 614 | + ABIFLAGS = sysconfig.get_config_var('ABIFLAGS') |
| 615 | + self.assertIsInstance(abiflags, str) |
| 616 | + self.assertIsInstance(ABIFLAGS, str) |
| 617 | + self.assertIn(abiflags, ABIFLAGS) |
| 618 | + if os.name == 'nt': |
| 619 | + self.assertEqual(abiflags, '') |
| 620 | + |
| 621 | + if not sys.platform.startswith('win'): |
| 622 | + valid_abiflags = ('', 't', 'd', 'td') |
| 623 | + else: |
| 624 | + # Windows uses '_d' rather than 'd'; see also test_abi_debug below |
| 625 | + valid_abiflags = ('', 't', '_d', 't_d') |
| 626 | + |
| 627 | + self.assertIn(ABIFLAGS, valid_abiflags) |
| 628 | + |
| 629 | + def test_abi_debug(self): |
| 630 | + ABIFLAGS = sysconfig.get_config_var('ABIFLAGS') |
| 631 | + if support.Py_DEBUG: |
| 632 | + self.assertIn('d', ABIFLAGS) |
| 633 | + else: |
| 634 | + self.assertNotIn('d', ABIFLAGS) |
| 635 | + |
| 636 | + # The 'd' flag should always be the last one on Windows. |
| 637 | + # On Windows, the debug flag is used differently with a underscore prefix. |
| 638 | + # For example, `python{X}.{Y}td` on Unix and `python{X}.{Y}t_d.exe` on Windows. |
| 639 | + if support.Py_DEBUG and sys.platform.startswith('win'): |
| 640 | + self.assertEndsWith(ABIFLAGS, '_d') |
| 641 | + |
| 642 | + def test_abi_thread(self): |
| 643 | + abi_thread = sysconfig.get_config_var('abi_thread') |
| 644 | + ABIFLAGS = sysconfig.get_config_var('ABIFLAGS') |
| 645 | + self.assertIsInstance(abi_thread, str) |
| 646 | + if support.Py_GIL_DISABLED: |
| 647 | + self.assertEqual(abi_thread, 't') |
| 648 | + self.assertIn('t', ABIFLAGS) |
| 649 | + else: |
| 650 | + self.assertEqual(abi_thread, '') |
| 651 | + self.assertNotIn('t', ABIFLAGS) |
| 652 | + |
595 | 653 | @requires_subprocess()
|
596 | 654 | def test_makefile_overwrites_config_vars(self):
|
597 | 655 | script = textwrap.dedent("""
|
|
0 commit comments