diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-05-24 21:38:03 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-05-24 21:38:03 (GMT) |
commit | 17dc81951acac1e6e6488357085003b3d9a9f48f (patch) | |
tree | 063ec6488cc0f2c8e18a214bbfdaafd7a4f7a1e4 /Lib | |
parent | eb734f77adb23a3cfe90a21679b74aee404d1a31 (diff) | |
parent | 1273b7cd9ccd19a168d3def5c7d1479c5fb6119a (diff) | |
download | cpython-17dc81951acac1e6e6488357085003b3d9a9f48f.zip cpython-17dc81951acac1e6e6488357085003b3d9a9f48f.tar.gz cpython-17dc81951acac1e6e6488357085003b3d9a9f48f.tar.bz2 |
(Merge 3.2) Issue #12070: Fix the Makefile parser of the sysconfig module to
handle correctly references to "bogus variable" (e.g. "prefix=$/opt/python").
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/sysconfig.py | 6 | ||||
-rw-r--r-- | Lib/test/test_sysconfig.py | 34 |
2 files changed, 28 insertions, 12 deletions
diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py index 4c1fd1b..63becb2 100644 --- a/Lib/sysconfig.py +++ b/Lib/sysconfig.py @@ -287,14 +287,16 @@ def _parse_makefile(filename, vars=None): variables.remove(name) if name.startswith('PY_') \ - and name[3:] in renamed_variables: + and name[3:] in renamed_variables: name = name[3:] if name not in done: done[name] = value else: - # bogus variable reference; just drop it since we can't deal + # bogus variable reference (e.g. "prefix=$/opt/python"); + # just drop it since we can't deal + done[name] = value variables.remove(name) # strip spurious spaces diff --git a/Lib/test/test_sysconfig.py b/Lib/test/test_sysconfig.py index 214fc70..5c84a75 100644 --- a/Lib/test/test_sysconfig.py +++ b/Lib/test/test_sysconfig.py @@ -26,7 +26,6 @@ class TestSysConfig(unittest.TestCase): """Make a copy of sys.path""" super(TestSysConfig, self).setUp() self.sys_path = sys.path[:] - self.makefile = None # patching os.uname if hasattr(os, 'uname'): self.uname = os.uname @@ -55,8 +54,6 @@ class TestSysConfig(unittest.TestCase): def tearDown(self): """Restore sys.path""" sys.path[:] = self.sys_path - if self.makefile is not None: - os.unlink(self.makefile) self._cleanup_testfn() if self.uname is not None: os.uname = self.uname @@ -239,12 +236,6 @@ class TestSysConfig(unittest.TestCase): config_h = sysconfig.get_config_h_filename() self.assertTrue(os.path.isfile(config_h), config_h) - @unittest.skipIf(sys.platform.startswith('win'), - 'Test is not Windows compatible') - def test_get_makefile_filename(self): - makefile = sysconfig.get_makefile_filename() - self.assertTrue(os.path.isfile(makefile), makefile) - def test_get_scheme_names(self): wanted = ('nt', 'nt_user', 'os2', 'os2_home', 'osx_framework_user', 'posix_home', 'posix_prefix', 'posix_user') @@ -342,10 +333,33 @@ class TestSysConfig(unittest.TestCase): self.assertEqual(my_platform, test_platform) +class MakefileTests(unittest.TestCase): + @unittest.skipIf(sys.platform.startswith('win'), + 'Test is not Windows compatible') + def test_get_makefile_filename(self): + makefile = sysconfig.get_makefile_filename() + self.assertTrue(os.path.isfile(makefile), makefile) + + def test_parse_makefile(self): + self.addCleanup(unlink, TESTFN) + with open(TESTFN, "w") as makefile: + print("var1=a$(VAR2)", file=makefile) + print("VAR2=b$(var3)", file=makefile) + print("var3=42", file=makefile) + print("var4=$/invalid", file=makefile) + print("var5=dollar$$5", file=makefile) + vars = sysconfig._parse_makefile(TESTFN) + self.assertEqual(vars, { + 'var1': 'ab42', + 'VAR2': 'b42', + 'var3': 42, + 'var4': '$/invalid', + 'var5': 'dollar$5', + }) def test_main(): - run_unittest(TestSysConfig) + run_unittest(TestSysConfig, MakefileTests) if __name__ == "__main__": test_main() |