forked from jspahrsummers/adt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add test cases for issues jspahrsummers#21, jspahrsummers#25, jspahrsummers#26 * Test case for jspahrsummers#21 is active because it passes with mypy==0.711 * Test cases for jspahrsummers#25 and jspahrsummers#26 are deactivated because they fail
- Loading branch information
Showing
4 changed files
with
93 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from adt import adt, Case | ||
|
||
|
||
@adt | ||
class Cmd: | ||
CASE0: Case | ||
CASE1: Case[str] | ||
CASE2: Case[str, str] | ||
CASE3: Case[str, str, str] |
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,9 @@ | ||
from adt import adt, Case | ||
|
||
|
||
@adt | ||
class Expression: | ||
LITERAL: Case[float] | ||
|
||
|
||
result: None = Expression.LITERAL(0.1).match(literal=lambda n: None) |
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,15 @@ | ||
from typing import Optional | ||
from adt import adt, Case | ||
|
||
|
||
@adt | ||
class ExampleADT: | ||
EMPTY: Case | ||
INTEGER: Case[int] | ||
STRING_PAIR: Case[str, str] | ||
|
||
@property | ||
def safe_integer(self) -> Optional[int]: | ||
return self.match(empty=lambda: None, | ||
integer=lambda n: n, | ||
string_pair=lambda a, b: None) |
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,60 @@ | ||
import unittest | ||
import mypy.main | ||
import mypy.version | ||
import os | ||
import sys | ||
import io | ||
|
||
|
||
class SimpleBuffer(io.TextIOBase): | ||
"""Simple memory buffer that behaves like a file""" | ||
|
||
def __init__(self): | ||
self.__buffer = [] | ||
|
||
def write(self, text): | ||
self.__buffer.append(text) | ||
print(text, end="") | ||
return len(text) | ||
|
||
def read(self): | ||
return ''.join(self.__buffer) | ||
|
||
def __str__(self): | ||
return self.read() | ||
|
||
|
||
class TestMyPyPlugin(unittest.TestCase): | ||
def test_issue21(self) -> None: | ||
self._call_mypy_on_source_file("issue21.py") | ||
|
||
def _test_issue25(self) -> None: | ||
# TODO: This is a deactivated test for issue #25. | ||
# Activate it when working on it. | ||
# cf. https://github.com/jspahrsummers/adt/issues/25 | ||
self._call_mypy_on_source_file("issue25.py") | ||
|
||
def _test_issue26(self) -> None: | ||
# TODO: This is a deactivated test for issue #26. | ||
# Activate it when working on it. | ||
# cf. https://github.com/jspahrsummers/adt/issues/26 | ||
self._call_mypy_on_source_file("issue26.py") | ||
|
||
def _test_readme_examples(self) -> None: | ||
# TODO: This fails because of issue #26. Deactivated this test. | ||
self._call_mypy_on_source_file("readme_examples.py") | ||
|
||
def _call_mypy_on_source_file(self, source_file_name: str): | ||
print( | ||
f"Testing {source_file_name} with mypy=={mypy.version.__version__}" | ||
) | ||
self._call_mypy_on_path( | ||
os.path.join(os.path.dirname(__file__), "source_files", | ||
source_file_name)) | ||
|
||
def _call_mypy_on_path(self, testfile): | ||
output = SimpleBuffer() | ||
try: | ||
mypy.main.main(None, output, sys.stderr, args=[testfile]) | ||
except SystemExit: | ||
self.fail(msg="Error during type-check:\n{}".format(output)) |