FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pytype/pytype/abstract_utils_test.py at master · dedsec-9/pytype · GitHub
dedsec-9
pytype
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pytype
/
pytype
/
abstract_utils_test.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
67 lines (55 loc) · 2.25 KB
Breadcrumbs
pytype
/
pytype
/
abstract_utils_test.py
Copy path
File metadata and controls
67 lines (55 loc) · 2.25 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
"""Tests for abstract_utils.py."""
from
pytype
import
abstract_utils
from
pytype
import
config
from
pytype
import
errors
from
pytype
import
load_pytd
from
pytype
import
vm
from
pytype
.
tests
import
test_base
import
six
import
unittest
class
GetViewsTest
(
test_base
.
UnitTest
):
def
setUp
(
self
):
super
().
setUp
()
self
.
_vm
=
vm
.
VirtualMachine
(
errors
.
ErrorLog
(),
config
.
Options
.
create
(
python_version
=
self
.
python_version
),
load_pytd
.
Loader
(
None
,
self
.
python_version
))
def
test_basic
(
self
):
v1
=
self
.
_vm
.
program
.
NewVariable
([
self
.
_vm
.
convert
.
unsolvable
], [],
self
.
_vm
.
root_node
)
v2
=
self
.
_vm
.
program
.
NewVariable
(
[
self
.
_vm
.
convert
.
int_type
,
self
.
_vm
.
convert
.
str_type
], [],
self
.
_vm
.
root_node
)
views
=
list
(
abstract_utils
.
get_views
([
v1
,
v2
],
self
.
_vm
.
root_node
))
six
.
assertCountEqual
(
self
,
[{
v1
:
views
[
0
][
v1
],
v2
:
views
[
0
][
v2
]},
{
v1
:
views
[
1
][
v1
],
v2
:
views
[
1
][
v2
]}],
[{
v1
:
v1
.
bindings
[
0
],
v2
:
v2
.
bindings
[
0
]},
{
v1
:
v1
.
bindings
[
0
],
v2
:
v2
.
bindings
[
1
]}])
def
_test_optimized
(
self
,
skip_future_value
,
expected_num_views
):
v1
=
self
.
_vm
.
program
.
NewVariable
([
self
.
_vm
.
convert
.
unsolvable
], [],
self
.
_vm
.
root_node
)
v2
=
self
.
_vm
.
program
.
NewVariable
(
[
self
.
_vm
.
convert
.
int_type
,
self
.
_vm
.
convert
.
str_type
], [],
self
.
_vm
.
root_node
)
views
=
abstract_utils
.
get_views
([
v1
,
v2
],
self
.
_vm
.
root_node
)
skip_future
=
None
# To count the number of views. Doesn't matter what we put in here, as long
# as it's one per view.
view_markers
=
[]
while
True
:
try
:
view
=
views
.
send
(
skip_future
)
except
StopIteration
:
break
# Accesses v1 only, so the v2 bindings should be deduplicated when
# `skip_future` is True.
view_markers
.
append
(
view
[
v1
])
skip_future
=
skip_future_value
self
.
assertEqual
(
len
(
view_markers
),
expected_num_views
)
def
test_skip
(
self
):
self
.
_test_optimized
(
skip_future_value
=
True
,
expected_num_views
=
1
)
def
test_no_skip
(
self
):
self
.
_test_optimized
(
skip_future_value
=
False
,
expected_num_views
=
2
)
if
__name__
==
"__main__"
:
unittest
.
main
()
Back
|
FazBrowse Home
|
New Git URL