From 94047a57bd34d23ca009bcf81cedf88a254f8efe Mon Sep 17 00:00:00 2001 From: Ruediger Pluem Date: Wed, 2 Oct 2019 11:30:00 +0200 Subject: [PATCH 01/19] bpo-38347: find Python scripts whose name contain a '-' Allow Python scripts to contain a '-' in their filename when working recursively. --- Tools/scripts/pathfix.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/scripts/pathfix.py b/Tools/scripts/pathfix.py index 237a3d96e9fab50..2a8add7843bb852 100755 --- a/Tools/scripts/pathfix.py +++ b/Tools/scripts/pathfix.py @@ -89,7 +89,7 @@ def main(): sys.exit(bad) -ispythonprog = re.compile(r'^[a-zA-Z0-9_]+\.py$') +ispythonprog = re.compile(r'^[a-zA-Z0-9_-]+\.py$') def ispython(name): From d8e988efe85bfef307258d06bbeae72e4a21d1fe Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Wed, 2 Oct 2019 09:48:43 +0000 Subject: [PATCH 02/19] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20b?= =?UTF-8?q?lurb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Tools/Demos/2019-10-02-09-48-42.bpo-38347.2Tq5D1.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Tools/Demos/2019-10-02-09-48-42.bpo-38347.2Tq5D1.rst diff --git a/Misc/NEWS.d/next/Tools/Demos/2019-10-02-09-48-42.bpo-38347.2Tq5D1.rst b/Misc/NEWS.d/next/Tools/Demos/2019-10-02-09-48-42.bpo-38347.2Tq5D1.rst new file mode 100644 index 000000000000000..b0f6bbc63978241 --- /dev/null +++ b/Misc/NEWS.d/next/Tools/Demos/2019-10-02-09-48-42.bpo-38347.2Tq5D1.rst @@ -0,0 +1 @@ +Allow Python scripts to contain a '-' in their filename when working recursively. \ No newline at end of file From 7ca16a25893a4c5264faa3ff3aedcdfddfc4e2db Mon Sep 17 00:00:00 2001 From: Ruediger Pluem Date: Wed, 2 Oct 2019 14:18:44 +0200 Subject: [PATCH 03/19] bpo-38347: assume all files that end on '.py' are Python scripts Assume all files that end on '.py' are Python scripts when working recursively. --- Tools/scripts/pathfix.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Tools/scripts/pathfix.py b/Tools/scripts/pathfix.py index 2a8add7843bb852..d252321a21a172a 100755 --- a/Tools/scripts/pathfix.py +++ b/Tools/scripts/pathfix.py @@ -89,11 +89,8 @@ def main(): sys.exit(bad) -ispythonprog = re.compile(r'^[a-zA-Z0-9_-]+\.py$') - - def ispython(name): - return bool(ispythonprog.match(name)) + return name.endswith('.py') def recursedown(dirname): From 9c512f4c571df7cce922543473bbf39d2bfa5052 Mon Sep 17 00:00:00 2001 From: Ruediger Pluem Date: Wed, 2 Oct 2019 14:22:05 +0200 Subject: [PATCH 04/19] bpo-38347: add a test case for the recursive search Add a test case for the recursive search including filenames with a '-'. --- Lib/test/test_tools/test_pathfix.py | 51 ++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/Lib/test/test_tools/test_pathfix.py b/Lib/test/test_tools/test_pathfix.py index a879924913445c1..ec83503754124bf 100644 --- a/Lib/test/test_tools/test_pathfix.py +++ b/Lib/test/test_tools/test_pathfix.py @@ -14,16 +14,24 @@ 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) + self.temp_directory = support.TESTFN + '.d' + self.addCleanup(support.rmtree, self.temp_directory) + os.mkdir(self.temp_directory) + self.temp_file = self.temp_directory + '/' + \ + os.path.basename(support.TESTFN) + '-t.py' + self.addCleanup(support.unlink, self.temp_file) + + def pathfix(self, shebang, pathfix_flags, exitcode=0, stdout='', stderr='', + target_file=''): + if target_file == '': + target_file = self.temp_file - 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], + *pathfix_flags, '-n', target_file], capture_output=True, text=1) if stdout == '' and proc.returncode == 0: @@ -44,55 +52,66 @@ def pathfix(self, shebang, pathfix_flags, exitcode=0, stdout='', stderr=''): return new_shebang - def test_pathfix(self): + def test_recursive(self): + temp_directory_basename = os.path.basename(self.temp_directory) + expected_stderr = f'recursedown(\'{temp_directory_basename}\')\n' + for method_name in dir(self): + method = getattr(self, method_name) + if method_name.startswith('test_') and \ + method_name != 'test_recursive' and \ + method_name != 'test_pathfix_adding_errors' and \ + callable(method): + method(target_file=self.temp_directory, stderr=expected_stderr) + + def test_pathfix(self, **kwargs): self.assertEqual( self.pathfix( '#! /usr/bin/env python', - ['-i', '/usr/bin/python3']), + ['-i', '/usr/bin/python3'], **kwargs), '#! /usr/bin/python3') self.assertEqual( self.pathfix( '#! /usr/bin/env python -R', - ['-i', '/usr/bin/python3']), + ['-i', '/usr/bin/python3'], **kwargs), '#! /usr/bin/python3') - def test_pathfix_keeping_flags(self): + def test_pathfix_keeping_flags(self, **kwargs): self.assertEqual( self.pathfix( '#! /usr/bin/env python -R', - ['-i', '/usr/bin/python3', '-k']), + ['-i', '/usr/bin/python3', '-k'], **kwargs), '#! /usr/bin/python3 -R') self.assertEqual( self.pathfix( '#! /usr/bin/env python', - ['-i', '/usr/bin/python3', '-k']), + ['-i', '/usr/bin/python3', '-k'], **kwargs), '#! /usr/bin/python3') - def test_pathfix_adding_flag(self): + def test_pathfix_adding_flag(self, **kwargs): self.assertEqual( self.pathfix( '#! /usr/bin/env python', - ['-i', '/usr/bin/python3', '-a', 's']), + ['-i', '/usr/bin/python3', '-a', 's'], **kwargs), '#! /usr/bin/python3 -s') self.assertEqual( self.pathfix( '#! /usr/bin/env python -S', - ['-i', '/usr/bin/python3', '-a', 's']), + ['-i', '/usr/bin/python3', '-a', 's'], **kwargs), '#! /usr/bin/python3 -s') self.assertEqual( self.pathfix( '#! /usr/bin/env python -V', - ['-i', '/usr/bin/python3', '-a', 'v', '-k']), + ['-i', '/usr/bin/python3', '-a', 'v', '-k'], **kwargs), '#! /usr/bin/python3 -vV') self.assertEqual( self.pathfix( '#! /usr/bin/env python', - ['-i', '/usr/bin/python3', '-a', 'Rs']), + ['-i', '/usr/bin/python3', '-a', 'Rs'], **kwargs), '#! /usr/bin/python3 -Rs') self.assertEqual( self.pathfix( '#! /usr/bin/env python -W default', - ['-i', '/usr/bin/python3', '-a', 's', '-k']), + ['-i', '/usr/bin/python3', '-a', 's', '-k'], **kwargs), '#! /usr/bin/python3 -sW default') def test_pathfix_adding_errors(self): From b1fa966e7719c6d148e8303df6faf41ebe168bf5 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Wed, 2 Oct 2019 12:28:00 +0000 Subject: [PATCH 05/19] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20b?= =?UTF-8?q?lurb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Misc/NEWS.d/next/Tests/2019-10-02-12-27-58.bpo-38347.zdkCBX.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Tests/2019-10-02-12-27-58.bpo-38347.zdkCBX.rst diff --git a/Misc/NEWS.d/next/Tests/2019-10-02-12-27-58.bpo-38347.zdkCBX.rst b/Misc/NEWS.d/next/Tests/2019-10-02-12-27-58.bpo-38347.zdkCBX.rst new file mode 100644 index 000000000000000..405db89912a0b06 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2019-10-02-12-27-58.bpo-38347.zdkCBX.rst @@ -0,0 +1 @@ +Add a test case for the recursive search including filenames with a '-'. \ No newline at end of file From 2dcdef4b36b48e85c3c53f28915c07ad40a8c4a5 Mon Sep 17 00:00:00 2001 From: Ruediger Pluem Date: Wed, 2 Oct 2019 14:56:17 +0200 Subject: [PATCH 06/19] bpo-38347: use os.sep instead of the Unix specific '/' Fix a test failure on Windows by using os.sep instead of the Unix specific '/' as path separator. --- Lib/test/test_tools/test_pathfix.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_tools/test_pathfix.py b/Lib/test/test_tools/test_pathfix.py index ec83503754124bf..6f8459f348b415e 100644 --- a/Lib/test/test_tools/test_pathfix.py +++ b/Lib/test/test_tools/test_pathfix.py @@ -17,7 +17,7 @@ def setUp(self): self.temp_directory = support.TESTFN + '.d' self.addCleanup(support.rmtree, self.temp_directory) os.mkdir(self.temp_directory) - self.temp_file = self.temp_directory + '/' + \ + self.temp_file = self.temp_directory + os.sep + \ os.path.basename(support.TESTFN) + '-t.py' self.addCleanup(support.unlink, self.temp_file) From 07f7158cfd3b6aa5e403317d7e7a3c959222ff5e Mon Sep 17 00:00:00 2001 From: Ruediger Pluem Date: Fri, 4 Oct 2019 12:26:07 +0200 Subject: [PATCH 07/19] bpo-38347: rename variable target_file to filename No functional change. --- Lib/test/test_tools/test_pathfix.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_tools/test_pathfix.py b/Lib/test/test_tools/test_pathfix.py index 6f8459f348b415e..b7d293970a76037 100644 --- a/Lib/test/test_tools/test_pathfix.py +++ b/Lib/test/test_tools/test_pathfix.py @@ -22,16 +22,16 @@ def setUp(self): self.addCleanup(support.unlink, self.temp_file) def pathfix(self, shebang, pathfix_flags, exitcode=0, stdout='', stderr='', - target_file=''): - if target_file == '': - target_file = self.temp_file + filename=''): + if filename == '': + filename = self.temp_file 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', target_file], + *pathfix_flags, '-n', filename], capture_output=True, text=1) if stdout == '' and proc.returncode == 0: @@ -61,7 +61,7 @@ def test_recursive(self): method_name != 'test_recursive' and \ method_name != 'test_pathfix_adding_errors' and \ callable(method): - method(target_file=self.temp_directory, stderr=expected_stderr) + method(filename=self.temp_directory, stderr=expected_stderr) def test_pathfix(self, **kwargs): self.assertEqual( From 14f5aa0d351fddae1e798b5838f498c648bbcbda Mon Sep 17 00:00:00 2001 From: Ruediger Pluem Date: Fri, 4 Oct 2019 12:30:01 +0200 Subject: [PATCH 08/19] bpo-38347: remove unneeded NEWS entry --- Misc/NEWS.d/next/Tests/2019-10-02-12-27-58.bpo-38347.zdkCBX.rst | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Misc/NEWS.d/next/Tests/2019-10-02-12-27-58.bpo-38347.zdkCBX.rst diff --git a/Misc/NEWS.d/next/Tests/2019-10-02-12-27-58.bpo-38347.zdkCBX.rst b/Misc/NEWS.d/next/Tests/2019-10-02-12-27-58.bpo-38347.zdkCBX.rst deleted file mode 100644 index 405db89912a0b06..000000000000000 --- a/Misc/NEWS.d/next/Tests/2019-10-02-12-27-58.bpo-38347.zdkCBX.rst +++ /dev/null @@ -1 +0,0 @@ -Add a test case for the recursive search including filenames with a '-'. \ No newline at end of file From a68ad4207100b365d00ffbb745592408d1d55a98 Mon Sep 17 00:00:00 2001 From: Ruediger Pluem Date: Fri, 4 Oct 2019 12:35:18 +0200 Subject: [PATCH 09/19] bpo-38347: adjust comment to refelct recent changes --- .../next/Tools/Demos/2019-10-02-09-48-42.bpo-38347.2Tq5D1.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Tools/Demos/2019-10-02-09-48-42.bpo-38347.2Tq5D1.rst b/Misc/NEWS.d/next/Tools/Demos/2019-10-02-09-48-42.bpo-38347.2Tq5D1.rst index b0f6bbc63978241..a69f22236f3ca9f 100644 --- a/Misc/NEWS.d/next/Tools/Demos/2019-10-02-09-48-42.bpo-38347.2Tq5D1.rst +++ b/Misc/NEWS.d/next/Tools/Demos/2019-10-02-09-48-42.bpo-38347.2Tq5D1.rst @@ -1 +1 @@ -Allow Python scripts to contain a '-' in their filename when working recursively. \ No newline at end of file +Assume all files that end on '.py' are Python scripts when working recursively. From 05c39a5dd793c45fb6c2f2cff62b947a9576b352 Mon Sep 17 00:00:00 2001 From: Ruediger Pluem Date: Fri, 4 Oct 2019 12:37:27 +0200 Subject: [PATCH 10/19] bpo-38347: forgot to mention pathfix.py --- .../next/Tools/Demos/2019-10-02-09-48-42.bpo-38347.2Tq5D1.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Tools/Demos/2019-10-02-09-48-42.bpo-38347.2Tq5D1.rst b/Misc/NEWS.d/next/Tools/Demos/2019-10-02-09-48-42.bpo-38347.2Tq5D1.rst index a69f22236f3ca9f..ae64a319b575605 100644 --- a/Misc/NEWS.d/next/Tools/Demos/2019-10-02-09-48-42.bpo-38347.2Tq5D1.rst +++ b/Misc/NEWS.d/next/Tools/Demos/2019-10-02-09-48-42.bpo-38347.2Tq5D1.rst @@ -1 +1 @@ -Assume all files that end on '.py' are Python scripts when working recursively. +pathfix.py: Assume all files that end on '.py' are Python scripts when working recursively. From eec25cec15c5282d23bff738911197b0f7751a4f Mon Sep 17 00:00:00 2001 From: Ruediger Pluem Date: Tue, 8 Oct 2019 08:40:37 +0200 Subject: [PATCH 11/19] Revert "bpo-38347: rename variable target_file to filename" This reverts commit 07f7158cfd3b6aa5e403317d7e7a3c959222ff5e. --- Lib/test/test_tools/test_pathfix.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_tools/test_pathfix.py b/Lib/test/test_tools/test_pathfix.py index b7d293970a76037..6f8459f348b415e 100644 --- a/Lib/test/test_tools/test_pathfix.py +++ b/Lib/test/test_tools/test_pathfix.py @@ -22,16 +22,16 @@ def setUp(self): self.addCleanup(support.unlink, self.temp_file) def pathfix(self, shebang, pathfix_flags, exitcode=0, stdout='', stderr='', - filename=''): - if filename == '': - filename = self.temp_file + target_file=''): + if target_file == '': + target_file = self.temp_file 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', filename], + *pathfix_flags, '-n', target_file], capture_output=True, text=1) if stdout == '' and proc.returncode == 0: @@ -61,7 +61,7 @@ def test_recursive(self): method_name != 'test_recursive' and \ method_name != 'test_pathfix_adding_errors' and \ callable(method): - method(filename=self.temp_directory, stderr=expected_stderr) + method(target_file=self.temp_directory, stderr=expected_stderr) def test_pathfix(self, **kwargs): self.assertEqual( From a1be155c20bbdef39b34006cb7aff68a88c72469 Mon Sep 17 00:00:00 2001 From: Ruediger Pluem Date: Tue, 8 Oct 2019 08:40:52 +0200 Subject: [PATCH 12/19] Revert "bpo-38347: use os.sep instead of the Unix specific '/'" This reverts commit 2dcdef4b36b48e85c3c53f28915c07ad40a8c4a5. --- Lib/test/test_tools/test_pathfix.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_tools/test_pathfix.py b/Lib/test/test_tools/test_pathfix.py index 6f8459f348b415e..ec83503754124bf 100644 --- a/Lib/test/test_tools/test_pathfix.py +++ b/Lib/test/test_tools/test_pathfix.py @@ -17,7 +17,7 @@ def setUp(self): self.temp_directory = support.TESTFN + '.d' self.addCleanup(support.rmtree, self.temp_directory) os.mkdir(self.temp_directory) - self.temp_file = self.temp_directory + os.sep + \ + self.temp_file = self.temp_directory + '/' + \ os.path.basename(support.TESTFN) + '-t.py' self.addCleanup(support.unlink, self.temp_file) From 7e606dd55a7ad56eadbb0ee1d20dbb66a3d90b5c Mon Sep 17 00:00:00 2001 From: Ruediger Pluem Date: Tue, 8 Oct 2019 08:40:57 +0200 Subject: [PATCH 13/19] Revert "bpo-38347: add a test case for the recursive search" This reverts commit 9c512f4c571df7cce922543473bbf39d2bfa5052. --- Lib/test/test_tools/test_pathfix.py | 51 +++++++++-------------------- 1 file changed, 16 insertions(+), 35 deletions(-) diff --git a/Lib/test/test_tools/test_pathfix.py b/Lib/test/test_tools/test_pathfix.py index ec83503754124bf..a879924913445c1 100644 --- a/Lib/test/test_tools/test_pathfix.py +++ b/Lib/test/test_tools/test_pathfix.py @@ -14,24 +14,16 @@ class TestPathfixFunctional(unittest.TestCase): script = os.path.join(scriptsdir, 'pathfix.py') def setUp(self): - self.temp_directory = support.TESTFN + '.d' - self.addCleanup(support.rmtree, self.temp_directory) - os.mkdir(self.temp_directory) - self.temp_file = self.temp_directory + '/' + \ - os.path.basename(support.TESTFN) + '-t.py' - self.addCleanup(support.unlink, self.temp_file) - - def pathfix(self, shebang, pathfix_flags, exitcode=0, stdout='', stderr='', - target_file=''): - if target_file == '': - target_file = self.temp_file + self.temp_file = support.TESTFN + self.addCleanup(support.unlink, support.TESTFN) + 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', target_file], + *pathfix_flags, '-n', self.temp_file], capture_output=True, text=1) if stdout == '' and proc.returncode == 0: @@ -52,66 +44,55 @@ def pathfix(self, shebang, pathfix_flags, exitcode=0, stdout='', stderr='', return new_shebang - def test_recursive(self): - temp_directory_basename = os.path.basename(self.temp_directory) - expected_stderr = f'recursedown(\'{temp_directory_basename}\')\n' - for method_name in dir(self): - method = getattr(self, method_name) - if method_name.startswith('test_') and \ - method_name != 'test_recursive' and \ - method_name != 'test_pathfix_adding_errors' and \ - callable(method): - method(target_file=self.temp_directory, stderr=expected_stderr) - - def test_pathfix(self, **kwargs): + def test_pathfix(self): self.assertEqual( self.pathfix( '#! /usr/bin/env python', - ['-i', '/usr/bin/python3'], **kwargs), + ['-i', '/usr/bin/python3']), '#! /usr/bin/python3') self.assertEqual( self.pathfix( '#! /usr/bin/env python -R', - ['-i', '/usr/bin/python3'], **kwargs), + ['-i', '/usr/bin/python3']), '#! /usr/bin/python3') - def test_pathfix_keeping_flags(self, **kwargs): + def test_pathfix_keeping_flags(self): self.assertEqual( self.pathfix( '#! /usr/bin/env python -R', - ['-i', '/usr/bin/python3', '-k'], **kwargs), + ['-i', '/usr/bin/python3', '-k']), '#! /usr/bin/python3 -R') self.assertEqual( self.pathfix( '#! /usr/bin/env python', - ['-i', '/usr/bin/python3', '-k'], **kwargs), + ['-i', '/usr/bin/python3', '-k']), '#! /usr/bin/python3') - def test_pathfix_adding_flag(self, **kwargs): + def test_pathfix_adding_flag(self): self.assertEqual( self.pathfix( '#! /usr/bin/env python', - ['-i', '/usr/bin/python3', '-a', 's'], **kwargs), + ['-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'], **kwargs), + ['-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'], **kwargs), + ['-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'], **kwargs), + ['-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'], **kwargs), + ['-i', '/usr/bin/python3', '-a', 's', '-k']), '#! /usr/bin/python3 -sW default') def test_pathfix_adding_errors(self): From 92384a53042557bb460ed91e441acfd9b43c4b0c Mon Sep 17 00:00:00 2001 From: Ruediger Pluem Date: Tue, 8 Oct 2019 08:57:04 +0200 Subject: [PATCH 14/19] bpo-38347: add a test case for the recursive search Add a test case for the recursive search including filenames with a '-'. --- Lib/test/test_tools/test_pathfix.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_tools/test_pathfix.py b/Lib/test/test_tools/test_pathfix.py index a879924913445c1..d45f3efb8206895 100644 --- a/Lib/test/test_tools/test_pathfix.py +++ b/Lib/test/test_tools/test_pathfix.py @@ -17,13 +17,17 @@ def setUp(self): self.temp_file = support.TESTFN self.addCleanup(support.unlink, support.TESTFN) - def pathfix(self, shebang, pathfix_flags, exitcode=0, stdout='', stderr=''): + def pathfix(self, shebang, pathfix_flags, exitcode=0, stdout='', stderr='', + filename=''): + if filename == '': + filename = self.temp_file + 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], + *pathfix_flags, '-n', filename], capture_output=True, text=1) if stdout == '' and proc.returncode == 0: @@ -44,6 +48,22 @@ def pathfix(self, shebang, pathfix_flags, exitcode=0, stdout='', stderr=''): return new_shebang + def test_recursive(self): + self.temp_directory = support.TESTFN + '.d' + self.addCleanup(support.rmtree, self.temp_directory) + os.mkdir(self.temp_directory) + self.temp_file = self.temp_directory + os.sep + \ + os.path.basename(support.TESTFN) + '-t.py' + temp_directory_basename = os.path.basename(self.temp_directory) + expected_stderr = f'recursedown(\'{temp_directory_basename}\')\n' + self.assertEqual( + self.pathfix( + '#! /usr/bin/env python', + ['-i', '/usr/bin/python3'], + filename=self.temp_directory, + stderr=expected_stderr), + '#! /usr/bin/python3') + def test_pathfix(self): self.assertEqual( self.pathfix( From 9e292375387c817853b4202f1693cc0c1c938f7e Mon Sep 17 00:00:00 2001 From: Ruediger Pluem Date: Thu, 10 Oct 2019 08:51:52 +0200 Subject: [PATCH 15/19] bpo-38347: Use local variables with better names Use local variables with better names instead of class attributes. --- Lib/test/test_tools/test_pathfix.py | 34 ++++++++++++++--------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Lib/test/test_tools/test_pathfix.py b/Lib/test/test_tools/test_pathfix.py index d45f3efb8206895..7e5a7ef5afbecb8 100644 --- a/Lib/test/test_tools/test_pathfix.py +++ b/Lib/test/test_tools/test_pathfix.py @@ -14,29 +14,32 @@ 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, exitcode=0, stdout='', stderr='', - filename=''): - if filename == '': - filename = self.temp_file - - with open(self.temp_file, 'w', encoding='utf8') as f: + directory=''): + if directory: + filename = os.path.join(directory, 'script-A_1.py') + pathfix_arg = directory + else: + filename = support.TESTFN + pathfix_arg = filename + + with open(filename, 'w', encoding='utf8') as f: f.write(f'{shebang}\n' + 'print("Hello world")\n') proc = subprocess.run( [sys.executable, self.script, - *pathfix_flags, '-n', filename], + *pathfix_flags, '-n', pathfix_arg], capture_output=True, text=1) if stdout == '' and proc.returncode == 0: - stdout = f'{self.temp_file}: updating\n' + stdout = f'{filename}: 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: + with open(filename, 'r', encoding='utf8') as f: output = f.read() lines = output.split('\n') @@ -49,18 +52,15 @@ def pathfix(self, shebang, pathfix_flags, exitcode=0, stdout='', stderr='', return new_shebang def test_recursive(self): - self.temp_directory = support.TESTFN + '.d' - self.addCleanup(support.rmtree, self.temp_directory) - os.mkdir(self.temp_directory) - self.temp_file = self.temp_directory + os.sep + \ - os.path.basename(support.TESTFN) + '-t.py' - temp_directory_basename = os.path.basename(self.temp_directory) - expected_stderr = f'recursedown(\'{temp_directory_basename}\')\n' + tmpdir = support.TESTFN + '.d' + self.addCleanup(support.rmtree, tmpdir) + os.mkdir(tmpdir) + expected_stderr = f'recursedown(\'{os.path.basename(tmpdir)}\')\n' self.assertEqual( self.pathfix( '#! /usr/bin/env python', ['-i', '/usr/bin/python3'], - filename=self.temp_directory, + directory=tmpdir, stderr=expected_stderr), '#! /usr/bin/python3') From a17410299b88bb3063daaed18f67efe70c9f2a2c Mon Sep 17 00:00:00 2001 From: Ruediger Pluem Date: Thu, 10 Oct 2019 12:10:43 +0200 Subject: [PATCH 16/19] bpo-38347: move NEWS to the correct location --- .../2019-10-02-09-48-42.bpo-38347.2Tq5D1.rst | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Misc/NEWS.d/next/{Tools/Demos => Tools-Demos}/2019-10-02-09-48-42.bpo-38347.2Tq5D1.rst (100%) diff --git a/Misc/NEWS.d/next/Tools/Demos/2019-10-02-09-48-42.bpo-38347.2Tq5D1.rst b/Misc/NEWS.d/next/Tools-Demos/2019-10-02-09-48-42.bpo-38347.2Tq5D1.rst similarity index 100% rename from Misc/NEWS.d/next/Tools/Demos/2019-10-02-09-48-42.bpo-38347.2Tq5D1.rst rename to Misc/NEWS.d/next/Tools-Demos/2019-10-02-09-48-42.bpo-38347.2Tq5D1.rst From 95e7a2bae6ec4dd8eca06f1d9e7978be3159817f Mon Sep 17 00:00:00 2001 From: Ruediger Pluem Date: Thu, 10 Oct 2019 12:27:06 +0200 Subject: [PATCH 17/19] bpo-38347: Use double quotes instead of single ones Co-Authored-By: Victor Stinner --- Lib/test/test_tools/test_pathfix.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_tools/test_pathfix.py b/Lib/test/test_tools/test_pathfix.py index 7e5a7ef5afbecb8..66052633131bb58 100644 --- a/Lib/test/test_tools/test_pathfix.py +++ b/Lib/test/test_tools/test_pathfix.py @@ -55,7 +55,7 @@ def test_recursive(self): tmpdir = support.TESTFN + '.d' self.addCleanup(support.rmtree, tmpdir) os.mkdir(tmpdir) - expected_stderr = f'recursedown(\'{os.path.basename(tmpdir)}\')\n' + expected_stderr = f"recursedown('{os.path.basename(tmpdir)}')\n" self.assertEqual( self.pathfix( '#! /usr/bin/env python', From 56eaa9441a3f56420817634d910c2575ff288131 Mon Sep 17 00:00:00 2001 From: Ruediger Pluem Date: Fri, 11 Oct 2019 11:26:23 +0200 Subject: [PATCH 18/19] bpo-38347: Add comment to explain the name of the script --- Lib/test/test_tools/test_pathfix.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/test/test_tools/test_pathfix.py b/Lib/test/test_tools/test_pathfix.py index 66052633131bb58..c16a1acfb3b01f5 100644 --- a/Lib/test/test_tools/test_pathfix.py +++ b/Lib/test/test_tools/test_pathfix.py @@ -19,6 +19,8 @@ def setUp(self): def pathfix(self, shebang, pathfix_flags, exitcode=0, stdout='', stderr='', directory=''): if directory: + # bpo-38347: Test filename should contain lowercase, upercase, + # "-", "_" and digits. filename = os.path.join(directory, 'script-A_1.py') pathfix_arg = directory else: From bbab2b405669fc285a8e0c6d52495b0f792b458c Mon Sep 17 00:00:00 2001 From: Ruediger Pluem Date: Fri, 11 Oct 2019 14:53:54 +0200 Subject: [PATCH 19/19] Fix typo Co-Authored-By: Victor Stinner --- Lib/test/test_tools/test_pathfix.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_tools/test_pathfix.py b/Lib/test/test_tools/test_pathfix.py index c16a1acfb3b01f5..ec361178e6d81f4 100644 --- a/Lib/test/test_tools/test_pathfix.py +++ b/Lib/test/test_tools/test_pathfix.py @@ -19,7 +19,7 @@ def setUp(self): def pathfix(self, shebang, pathfix_flags, exitcode=0, stdout='', stderr='', directory=''): if directory: - # bpo-38347: Test filename should contain lowercase, upercase, + # bpo-38347: Test filename should contain lowercase, uppercase, # "-", "_" and digits. filename = os.path.join(directory, 'script-A_1.py') pathfix_arg = directory