Skip to content

Commit 7fca6d7

Browse files
committed
Consolidate importcompletion tests
1 parent 18fc6ff commit 7fca6d7

File tree

2 files changed

+90
-97
lines changed

2 files changed

+90
-97
lines changed

bpython/test/test_import_not_cyclical.py

Lines changed: 0 additions & 97 deletions
This file was deleted.

bpython/test/test_importcompletion.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
import tempfile
13
import unittest
24

35
from bpython.importcompletion import ModuleGatherer
@@ -48,3 +50,91 @@ def test_from_package(self):
4850
self.assertSetEqual(
4951
self.module_gatherer.complete(17, "from xml import d"), {"dom"}
5052
)
53+
54+
55+
class TestAvoidSymbolicLinks(unittest.TestCase):
56+
def setUp(self):
57+
with tempfile.TemporaryDirectory() as import_test_folder:
58+
os.mkdir(os.path.join(import_test_folder, "Level0"))
59+
os.mkdir(os.path.join(import_test_folder, "Right"))
60+
os.mkdir(os.path.join(import_test_folder, "Left"))
61+
62+
current_path = os.path.join(import_test_folder, "Level0")
63+
with open(
64+
os.path.join(current_path, "__init__.py"), "x"
65+
) as init_file:
66+
pass
67+
68+
current_path = os.path.join(current_path, "Level1")
69+
os.mkdir(current_path)
70+
with open(
71+
os.path.join(current_path, "__init__.py"), "x"
72+
) as init_file:
73+
pass
74+
75+
current_path = os.path.join(current_path, "Level2")
76+
os.mkdir(current_path)
77+
with open(
78+
os.path.join(current_path, "__init__.py"), "x"
79+
) as init_file:
80+
pass
81+
82+
os.symlink(
83+
os.path.join(import_test_folder, "Level0/Level1"),
84+
os.path.join(current_path, "Level3"),
85+
True,
86+
)
87+
88+
current_path = os.path.join(import_test_folder, "Right")
89+
with open(
90+
os.path.join(current_path, "__init__.py"), "x"
91+
) as init_file:
92+
pass
93+
94+
os.symlink(
95+
os.path.join(import_test_folder, "Left"),
96+
os.path.join(current_path, "toLeft"),
97+
True,
98+
)
99+
100+
current_path = os.path.join(import_test_folder, "Left")
101+
with open(
102+
os.path.join(current_path, "__init__.py"), "x"
103+
) as init_file:
104+
pass
105+
106+
os.symlink(
107+
os.path.join(import_test_folder, "Right"),
108+
os.path.join(current_path, "toRight"),
109+
True,
110+
)
111+
112+
self.module_gatherer = ModuleGatherer(
113+
[os.path.abspath(import_test_folder)]
114+
)
115+
while self.module_gatherer.find_coroutine():
116+
pass
117+
self.filepaths = [
118+
"Left.toRight.toLeft",
119+
"Left.toRight",
120+
"Left",
121+
"Level0.Level1.Level2.Level3",
122+
"Level0.Level1.Level2",
123+
"Level0.Level1",
124+
"Level0",
125+
"Right",
126+
"Right.toLeft",
127+
"Right.toLeft.toRight",
128+
]
129+
130+
def test_simple_symbolic_link_loop(self):
131+
for thing in self.module_gatherer.modules:
132+
self.assertTrue(thing in self.filepaths)
133+
if thing == "Left.toRight.toLeft":
134+
self.filepaths.remove("Right.toLeft")
135+
self.filepaths.remove("Right.toLeft.toRight")
136+
if thing == "Right.toLeft.toRight":
137+
self.filepaths.remove("Left.toRight.toLeft")
138+
self.filepaths.remove("Left.toRight")
139+
self.filepaths.remove(thing)
140+
self.assertFalse(self.filepaths)

0 commit comments

Comments
 (0)