Skip to content

Commit 9e29237

Browse files
committed
bpo-38347: Use local variables with better names
Use local variables with better names instead of class attributes.
1 parent 92384a5 commit 9e29237

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

Lib/test/test_tools/test_pathfix.py

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

1616
def setUp(self):
17-
self.temp_file = support.TESTFN
1817
self.addCleanup(support.unlink, support.TESTFN)
1918

2019
def pathfix(self, shebang, pathfix_flags, exitcode=0, stdout='', stderr='',
21-
filename=''):
22-
if filename == '':
23-
filename = self.temp_file
24-
25-
with open(self.temp_file, 'w', encoding='utf8') as f:
20+
directory=''):
21+
if directory:
22+
filename = os.path.join(directory, 'script-A_1.py')
23+
pathfix_arg = directory
24+
else:
25+
filename = support.TESTFN
26+
pathfix_arg = filename
27+
28+
with open(filename, 'w', encoding='utf8') as f:
2629
f.write(f'{shebang}\n' + 'print("Hello world")\n')
2730

2831
proc = subprocess.run(
2932
[sys.executable, self.script,
30-
*pathfix_flags, '-n', filename],
33+
*pathfix_flags, '-n', pathfix_arg],
3134
capture_output=True, text=1)
3235

3336
if stdout == '' and proc.returncode == 0:
34-
stdout = f'{self.temp_file}: updating\n'
37+
stdout = f'{filename}: updating\n'
3538
self.assertEqual(proc.returncode, exitcode, proc)
3639
self.assertEqual(proc.stdout, stdout, proc)
3740
self.assertEqual(proc.stderr, stderr, proc)
3841

39-
with open(self.temp_file, 'r', encoding='utf8') as f:
42+
with open(filename, 'r', encoding='utf8') as f:
4043
output = f.read()
4144

4245
lines = output.split('\n')
@@ -49,18 +52,15 @@ def pathfix(self, shebang, pathfix_flags, exitcode=0, stdout='', stderr='',
4952
return new_shebang
5053

5154
def test_recursive(self):
52-
self.temp_directory = support.TESTFN + '.d'
53-
self.addCleanup(support.rmtree, self.temp_directory)
54-
os.mkdir(self.temp_directory)
55-
self.temp_file = self.temp_directory + os.sep + \
56-
os.path.basename(support.TESTFN) + '-t.py'
57-
temp_directory_basename = os.path.basename(self.temp_directory)
58-
expected_stderr = f'recursedown(\'{temp_directory_basename}\')\n'
55+
tmpdir = support.TESTFN + '.d'
56+
self.addCleanup(support.rmtree, tmpdir)
57+
os.mkdir(tmpdir)
58+
expected_stderr = f'recursedown(\'{os.path.basename(tmpdir)}\')\n'
5959
self.assertEqual(
6060
self.pathfix(
6161
'#! /usr/bin/env python',
6262
['-i', '/usr/bin/python3'],
63-
filename=self.temp_directory,
63+
directory=tmpdir,
6464
stderr=expected_stderr),
6565
'#! /usr/bin/python3')
6666

0 commit comments

Comments
 (0)