1"""Tests for the lll script in the Tools/script directory."""
2
3import os
4import tempfile
5from test import support
6from test.test_tools import skip_if_missing, import_tool
7import unittest
8
9skip_if_missing()
10
11
12class 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            prefix = '\\\\?\\' if os.name == 'nt' else ''
30            self.assertEqual(output.getvalue(),
31                f'{dir1}:\n'
32                f'symlink -> {prefix}{fn1}\n'
33                f'\n'
34                f'{dir2}:\n'
35                f'symlink -> {prefix}{fn2}\n'
36            )
37
38
39if __name__ == '__main__':
40    unittest.main()
41