summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_tools
diff options
context:
space:
mode:
authorPatrikKopkan <kopkanpatrik@gmail.com>2019-09-05 14:54:54 (GMT)
committerVictor Stinner <vstinner@redhat.com>2019-09-05 14:54:54 (GMT)
commit50254ac4c179cb412e90682098c97db786143929 (patch)
treeb7f6ad33313bd1c7c0639aa97128dd16902b4db9 /Lib/test/test_tools
parent3038e87ba848023470f571242a8bb5a206c24430 (diff)
downloadcpython-50254ac4c179cb412e90682098c97db786143929.zip
cpython-50254ac4c179cb412e90682098c97db786143929.tar.gz
cpython-50254ac4c179cb412e90682098c97db786143929.tar.bz2
bpo-37064: Add option -k to Tools/scripts/pathfix.py (GH-15548)
Add flag -k to pathscript.py script: preserve shebang flags.
Diffstat (limited to 'Lib/test/test_tools')
-rw-r--r--Lib/test/test_tools/test_pathfix.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/Lib/test/test_tools/test_pathfix.py b/Lib/test/test_tools/test_pathfix.py
new file mode 100644
index 0000000..5c0dd1d
--- /dev/null
+++ b/Lib/test/test_tools/test_pathfix.py
@@ -0,0 +1,64 @@
+import os
+import subprocess
+import sys
+import unittest
+from test import support
+from test.test_tools import import_tool, scriptsdir
+
+
+class TestPathfixFunctional(unittest.TestCase):
+ script = os.path.join(scriptsdir, 'pathfix.py')
+
+ def setUp(self):
+ self.temp_file = support.TESTFN
+ self.addCleanup(support.unlink, support.TESTFN)
+
+ def pathfix(self, shebang, pathfix_flags):
+ with open(self.temp_file, 'w', encoding='utf8') as f:
+ f.write(f'{shebang}\n' + 'print("Hello world")\n')
+
+ proc = subprocess.run(
+ [sys.executable, self.script,
+ *pathfix_flags, '-n', self.temp_file],
+ capture_output=True)
+ self.assertEqual(proc.returncode, 0, proc)
+
+ with open(self.temp_file, 'r', encoding='utf8') as f:
+ output = f.read()
+
+ lines = output.split('\n')
+ self.assertEqual(lines[1:], ['print("Hello world")', ''])
+ shebang = lines[0]
+ return shebang
+
+ def test_pathfix(self):
+ self.assertEqual(
+ self.pathfix(
+ '#! /usr/bin/env python',
+ ['-i', '/usr/bin/python3',]),
+ '#! /usr/bin/python3',
+ )
+ self.assertEqual(
+ self.pathfix(
+ '#! /usr/bin/env python -R',
+ ['-i', '/usr/bin/python3', ]),
+ '#! /usr/bin/python3',
+ )
+
+ def test_pathfix_keeping_flags(self):
+ self.assertEqual(
+ self.pathfix(
+ '#! /usr/bin/env python -R',
+ ['-i', '/usr/bin/python3', '-k',]),
+ '#! /usr/bin/python3 -R',
+ )
+ self.assertEqual(
+ self.pathfix(
+ '#! /usr/bin/env python',
+ ['-i', '/usr/bin/python3', '-k',]),
+ '#! /usr/bin/python3',
+ )
+
+
+if __name__ == '__main__':
+ unittest.main()