FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pytype/pytype/module_utils_test.py at master · kmr0877/pytype · GitHub
kmr0877
/
pytype
Public
forked from
google/pytype
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
pytype
/
pytype
/
module_utils_test.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
69 lines (51 loc) · 2.37 KB
Breadcrumbs
pytype
/
pytype
/
module_utils_test.py
Copy path
File metadata and controls
69 lines (51 loc) · 2.37 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
"""Tests for module_utils.py."""
import
os
from
pytype
import
file_utils
from
pytype
import
module_utils
import
unittest
class
ModuleUtilsTest
(
unittest
.
TestCase
):
"""Test module utilities."""
def
testGetAbsoluteName
(
self
):
test_cases
=
[
(
"x.y"
,
"a.b"
,
"x.y.a.b"
),
(
""
,
"a.b"
,
"a.b"
),
(
"x.y"
,
".a.b"
,
"x.y.a.b"
),
(
"x.y"
,
"..a.b"
,
"x.a.b"
),
(
"x.y"
,
"...a.b"
,
None
),
]
for
prefix
,
name
,
expected
in
test_cases
:
self
.
assertEqual
(
module_utils
.
get_absolute_name
(
prefix
,
name
),
expected
)
def
testPathToModuleName
(
self
):
self
.
assertIsNone
(
module_utils
.
path_to_module_name
(
"../foo.py"
))
self
.
assertEqual
(
"x.y.z"
,
module_utils
.
path_to_module_name
(
"x/y/z.pyi"
))
self
.
assertEqual
(
"x.y.z"
,
module_utils
.
path_to_module_name
(
"x/y/z.pytd"
))
self
.
assertEqual
(
"x.y.z"
,
module_utils
.
path_to_module_name
(
"x/y/z/__init__.pyi"
))
# Because TestInferModule expands a lot of paths:
expand
=
file_utils
.
expand_path
class
TestInferModule
(
unittest
.
TestCase
):
"""Test module_utils.infer_module."""
def
assert_module_equal
(
self
,
module
,
path
,
target
,
name
,
kind
=
"Local"
):
self
.
assertEqual
(
module
.
path
.
rstrip
(
os
.
sep
),
path
.
rstrip
(
os
.
sep
))
self
.
assertEqual
(
module
.
target
,
target
)
self
.
assertEqual
(
module
.
name
,
name
)
self
.
assertEqual
(
module
.
kind
,
kind
)
def
test_simple_name
(
self
):
mod
=
module_utils
.
infer_module
(
expand
(
"foo/bar.py"
), [
expand
(
"foo"
)])
self
.
assert_module_equal
(
mod
,
expand
(
"foo"
),
"bar.py"
,
"bar"
)
def
test_name_in_package
(
self
):
mod
=
module_utils
.
infer_module
(
expand
(
"foo/bar/baz.py"
), [
expand
(
"foo"
)])
self
.
assert_module_equal
(
mod
,
expand
(
"foo"
),
"bar/baz.py"
,
"bar.baz"
)
def
test_multiple_paths
(
self
):
pythonpath
=
[
expand
(
"foo"
),
expand
(
"bar/baz"
),
expand
(
"bar"
)]
mod
=
module_utils
.
infer_module
(
expand
(
"bar/baz/qux.py"
),
pythonpath
)
self
.
assert_module_equal
(
mod
,
expand
(
"bar/baz"
),
"qux.py"
,
"qux"
)
mod
=
module_utils
.
infer_module
(
expand
(
"bar/qux.py"
),
pythonpath
)
self
.
assert_module_equal
(
mod
,
expand
(
"bar"
),
"qux.py"
,
"qux"
)
def
test_not_found
(
self
):
mod
=
module_utils
.
infer_module
(
expand
(
"bar/baz.py"
), [
"foo"
])
expected_target
=
expand
(
"bar/baz.py"
)
expected_name
,
_
=
os
.
path
.
splitext
(
expected_target
.
replace
(
os
.
sep
,
"."
))
self
.
assert_module_equal
(
mod
,
""
,
expected_target
,
expected_name
)
if
__name__
==
"__main__"
:
unittest
.
main
()
Back
|
FazBrowse Home
|
New Git URL