<s> from itertools import product <EOL> import pytest <EOL> from blaze . expr import Add , USub , Not , Gt , Mult , Concat , Interp , Repeat , Relational <EOL> from blaze import symbol <EOL> from datashape import dshape , Option <EOL> x = symbol ( '<STR_LIT:x>' , '<STR_LIT>' ) <EOL> y = symbol ( '<STR_LIT:y>' , '<STR_LIT>' ) <EOL> w = symbol ( '<STR_LIT:w>' , '<STR_LIT>' ) <EOL> z = symbol ( '<STR_LIT:z>' , '<STR_LIT>' ) <EOL> a = symbol ( '<STR_LIT:a>' , '<STR_LIT>' ) <EOL> b = symbol ( '<STR_LIT:b>' , '<STR_LIT>' ) <EOL> cs = symbol ( '<STR_LIT>' , '<STR_LIT:string>' ) <EOL> d = symbol ( '<STR_LIT:d>' , '<STR_LIT>' ) <EOL> e = symbol ( '<STR_LIT:e>' , '<STR_LIT>' ) <EOL> f = symbol ( '<STR_LIT:f>' , '<STR_LIT>' ) <EOL> g = symbol ( '<STR_LIT:g>' , '<STR_LIT>' ) <EOL> h = symbol ( '<STR_LIT:h>' , '<STR_LIT>' ) <EOL> i = symbol ( '<STR_LIT:i>' , '<STR_LIT>' ) <EOL> j = symbol ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> k = symbol ( '<STR_LIT:k>' , '<STR_LIT>' ) <EOL> l = symbol ( '<STR_LIT:l>' , '<STR_LIT>' ) <EOL> optionals = { d , e , f } <EOL> def test_arithmetic_dshape_on_collections ( ) : <EOL> assert Add ( x , y ) . shape == x . shape == y . shape <EOL> def test_arithmetic_broadcasts_to_scalars ( ) : <EOL> assert Add ( x , a ) . shape == x . shape <EOL> assert Add ( x , <NUM_LIT:1> ) . shape == x . shape <EOL> def test_unary_ops_are_elemwise ( ) : <EOL> assert USub ( x ) . shape == x . shape <EOL> assert Not ( b ) . shape == b . shape <EOL> @ pytest . mark . parametrize ( '<STR_LIT>' , ( b , f ) ) <EOL> def test_not_dshape ( sym ) : <EOL> if sym in optionals : <EOL> assert Not ( sym ) . schema == dshape ( Option ( '<STR_LIT:bool>' ) ) <EOL> else : <EOL> assert Not ( sym ) . schema == dshape ( '<STR_LIT:bool>' ) <EOL> @ pytest . mark . parametrize ( '<STR_LIT>' , Relational . __subclasses__ ( ) ) <EOL> def test_relations_maintain_shape ( relation_type ) : <EOL> assert relation_type ( x , y ) . shape == x . shape <EOL> @ pytest . mark . parametrize ( '<STR_LIT>' , Relational . __subclasses__ ( ) ) <EOL> @ pytest . mark . parametrize ( '<STR_LIT>' , product ( ( x , y , d , e , f ) , repeat = <NUM_LIT:2> ) ) <EOL> def test_relations_are_boolean ( lhs , rhs , relation_type ) : <EOL> if lhs in optionals or rhs in optionals : <EOL> assert relation_type ( lhs , rhs ) . schema == dshape ( Option ( '<STR_LIT:bool>' ) ) <EOL> else : <EOL> assert relation_type ( lhs , rhs ) . schema == dshape ( '<STR_LIT:bool>' ) <EOL> def test_names ( ) : <EOL> assert Add ( x , <NUM_LIT:1> ) . _name == x . _name <EOL> assert Add ( <NUM_LIT:1> , x ) . _name == x . _name <EOL> assert Mult ( Add ( <NUM_LIT:1> , x ) , <NUM_LIT:2> ) . _name == x . _name <EOL> assert Add ( y , x ) . _name != x . _name <EOL> assert Add ( y , x ) . _name != y . _name <EOL> assert Add ( x , x ) . _name == x . _name <EOL> def test_inputs ( ) : <EOL> assert ( x + y ) . _inputs == ( x , y ) <EOL> assert ( x + <NUM_LIT:1> ) . _inputs == ( x , ) <EOL> assert ( <NUM_LIT:1> + y ) . _inputs == ( y , ) <EOL> def test_printing ( ) : <EOL> assert str ( - x ) == '<STR_LIT>' <EOL> assert str ( - ( x + y ) ) == '<STR_LIT>' <EOL> assert str ( ~ b ) == '<STR_LIT>' <EOL> assert str ( ~ ( b | ( x > y ) ) ) == '<STR_LIT>' <EOL> def test_dir ( ) : <EOL> i = symbol ( '<STR_LIT:i>' , '<STR_LIT>' ) <EOL> d = symbol ( '<STR_LIT:d>' , '<STR_LIT>' ) <EOL> assert isinstance ( i + <NUM_LIT:1> , Add ) <EOL> with pytest . raises ( Exception ) : <EOL> d + <NUM_LIT:1> <EOL> def test_arith_ops_promote_dtype ( ) : <EOL> r = w + z <EOL> assert r . dshape == dshape ( '<STR_LIT>' ) <EOL> def test_str_arith ( ) : <EOL> rep = cs * <NUM_LIT:1> <EOL> assert isinstance ( rep , Repeat ) <EOL> assert rep . lhs . isidentical ( cs ) <EOL> assert rep . rhs == <NUM_LIT:1> <EOL> with pytest . raises ( TypeError ) : <EOL> cs * <NUM_LIT> <EOL> with pytest . raises ( TypeError ) : <EOL> cs * '<STR_LIT:a>' <EOL> interp = cs % cs <EOL> assert isinstance ( interp , Interp ) <EOL> assert interp . lhs . isidentical ( cs ) <EOL> assert interp . rhs . isidentical ( cs ) <EOL> interp_lit = cs % '<STR_LIT:a>' <EOL> assert isinstance ( interp_lit , Interp ) <EOL> assert interp_lit . lhs . isidentical ( cs ) <EOL> assert interp_lit . rhs == '<STR_LIT:a>' <EOL> with pytest . raises ( Exception ) : <EOL> cs / <NUM_LIT:1> <EOL> with pytest . raises ( Exception ) : <EOL> cs // <NUM_LIT:1> <EOL> def test_datetime_sub ( ) : <EOL> assert ( g - h ) . dshape == dshape ( '<STR_LIT>' ) <EOL> assert ( g - i ) . dshape == dshape ( '<STR_LIT>' ) <EOL> assert ( i - j ) . dshape == dshape ( '<STR_LIT>' ) <EOL> assert ( g - k ) . dshape == dshape ( '<STR_LIT>' ) <EOL> assert ( g - l ) . dshape == dshape ( '<STR_LIT>' ) <EOL> assert ( i - k ) . dshape == dshape ( '<STR_LIT>' ) <EOL> assert ( i - l ) . dshape == dshape ( '<STR_LIT>' ) <EOL> def test_datetime_add ( ) : <EOL> assert ( g + k ) . dshape == dshape ( '<STR_LIT>' ) <EOL> assert ( g + l ) . dshape == dshape ( '<STR_LIT>' ) <EOL> assert ( i + k ) . dshape == dshape ( '<STR_LIT>' ) <EOL> assert ( i + l ) . dshape == dshape ( '<STR_LIT>' ) </s>
