forked from bpython/bpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_import_not_cyclical.py
More file actions
95 lines (80 loc) · 3.07 KB
/
test_import_not_cyclical.py
File metadata and controls
95 lines (80 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import os
import tempfile
from bpython.test import unittest
from bpython.importcompletion import find_modules
class TestAvoidSymbolicLinks(unittest.TestCase):
def setUp(self):
with tempfile.TemporaryDirectory() as import_test_folder:
os.mkdir(os.path.join(import_test_folder, "Level0"))
os.mkdir(os.path.join(import_test_folder, "Right"))
os.mkdir(os.path.join(import_test_folder, "Left"))
current_path = os.path.join(import_test_folder, "Level0")
with open(
os.path.join(current_path, "__init__.py"), "x"
) as init_file:
pass
current_path = os.path.join(current_path, "Level1")
os.mkdir(current_path)
with open(
os.path.join(current_path, "__init__.py"), "x"
) as init_file:
pass
current_path = os.path.join(current_path, "Level2")
os.mkdir(current_path)
with open(
os.path.join(current_path, "__init__.py"), "x"
) as init_file:
pass
os.symlink(
os.path.join(import_test_folder, "Level0/Level1"),
os.path.join(current_path, "Level3"),
True,
)
current_path = os.path.join(import_test_folder, "Right")
with open(
os.path.join(current_path, "__init__.py"), "x"
) as init_file:
pass
os.symlink(
os.path.join(import_test_folder, "Left"),
os.path.join(current_path, "toLeft"),
True,
)
current_path = os.path.join(import_test_folder, "Left")
with open(
os.path.join(current_path, "__init__.py"), "x"
) as init_file:
pass
os.symlink(
os.path.join(import_test_folder, "Right"),
os.path.join(current_path, "toRight"),
True,
)
self.modules = list(
find_modules(os.path.abspath(import_test_folder))
)
self.filepaths = [
"Left.toRight.toLeft",
"Left.toRight",
"Left",
"Level0.Level1.Level2.Level3",
"Level0.Level1.Level2",
"Level0.Level1",
"Level0",
"Right",
"Right.toLeft",
"Right.toLeft.toRight",
]
def test_simple_symbolic_link_loop(self):
for thing in self.modules:
self.assertTrue(thing in self.filepaths)
if thing == "Left.toRight.toLeft":
self.filepaths.remove("Right.toLeft")
self.filepaths.remove("Right.toLeft.toRight")
if thing == "Right.toLeft.toRight":
self.filepaths.remove("Left.toRight.toLeft")
self.filepaths.remove("Left.toRight")
self.filepaths.remove(thing)
self.assertFalse(self.filepaths)
if __name__ == "__main__":
unittest.main()