summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_tools
diff options
context:
space:
mode:
authorPatrikKopkan <kopkanpatrik@gmail.com>2019-09-25 12:26:28 (GMT)
committerVictor Stinner <vstinner@redhat.com>2019-09-25 12:26:28 (GMT)
commit1dc1acbd73f05f14c974b7ce1041787d7abef31e (patch)
tree696c41e88282f39d350854b9e6fe9c61cede7c17 /Lib/test/test_tools
parent468f8a6ee0d83e36795bbab6f20037b0e380f493 (diff)
downloadcpython-1dc1acbd73f05f14c974b7ce1041787d7abef31e.zip
cpython-1dc1acbd73f05f14c974b7ce1041787d7abef31e.tar.gz
cpython-1dc1acbd73f05f14c974b7ce1041787d7abef31e.tar.bz2
bpo-37064: Add option -a to pathfix.py tool (GH-15717)
Add option -a to Tools/Scripts/pathfix.py script: add flags.
Diffstat (limited to 'Lib/test/test_tools')
-rw-r--r--Lib/test/test_tools/test_pathfix.py73
1 files changed, 56 insertions, 17 deletions
diff --git a/Lib/test/test_tools/test_pathfix.py b/Lib/test/test_tools/test_pathfix.py
index 0c1aea7..a879924 100644
--- a/Lib/test/test_tools/test_pathfix.py
+++ b/Lib/test/test_tools/test_pathfix.py
@@ -17,51 +17,90 @@ class TestPathfixFunctional(unittest.TestCase):
self.temp_file = support.TESTFN
self.addCleanup(support.unlink, support.TESTFN)
- def pathfix(self, shebang, pathfix_flags):
+ def pathfix(self, shebang, pathfix_flags, exitcode=0, stdout='', stderr=''):
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)
+ capture_output=True, text=1)
+
+ if stdout == '' and proc.returncode == 0:
+ stdout = f'{self.temp_file}: updating\n'
+ self.assertEqual(proc.returncode, exitcode, proc)
+ self.assertEqual(proc.stdout, stdout, proc)
+ self.assertEqual(proc.stderr, stderr, 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
+ new_shebang = lines[0]
+
+ if proc.returncode != 0:
+ self.assertEqual(shebang, new_shebang)
+
+ return new_shebang
def test_pathfix(self):
self.assertEqual(
self.pathfix(
'#! /usr/bin/env python',
- ['-i', '/usr/bin/python3',]),
- '#! /usr/bin/python3',
- )
+ ['-i', '/usr/bin/python3']),
+ '#! /usr/bin/python3')
self.assertEqual(
self.pathfix(
'#! /usr/bin/env python -R',
- ['-i', '/usr/bin/python3', ]),
- '#! /usr/bin/python3',
- )
+ ['-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',
- )
+ ['-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',
- )
+ ['-i', '/usr/bin/python3', '-k']),
+ '#! /usr/bin/python3')
+
+ def test_pathfix_adding_flag(self):
+ self.assertEqual(
+ self.pathfix(
+ '#! /usr/bin/env python',
+ ['-i', '/usr/bin/python3', '-a', 's']),
+ '#! /usr/bin/python3 -s')
+ self.assertEqual(
+ self.pathfix(
+ '#! /usr/bin/env python -S',
+ ['-i', '/usr/bin/python3', '-a', 's']),
+ '#! /usr/bin/python3 -s')
+ self.assertEqual(
+ self.pathfix(
+ '#! /usr/bin/env python -V',
+ ['-i', '/usr/bin/python3', '-a', 'v', '-k']),
+ '#! /usr/bin/python3 -vV')
+ self.assertEqual(
+ self.pathfix(
+ '#! /usr/bin/env python',
+ ['-i', '/usr/bin/python3', '-a', 'Rs']),
+ '#! /usr/bin/python3 -Rs')
+ self.assertEqual(
+ self.pathfix(
+ '#! /usr/bin/env python -W default',
+ ['-i', '/usr/bin/python3', '-a', 's', '-k']),
+ '#! /usr/bin/python3 -sW default')
+
+ def test_pathfix_adding_errors(self):
+ self.pathfix(
+ '#! /usr/bin/env python -E',
+ ['-i', '/usr/bin/python3', '-a', 'W default', '-k'],
+ exitcode=2,
+ stderr="-a option doesn't support whitespaces")
if __name__ == '__main__':