Skip to content

Commit 9c512f4

Browse files
committed
bpo-38347: add a test case for the recursive search
Add a test case for the recursive search including filenames with a '-'.
1 parent 7ca16a2 commit 9c512f4

File tree

1 file changed

+35
-16
lines changed

1 file changed

+35
-16
lines changed

Lib/test/test_tools/test_pathfix.py

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,24 @@ class TestPathfixFunctional(unittest.TestCase):
1414
script = os.path.join(scriptsdir, 'pathfix.py')
1515

1616
def setUp(self):
17-
self.temp_file = support.TESTFN
18-
self.addCleanup(support.unlink, support.TESTFN)
17+
self.temp_directory = support.TESTFN + '.d'
18+
self.addCleanup(support.rmtree, self.temp_directory)
19+
os.mkdir(self.temp_directory)
20+
self.temp_file = self.temp_directory + '/' + \
21+
os.path.basename(support.TESTFN) + '-t.py'
22+
self.addCleanup(support.unlink, self.temp_file)
23+
24+
def pathfix(self, shebang, pathfix_flags, exitcode=0, stdout='', stderr='',
25+
target_file=''):
26+
if target_file == '':
27+
target_file = self.temp_file
1928

20-
def pathfix(self, shebang, pathfix_flags, exitcode=0, stdout='', stderr=''):
2129
with open(self.temp_file, 'w', encoding='utf8') as f:
2230
f.write(f'{shebang}\n' + 'print("Hello world")\n')
2331

2432
proc = subprocess.run(
2533
[sys.executable, self.script,
26-
*pathfix_flags, '-n', self.temp_file],
34+
*pathfix_flags, '-n', target_file],
2735
capture_output=True, text=1)
2836

2937
if stdout == '' and proc.returncode == 0:
@@ -44,55 +52,66 @@ def pathfix(self, shebang, pathfix_flags, exitcode=0, stdout='', stderr=''):
4452

4553
return new_shebang
4654

47-
def test_pathfix(self):
55+
def test_recursive(self):
56+
temp_directory_basename = os.path.basename(self.temp_directory)
57+
expected_stderr = f'recursedown(\'{temp_directory_basename}\')\n'
58+
for method_name in dir(self):
59+
method = getattr(self, method_name)
60+
if method_name.startswith('test_') and \
61+
method_name != 'test_recursive' and \
62+
method_name != 'test_pathfix_adding_errors' and \
63+
callable(method):
64+
method(target_file=self.temp_directory, stderr=expected_stderr)
65+
66+
def test_pathfix(self, **kwargs):
4867
self.assertEqual(
4968
self.pathfix(
5069
'#! /usr/bin/env python',
51-
['-i', '/usr/bin/python3']),
70+
['-i', '/usr/bin/python3'], **kwargs),
5271
'#! /usr/bin/python3')
5372
self.assertEqual(
5473
self.pathfix(
5574
'#! /usr/bin/env python -R',
56-
['-i', '/usr/bin/python3']),
75+
['-i', '/usr/bin/python3'], **kwargs),
5776
'#! /usr/bin/python3')
5877

59-
def test_pathfix_keeping_flags(self):
78+
def test_pathfix_keeping_flags(self, **kwargs):
6079
self.assertEqual(
6180
self.pathfix(
6281
'#! /usr/bin/env python -R',
63-
['-i', '/usr/bin/python3', '-k']),
82+
['-i', '/usr/bin/python3', '-k'], **kwargs),
6483
'#! /usr/bin/python3 -R')
6584
self.assertEqual(
6685
self.pathfix(
6786
'#! /usr/bin/env python',
68-
['-i', '/usr/bin/python3', '-k']),
87+
['-i', '/usr/bin/python3', '-k'], **kwargs),
6988
'#! /usr/bin/python3')
7089

71-
def test_pathfix_adding_flag(self):
90+
def test_pathfix_adding_flag(self, **kwargs):
7291
self.assertEqual(
7392
self.pathfix(
7493
'#! /usr/bin/env python',
75-
['-i', '/usr/bin/python3', '-a', 's']),
94+
['-i', '/usr/bin/python3', '-a', 's'], **kwargs),
7695
'#! /usr/bin/python3 -s')
7796
self.assertEqual(
7897
self.pathfix(
7998
'#! /usr/bin/env python -S',
80-
['-i', '/usr/bin/python3', '-a', 's']),
99+
['-i', '/usr/bin/python3', '-a', 's'], **kwargs),
81100
'#! /usr/bin/python3 -s')
82101
self.assertEqual(
83102
self.pathfix(
84103
'#! /usr/bin/env python -V',
85-
['-i', '/usr/bin/python3', '-a', 'v', '-k']),
104+
['-i', '/usr/bin/python3', '-a', 'v', '-k'], **kwargs),
86105
'#! /usr/bin/python3 -vV')
87106
self.assertEqual(
88107
self.pathfix(
89108
'#! /usr/bin/env python',
90-
['-i', '/usr/bin/python3', '-a', 'Rs']),
109+
['-i', '/usr/bin/python3', '-a', 'Rs'], **kwargs),
91110
'#! /usr/bin/python3 -Rs')
92111
self.assertEqual(
93112
self.pathfix(
94113
'#! /usr/bin/env python -W default',
95-
['-i', '/usr/bin/python3', '-a', 's', '-k']),
114+
['-i', '/usr/bin/python3', '-a', 's', '-k'], **kwargs),
96115
'#! /usr/bin/python3 -sW default')
97116

98117
def test_pathfix_adding_errors(self):

0 commit comments

Comments
 (0)