Last active
August 29, 2015 14:12
-
-
Save bedekelly/93ee746b7750f730d586 to your computer and use it in GitHub Desktop.
Typechecking for Python - Test Suite
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
""" | |
Quick unit-test for typecheck.py. | |
Wonder if there's any way to unittest an exception's text? | |
""" | |
import unittest | |
from typecheck import typecheck | |
@typecheck | |
def add(x: int, y: int) -> int: | |
"""Returns the sum of the integers x and y as an integer.""" | |
return x + y | |
@typecheck | |
def addReturnsString(x: int, y: int) -> int: | |
"""Returns the sum of the integers x and y as an 'integer'.""" | |
return str(x + y) | |
class TestTypeChecking(unittest.TestCase): | |
def test_correct(self): | |
self.assertIsInstance(add(4,5), int) | |
def test_return_type(self): | |
with self.assertRaises(TypeError): | |
addReturnsString(54, 4) | |
def test_arg_type(self): | |
with self.assertRaises(TypeError): | |
add(4, "hello") | |
if __name__ == "__main__": | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment