|
| 1 | +from bpython.test import unittest |
1 | 2 | from bpython.importcompletion import find_modules |
2 | 3 | import os, sys, tempfile |
3 | 4 |
|
|
8 | 9 | print("Can't change the Current Working Directory") |
9 | 10 | sys.exit() |
10 | 11 |
|
11 | | - os.mkdir(os.path.join(os.getcwd(), "Level0") |
| 12 | + os.mkdir(os.path.join(os.getcwd(), "Level0")) |
| 13 | + os.mkdir(os.path.join(os.getcwd(), "Right")) |
| 14 | + os.mkdir(os.path.join(os.getcwd(), "Left")) |
12 | 15 | try: |
13 | | - os.chdir(Level0) |
14 | | - open("__init__.py", w) |
| 16 | + os.chdir("Level0") |
| 17 | + open("__init__.py", "w") |
15 | 18 | except OSError: |
16 | 19 | print("Can't change the Current Working Directory") |
17 | 20 | sys.exit() |
18 | 21 |
|
19 | | - os.mkdir(os.path.join(os.getcwd(), "Level1") |
| 22 | + os.mkdir(os.path.join(os.getcwd(), "Level1")) |
20 | 23 | try: |
21 | | - os.chdir(Level1) |
22 | | - open("__init__.py", w) |
| 24 | + os.chdir("Level1") |
| 25 | + open("__init__.py", "w") |
23 | 26 | except OSError: |
24 | 27 | print("Can't change the Current Working Directory") |
25 | 28 | sys.exit() |
26 | 29 |
|
27 | | - os.mkdir(os.path.join(os.getcwd(), "Level2") |
| 30 | + os.mkdir(os.path.join(os.getcwd(), "Level2")) |
28 | 31 | try: |
29 | | - os.chdir(Level2) |
30 | | - open("__init__.py", w) |
| 32 | + os.chdir("Level2") |
| 33 | + open("__init__.py", "w") |
31 | 34 | except OSError: |
32 | 35 | print("Can't change the Current Working Directory") |
33 | 36 | sys.exit() |
34 | 37 |
|
35 | 38 | os.symlink( |
36 | 39 | "import_test_folder/Level0/Level1", |
37 | | - os.path.join(os.getcwd, "Level3"), |
| 40 | + os.path.join(os.getcwd(), "Level3"), |
38 | 41 | True, |
39 | 42 | ) |
40 | 43 |
|
41 | | - foo = find_modules(os.path.abspath("import_test_folder")) |
| 44 | + try: |
| 45 | + os.chdir(import_test_folder) |
| 46 | + except: |
| 47 | + print("Can't change the Current Working Directory") |
| 48 | + sys.exit() |
| 49 | + |
| 50 | + try: |
| 51 | + os.chdir("Right") |
| 52 | + open("__init__.py", "w") |
| 53 | + except OSError: |
| 54 | + print("Can't change the Current Working Directory") |
| 55 | + sys.exit() |
| 56 | + |
| 57 | + os.symlink( |
| 58 | + "import_test_folder/Left", |
| 59 | + os.path.join(os.getcwd(), "toLeft"), |
| 60 | + True, |
| 61 | + ) |
| 62 | + |
| 63 | + try: |
| 64 | + os.chdir(import_test_folder) |
| 65 | + except: |
| 66 | + print("Can't change the Current Working Directory") |
| 67 | + sys.exit() |
| 68 | + |
| 69 | + try: |
| 70 | + os.chdir("Left") |
| 71 | + open("__init__.py", "w") |
| 72 | + except OSError: |
| 73 | + print("Can't change the Current Working Directory") |
| 74 | + sys.exit() |
| 75 | + |
| 76 | + os.symlink( |
| 77 | + "import_test_folder/Right", |
| 78 | + os.path.join(os.getcwd(), "toRight"), |
| 79 | + True, |
| 80 | + ) |
| 81 | + foob = find_modules(os.path.abspath(import_test_folder)) |
| 82 | + for things in foob: |
| 83 | + print("Yield", things) |
| 84 | + |
| 85 | +class TestAvoidSymbolicLinks(unittest.TestCase): |
| 86 | + def setUp(self): |
| 87 | + self.foo = find_modules(os.path.abspath(import_test_folder)) |
| 88 | + self.counter = 0 |
| 89 | + self.filepaths = ["Level0.Level1.Level2", "Level0.Level1", "Level0", "Right", "Left"] |
| 90 | + |
| 91 | + def test_simple_symbolic_link_loop(self): |
| 92 | + for thing in self.foo: |
| 93 | + self.assertEqual(thing, self.filepaths[self.counter]) |
| 94 | + self.counter = self.counter + 1 |
42 | 95 |
|
43 | | - for thing in foo: |
44 | | - print("YIELD:", thing) |
| 96 | +if __name__ == '__main__': |
| 97 | + unittest.main() |
0 commit comments