|
8 | 8 | import json |
9 | 9 | import textwrap |
10 | 10 | from unittest.mock import patch |
| 11 | +import tempfile |
11 | 12 | from copy import copy |
12 | 13 |
|
13 | 14 | from test import support |
@@ -760,6 +761,46 @@ def test_sysconfig_config_vars_no_prefix_cache(self): |
760 | 761 | self.assertEqual(config_vars['exec_prefix'], sys.exec_prefix) |
761 | 762 | self.assertEqual(config_vars['platbase'], sys.exec_prefix) |
762 | 763 |
|
| 764 | + @unittest.skipUnless( |
| 765 | + os.name == "posix" and sys.platform != "darwin", |
| 766 | + "requires shell python-config", |
| 767 | + ) |
| 768 | + @skip_unless_symlink |
| 769 | + @requires_subprocess() |
| 770 | + def test_python_config_symlink(self): |
| 771 | + if not is_python_build(): |
| 772 | + self.skipTest("requires a CPython build directory") |
| 773 | + |
| 774 | + python_config = os.path.join(_PROJECT_BASE, "python-config") |
| 775 | + if not os.path.isfile(python_config): |
| 776 | + self.skipTest("python-config was not built") |
| 777 | + |
| 778 | + with tempfile.TemporaryDirectory() as tmpdir: |
| 779 | + real_prefix = os.path.join(tmpdir, "real") |
| 780 | + real_bindir = os.path.join(real_prefix, "bin") |
| 781 | + os.makedirs(real_bindir) |
| 782 | + |
| 783 | + real_config = os.path.join(real_bindir, "python-config") |
| 784 | + shutil.copyfile(python_config, real_config) |
| 785 | + |
| 786 | + link_prefix = os.path.join(tmpdir, "link") |
| 787 | + link_bindir = os.path.join(link_prefix, "bin") |
| 788 | + os.makedirs(link_bindir) |
| 789 | + |
| 790 | + linked_config = os.path.join(link_bindir, "python-config") |
| 791 | + os.symlink(real_config, linked_config) |
| 792 | + |
| 793 | + def get_prefix(config): |
| 794 | + return subprocess.check_output( |
| 795 | + ["/bin/sh", config, "--prefix"], |
| 796 | + text=True, |
| 797 | + ).strip() |
| 798 | + |
| 799 | + expected = os.path.realpath(real_prefix) |
| 800 | + |
| 801 | + self.assertEqual(get_prefix(real_config), expected) |
| 802 | + self.assertEqual(get_prefix(linked_config), expected) |
| 803 | + |
763 | 804 |
|
764 | 805 | class MakefileTests(unittest.TestCase): |
765 | 806 |
|
|
0 commit comments