Skip to content

Instantly share code, notes, and snippets.

@Grahack
Created March 3, 2014 20:15
Show Gist options
  • Save Grahack/9333665 to your computer and use it in GitHub Desktop.
Save Grahack/9333665 to your computer and use it in GitHub Desktop.
Testing obiwan, I don't understand why some exceptions are not raised.
"""Testing the obiwan module.
https://github.com/williame/obiwan
"""
from obiwan import *
install_obiwan_runtime_check()
def id1(x: int) -> int:
"""Identitée
>>> id1(2)
Traceback (most recent call last):
...
obiwan.ObiwanError: id1()-> is <class 'NoneType'> but should be <class 'int'>
"""
return
def id2(x: int) -> int:
"""Identitée
>>> id2(2)
2
>>> id2(2.0)
Traceback (most recent call last):
...
obiwan.ObiwanError: id(x) is <class 'float'> but should be <class 'int'>
"""
return x
def somme1(a: int, b: int) -> int:
"""Somme
>>> somme1(2, 2)
4
>>> somme1(2, 2.0)
Traceback (most recent call last):
...
obiwan.ObiwanError: somme1(b) is <class 'float'> but should be <class 'int'>
"""
return a + b
def somme2(a: int, b: float) -> number:
"""Somme
>>> somme2(2, 2)
Traceback (most recent call last):
...
obiwan.ObiwanError: somme2(b) is <class 'int'> but should be <class 'float'>
"""
return a + b
import doctest
doctest.testmod()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment