<s> from __future__ import print_function <EOL> import numba . unittest_support as unittest <EOL> from numba . compiler import compile_isolated <EOL> from numba import types <EOL> from numba . errors import TypingError <EOL> from . support import TestCase <EOL> import math <EOL> def what ( ) : <EOL> pass <EOL> def foo ( ) : <EOL> return what ( ) <EOL> def bar ( x ) : <EOL> return x . a <EOL> def issue_868 ( a ) : <EOL> return a . shape * <NUM_LIT:2> <EOL> def impossible_return_type ( x ) : <EOL> if x > <NUM_LIT:0> : <EOL> return ( ) <EOL> else : <EOL> return <NUM_LIT> <EOL> def bad_hypot_usage ( ) : <EOL> return math . hypot ( <NUM_LIT:1> ) <EOL> def imprecise_list ( ) : <EOL> l = [ ] <EOL> return len ( l ) <EOL> def unknown_module ( ) : <EOL> return numpyz . int32 ( <NUM_LIT:0> ) <EOL> class TestTypingError ( unittest . TestCase ) : <EOL> def test_unknown_function ( self ) : <EOL> try : <EOL> compile_isolated ( foo , ( ) ) <EOL> except TypingError as e : <EOL> self . assertTrue ( e . msg . startswith ( "<STR_LIT>" ) , e . msg ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_unknown_attrs ( self ) : <EOL> try : <EOL> compile_isolated ( bar , ( types . int32 , ) ) <EOL> except TypingError as e : <EOL> self . assertTrue ( e . msg . startswith ( "<STR_LIT>" ) , e . msg ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_unknown_module ( self ) : <EOL> with self . assertRaises ( TypingError ) as raises : <EOL> compile_isolated ( unknown_module , ( ) ) <EOL> self . assertIn ( "<STR_LIT>" , str ( raises . exception ) ) <EOL> def test_issue_868 ( self ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> compile_isolated ( issue_868 , ( types . Array ( types . int32 , <NUM_LIT:1> , '<STR_LIT:C>' ) , ) ) <EOL> except TypingError as e : <EOL> self . assertTrue ( e . msg . startswith ( '<STR_LIT>' ) ) <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> def test_return_type_unification ( self ) : <EOL> with self . assertRaises ( TypingError ) as raises : <EOL> compile_isolated ( impossible_return_type , ( types . int32 , ) ) <EOL> self . assertIn ( "<STR_LIT>" , <EOL> str ( raises . exception ) ) <EOL> def test_bad_hypot_usage ( self ) : <EOL> with self . assertRaises ( TypingError ) as raises : <EOL> compile_isolated ( bad_hypot_usage , ( ) ) <EOL> errmsg = str ( raises . exception ) <EOL> self . assertIn ( "<STR_LIT>" , errmsg ) <EOL> def test_imprecise_list ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . assertRaises ( TypingError ) as raises : <EOL> compile_isolated ( imprecise_list , ( ) ) <EOL> errmsg = str ( raises . exception ) <EOL> self . assertIn ( "<STR_LIT>" , <EOL> errmsg ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
