FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
bpython/bpython/test/test_importcompletion.py at main · kroy-dev/bpython · GitHub
kroy-dev
/
bpython
Public
forked from
bpython/bpython
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
bpython
/
bpython
/
test
/
test_importcompletion.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
223 lines (191 loc) · 7.15 KB
Breadcrumbs
bpython
/
bpython
/
test
/
test_importcompletion.py
Copy path
File metadata and controls
223 lines (191 loc) · 7.15 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import
os
import
tempfile
import
unittest
from
pathlib
import
Path
from
bpython
.
importcompletion
import
ModuleGatherer
class
TestSimpleComplete
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
module_gatherer
=
ModuleGatherer
()
self
.
module_gatherer
.
modules
=
[
"zzabc"
,
"zzabd"
,
"zzefg"
,
"zzabc.e"
,
"zzabc.f"
,
"zzefg.a1"
,
"zzefg.a2"
,
]
def
test_simple_completion
(
self
):
self
.
assertSetEqual
(
self
.
module_gatherer
.
complete
(
10
,
"import zza"
), {
"zzabc"
,
"zzabd"
}
)
self
.
assertSetEqual
(
self
.
module_gatherer
.
complete
(
11
,
"import zza"
), {
"zzabc"
,
"zzabd"
}
)
def
test_import_empty
(
self
):
self
.
assertSetEqual
(
self
.
module_gatherer
.
complete
(
13
,
"import zzabc."
),
{
"zzabc.e"
,
"zzabc.f"
},
)
self
.
assertSetEqual
(
self
.
module_gatherer
.
complete
(
14
,
"import zzabc."
),
{
"zzabc.e"
,
"zzabc.f"
},
)
def
test_import
(
self
):
self
.
assertSetEqual
(
self
.
module_gatherer
.
complete
(
14
,
"import zzefg.a"
),
{
"zzefg.a1"
,
"zzefg.a2"
},
)
self
.
assertSetEqual
(
self
.
module_gatherer
.
complete
(
15
,
"import zzefg.a"
),
{
"zzefg.a1"
,
"zzefg.a2"
},
)
@
unittest
.
expectedFailure
def
test_import_blank
(
self
):
self
.
assertSetEqual
(
self
.
module_gatherer
.
complete
(
7
,
"import "
),
{
"zzabc"
,
"zzabd"
,
"zzefg"
},
)
self
.
assertSetEqual
(
self
.
module_gatherer
.
complete
(
8
,
"import "
),
{
"zzabc"
,
"zzabd"
,
"zzefg"
},
)
@
unittest
.
expectedFailure
def
test_from_import_empty
(
self
):
self
.
assertSetEqual
(
self
.
module_gatherer
.
complete
(
5
,
"from "
),
{
"zzabc"
,
"zzabd"
,
"zzefg"
},
)
self
.
assertSetEqual
(
self
.
module_gatherer
.
complete
(
6
,
"from "
),
{
"zzabc"
,
"zzabd"
,
"zzefg"
},
)
@
unittest
.
expectedFailure
def
test_from_module_import_empty
(
self
):
self
.
assertSetEqual
(
self
.
module_gatherer
.
complete
(
18
,
"from zzabc import "
), {
"e"
,
"f"
}
)
self
.
assertSetEqual
(
self
.
module_gatherer
.
complete
(
19
,
"from zzabc import "
), {
"e"
,
"f"
}
)
self
.
assertSetEqual
(
self
.
module_gatherer
.
complete
(
19
,
"from zzabc import "
), {
"e"
,
"f"
}
)
self
.
assertSetEqual
(
self
.
module_gatherer
.
complete
(
19
,
"from zzabc import "
), {
"e"
,
"f"
}
)
def
test_from_module_import
(
self
):
self
.
assertSetEqual
(
self
.
module_gatherer
.
complete
(
19
,
"from zzefg import a"
),
{
"a1"
,
"a2"
},
)
self
.
assertSetEqual
(
self
.
module_gatherer
.
complete
(
20
,
"from zzefg import a"
),
{
"a1"
,
"a2"
},
)
self
.
assertSetEqual
(
self
.
module_gatherer
.
complete
(
20
,
"from zzefg import a"
),
{
"a1"
,
"a2"
},
)
self
.
assertSetEqual
(
self
.
module_gatherer
.
complete
(
20
,
"from zzefg import a"
),
{
"a1"
,
"a2"
},
)
class
TestRealComplete
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
module_gatherer
=
ModuleGatherer
()
while
self
.
module_gatherer
.
find_coroutine
():
pass
__import__
(
"sys"
)
__import__
(
"os"
)
def
test_from_attribute
(
self
):
self
.
assertSetEqual
(
self
.
module_gatherer
.
complete
(
19
,
"from sys import arg"
), {
"argv"
}
)
def
test_from_attr_module
(
self
):
self
.
assertSetEqual
(
self
.
module_gatherer
.
complete
(
9
,
"from os.p"
), {
"os.path"
}
)
def
test_from_package
(
self
):
self
.
assertSetEqual
(
self
.
module_gatherer
.
complete
(
17
,
"from xml import d"
), {
"dom"
}
)
class
TestAvoidSymbolicLinks
(
unittest
.
TestCase
):
def
setUp
(
self
):
with
tempfile
.
TemporaryDirectory
()
as
import_test_folder
:
base_path
=
Path
(
import_test_folder
)
(
base_path
/
"Level0"
/
"Level1"
/
"Level2"
).
mkdir
(
parents
=
True
)
(
base_path
/
"Left"
).
mkdir
(
parents
=
True
)
(
base_path
/
"Right"
).
mkdir
(
parents
=
True
)
current_path
=
base_path
/
"Level0"
(
current_path
/
"__init__.py"
).
touch
()
current_path
=
current_path
/
"Level1"
(
current_path
/
"__init__.py"
).
touch
()
current_path
=
current_path
/
"Level2"
(
current_path
/
"__init__.py"
).
touch
()
# Level0/Level1/Level2/Level3 -> Level0/Level1
(
current_path
/
"Level3"
).
symlink_to
(
base_path
/
"Level0"
/
"Level1"
,
target_is_directory
=
True
)
current_path
=
base_path
/
"Right"
(
current_path
/
"__init__.py"
).
touch
()
# Right/toLeft -> Left
(
current_path
/
"toLeft"
).
symlink_to
(
base_path
/
"Left"
,
target_is_directory
=
True
)
current_path
=
base_path
/
"Left"
(
current_path
/
"__init__.py"
).
touch
()
# Left/toRight -> Right
(
current_path
/
"toRight"
).
symlink_to
(
base_path
/
"Right"
,
target_is_directory
=
True
)
self
.
module_gatherer
=
ModuleGatherer
((
base_path
.
absolute
(),))
while
self
.
module_gatherer
.
find_coroutine
():
pass
def
test_simple_symbolic_link_loop
(
self
):
filepaths
=
[
"Left.toRight.toLeft"
,
"Left.toRight"
,
"Left"
,
"Level0.Level1.Level2.Level3"
,
"Level0.Level1.Level2"
,
"Level0.Level1"
,
"Level0"
,
"Right"
,
"Right.toLeft"
,
"Right.toLeft.toRight"
,
]
for
thing
in
self
.
module_gatherer
.
modules
:
self
.
assertIn
(
thing
,
filepaths
)
if
thing
==
"Left.toRight.toLeft"
:
filepaths
.
remove
(
"Right.toLeft"
)
filepaths
.
remove
(
"Right.toLeft.toRight"
)
if
thing
==
"Right.toLeft.toRight"
:
filepaths
.
remove
(
"Left.toRight.toLeft"
)
filepaths
.
remove
(
"Left.toRight"
)
filepaths
.
remove
(
thing
)
self
.
assertFalse
(
filepaths
)
class
TestBugReports
(
unittest
.
TestCase
):
def
test_issue_847
(
self
):
with
tempfile
.
TemporaryDirectory
()
as
import_test_folder
:
# ./xyzzy
# ./xyzzy/__init__.py
# ./xyzzy/plugh
# ./xyzzy/plugh/__init__.py
# ./xyzzy/plugh/bar.py
# ./xyzzy/plugh/foo.py
base_path
=
Path
(
import_test_folder
)
(
base_path
/
"xyzzy"
/
"plugh"
).
mkdir
(
parents
=
True
)
(
base_path
/
"xyzzy"
/
"__init__.py"
).
touch
()
(
base_path
/
"xyzzy"
/
"plugh"
/
"__init__.py"
).
touch
()
(
base_path
/
"xyzzy"
/
"plugh"
/
"bar.py"
).
touch
()
(
base_path
/
"xyzzy"
/
"plugh"
/
"foo.py"
).
touch
()
module_gatherer
=
ModuleGatherer
((
base_path
.
absolute
(),))
while
module_gatherer
.
find_coroutine
():
pass
self
.
assertSetEqual
(
module_gatherer
.
complete
(
17
,
"from xyzzy.plugh."
),
{
"xyzzy.plugh.bar"
,
"xyzzy.plugh.foo"
},
)
if
__name__
==
"__main__"
:
unittest
.
main
()
Back
|
FazBrowse Home
|
New Git URL