Skip to content

Commit e85ba1e

Browse files
miss-islingtonZackerySpytz
authored andcommitted
[3.7] bpo-14546: Fix the argument handling in Tools/scripts/lll.py (GH-13026) (GH-13060)
(cherry picked from commit c4e78b1) Co-authored-by: Zackery Spytz <[email protected]>
1 parent 3f8f64e commit e85ba1e

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

Lib/test/test_tools/test_lll.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""Tests for the lll script in the Tools/script directory."""
2+
3+
import os
4+
import tempfile
5+
from test import support
6+
from test.test_tools import skip_if_missing, import_tool
7+
import unittest
8+
9+
skip_if_missing()
10+
11+
12+
class lllTests(unittest.TestCase):
13+
14+
def setUp(self):
15+
self.lll = import_tool('lll')
16+
17+
@support.skip_unless_symlink
18+
def test_lll_multiple_dirs(self):
19+
with tempfile.TemporaryDirectory() as dir1, \
20+
tempfile.TemporaryDirectory() as dir2:
21+
fn1 = os.path.join(dir1, 'foo1')
22+
fn2 = os.path.join(dir2, 'foo2')
23+
for fn, dir in (fn1, dir1), (fn2, dir2):
24+
open(fn, 'w').close()
25+
os.symlink(fn, os.path.join(dir, 'symlink'))
26+
27+
with support.captured_stdout() as output:
28+
self.lll.main([dir1, dir2])
29+
self.assertEqual(output.getvalue(),
30+
f'{dir1}:\n'
31+
f'symlink -> {fn1}\n'
32+
f'\n'
33+
f'{dir2}:\n'
34+
f'symlink -> {fn2}\n'
35+
)
36+
37+
38+
if __name__ == '__main__':
39+
unittest.main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix the argument handling in Tools/scripts/lll.py.

Tools/scripts/lll.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@ def lll(dirname):
1313
full = os.path.join(dirname, name)
1414
if os.path.islink(full):
1515
print(name, '->', os.readlink(full))
16-
def main():
17-
args = sys.argv[1:]
16+
def main(args):
1817
if not args: args = [os.curdir]
1918
first = 1
2019
for arg in args:
2120
if len(args) > 1:
2221
if not first: print()
2322
first = 0
2423
print(arg + ':')
25-
lll(arg)
24+
lll(arg)
2625

2726
if __name__ == '__main__':
28-
main()
27+
main(sys.argv[1:])

0 commit comments

Comments
 (0)