summaryrefslogtreecommitdiff
path: root/Lib/test/test_cmd_line_script.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-06-25 15:02:43 +0200
committerGitHub <noreply@github.com>2019-06-25 15:02:43 +0200
commit3939c321c90283b49eddde762656e4b1940e7150 (patch)
treef2b8429629e80925feac81280c7696a16a0328ea /Lib/test/test_cmd_line_script.py
parent080b6b40fa6c6ddc79dcfcadab575bb1be3f47e9 (diff)
downloadcpython-git-3939c321c90283b49eddde762656e4b1940e7150.tar.gz
bpo-20443: _PyConfig_Read() gets the absolute path of run_filename (GH-14053)
Python now gets the absolute path of the script filename specified on the command line (ex: "python3 script.py"): the __file__ attribute of the __main__ module, sys.argv[0] and sys.path[0] become an absolute path, rather than a relative path. * Add _Py_isabs() and _Py_abspath() functions. * _PyConfig_Read() now tries to get the absolute path of run_filename, but keeps the relative path if _Py_abspath() fails. * Reimplement os._getfullpathname() using _Py_abspath(). * Use _Py_isabs() in getpath.c.
Diffstat (limited to 'Lib/test/test_cmd_line_script.py')
-rw-r--r--Lib/test/test_cmd_line_script.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/Lib/test/test_cmd_line_script.py b/Lib/test/test_cmd_line_script.py
index d138ca027c..4677e60c81 100644
--- a/Lib/test/test_cmd_line_script.py
+++ b/Lib/test/test_cmd_line_script.py
@@ -218,6 +218,18 @@ class CmdLineTest(unittest.TestCase):
script_name = _make_test_script(script_dir, 'script')
self._check_script(script_name, script_name, script_name,
script_dir, None,
+ importlib.machinery.SourceFileLoader,
+ expected_cwd=script_dir)
+
+ def test_script_abspath(self):
+ # pass the script using the relative path, expect the absolute path
+ # in __file__ and sys.argv[0]
+ with support.temp_cwd() as script_dir:
+ self.assertTrue(os.path.isabs(script_dir), script_dir)
+
+ script_name = _make_test_script(script_dir, 'script')
+ self._check_script(os.path.basename(script_name), script_name, script_name,
+ script_dir, None,
importlib.machinery.SourceFileLoader)
def test_script_compiled(self):
@@ -542,7 +554,7 @@ class CmdLineTest(unittest.TestCase):
# Issue #16218
source = 'print(ascii(__file__))\n'
- script_name = _make_test_script(os.curdir, name, source)
+ script_name = _make_test_script(os.getcwd(), name, source)
self.addCleanup(support.unlink, script_name)
rc, stdout, stderr = assert_python_ok(script_name)
self.assertEqual(