8000 bpo-38347: find Python scripts whose name contain a '-' by rpluem · Pull Request #16536 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-38347: find Python scripts whose name contain a '-' #16536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Oct 11, 2019
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bpo-38347: add a test case for the recursive search
Add a test case for the recursive search including filenames with
a '-'.
  • Loading branch information
rpluem committed Oct 8, 2019
commit 92384a53042557bb460ed91e441acfd9b43c4b0c
24 changes: 22 additions & 2 deletions Lib/test/test_tools/test_pathfix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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(
Expand Down
0