-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b11f15a
commit 11ca89a
Showing
6 changed files
with
109 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# static analysis: ignore | ||
from .test_name_check_visitor import TestNameCheckVisitorBase | ||
from .test_node_visitor import assert_passes | ||
from .value import KnownValue | ||
|
||
|
||
class TestInferenceHelpers(TestNameCheckVisitorBase): | ||
@assert_passes() | ||
def test(self) -> None: | ||
from pyanalyze import dump_value, assert_is_value | ||
from pyanalyze.value import Value | ||
|
||
def capybara(val: Value) -> None: | ||
reveal_type(dump_value) # E: inference_failure | ||
dump_value(reveal_type) # E: inference_failure | ||
assert_is_value(1, KnownValue(1)) | ||
assert_is_value(1, KnownValue(2)) # E: inference_failure | ||
assert_is_value(1, val) # E: inference_failure | ||
|
||
@assert_passes() | ||
def test_return_value(self) -> None: | ||
from pyanalyze import dump_value, assert_is_value | ||
|
||
def capybara(): | ||
x = dump_value(1) # E: inference_failure | ||
y = reveal_type(1) # E: inference_failure | ||
assert_is_value(x, KnownValue(1)) | ||
assert_is_value(y, KnownValue(1)) | ||
|
||
@assert_passes() | ||
def test_assert_type(self) -> None: | ||
from pyanalyze.extensions import assert_type | ||
from typing import Any | ||
|
||
def capybara(x: int) -> None: | ||
assert_type(x, int) | ||
assert_type(x, "int") | ||
assert_type(x, Any) # E: inference_failure | ||
assert_type(x, str) # E: inference_failure | ||
|
||
|
||
class TestAssertError(TestNameCheckVisitorBase): | ||
@assert_passes() | ||
def test(self) -> None: | ||
from pyanalyze.extensions import assert_error | ||
|
||
def f(x: int) -> None: | ||
pass | ||
|
||
def capybara() -> None: | ||
with assert_error(): | ||
f("x") | ||
|
||
with assert_error(): # E: inference_failure | ||
f(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters