Skip to content

Commit 62bed48

Browse files
replaced import test file with them file directory
1 parent 2edc977 commit 62bed48

10 files changed

Lines changed: 66 additions & 16 deletions

File tree

importtest.py

Lines changed: 66 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from bpython.test import unittest
12
from bpython.importcompletion import find_modules
23
import os, sys, tempfile
34

@@ -8,37 +9,89 @@
89
print("Can't change the Current Working Directory")
910
sys.exit()
1011

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"))
1215
try:
13-
os.chdir(Level0)
14-
open("__init__.py", w)
16+
os.chdir("Level0")
17+
open("__init__.py", "w")
1518
except OSError:
1619
print("Can't change the Current Working Directory")
1720
sys.exit()
1821

19-
os.mkdir(os.path.join(os.getcwd(), "Level1")
22+
os.mkdir(os.path.join(os.getcwd(), "Level1"))
2023
try:
21-
os.chdir(Level1)
22-
open("__init__.py", w)
24+
os.chdir("Level1")
25+
open("__init__.py", "w")
2326
except OSError:
2427
print("Can't change the Current Working Directory")
2528
sys.exit()
2629

27-
os.mkdir(os.path.join(os.getcwd(), "Level2")
30+
os.mkdir(os.path.join(os.getcwd(), "Level2"))
2831
try:
29-
os.chdir(Level2)
30-
open("__init__.py", w)
32+
os.chdir("Level2")
33+
open("__init__.py", "w")
3134
except OSError:
3235
print("Can't change the Current Working Directory")
3336
sys.exit()
3437

3538
os.symlink(
3639
"import_test_folder/Level0/Level1",
37-
os.path.join(os.getcwd, "Level3"),
40+
os.path.join(os.getcwd(), "Level3"),
3841
True,
3942
)
4043

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
4295

43-
for thing in foo:
44-
print("YIELD:", thing)
96+
if __name__ == '__main__':
97+
unittest.main()

importtestfolder/Left/__init__.py

Whitespace-only changes.

importtestfolder/Left/toRight

Lines changed: 0 additions & 1 deletion
This file was deleted.

importtestfolder/Level0/Level1/Level2/Level3

Lines changed: 0 additions & 1 deletion
This file was deleted.

importtestfolder/Level0/Level1/Level2/__init__.py

Whitespace-only changes.

importtestfolder/Level0/Level1/__init__.py

Whitespace-only changes.

importtestfolder/Level0/__init__.py

Whitespace-only changes.

importtestfolder/Right/__init__.py

Whitespace-only changes.

importtestfolder/Right/toLeft

Lines changed: 0 additions & 1 deletion
This file was deleted.

importtestfolder/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)