Skip to content

Commit c4e78b1

Browse files
ZackerySpytzserhiy-storchaka
authored andcommitted
bpo-14546: Fix the argument handling in Tools/scripts/lll.py (GH-13026)
1 parent 0d5864f commit c4e78b1

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

Lib/test/test_tools/test_lll.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
def test_lll_multiple_dirs(self):
18+
with tempfile.TemporaryDirectory() as dir1, \
19+
tempfile.TemporaryDirectory() as dir2:
20+
fn1 = os.path.join(dir1, 'foo1')
21+
fn2 = os.path.join(dir2, 'foo2')
22+
for fn, dir in (fn1, dir1), (fn2, dir2):
23+
open(fn, 'w').close()
24+
os.symlink(fn, os.path.join(dir, 'symlink'))
25+
26+
with support.captured_stdout() as output:
27+
self.lll.main([dir1, dir2])
28+
self.assertEqual(output.getvalue(),
29+
f'{dir1}:\n'
30+
f'symlink -> {fn1}\n'
31+
f'\n'
32+
f'{dir2}:\n'
33+
f'symlink -> {fn2}\n'
34+
)
35+
36+
37+
if __name__ == '__main__':
38+
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)