<s> from business_rules . operators import ( StringType , <EOL> NumericType , BooleanType , SelectType , <EOL> SelectMultipleType ) <EOL> from . import TestCase <EOL> from decimal import Decimal <EOL> import sys <EOL> class StringOperatorTests ( TestCase ) : <EOL> def test_operator_decorator ( self ) : <EOL> self . assertTrue ( StringType ( "<STR_LIT:foo>" ) . equal_to . is_operator ) <EOL> def test_string_equal_to ( self ) : <EOL> self . assertTrue ( StringType ( "<STR_LIT:foo>" ) . equal_to ( "<STR_LIT:foo>" ) ) <EOL> self . assertFalse ( StringType ( "<STR_LIT:foo>" ) . equal_to ( "<STR_LIT>" ) ) <EOL> def test_string_equal_to_case_insensitive ( self ) : <EOL> self . assertTrue ( StringType ( "<STR_LIT:foo>" ) . equal_to_case_insensitive ( "<STR_LIT>" ) ) <EOL> self . assertTrue ( StringType ( "<STR_LIT:foo>" ) . equal_to_case_insensitive ( "<STR_LIT:foo>" ) ) <EOL> self . assertFalse ( StringType ( "<STR_LIT:foo>" ) . equal_to_case_insensitive ( "<STR_LIT>" ) ) <EOL> def test_string_starts_with ( self ) : <EOL> self . assertTrue ( StringType ( "<STR_LIT:hello>" ) . starts_with ( "<STR_LIT>" ) ) <EOL> self . assertFalse ( StringType ( "<STR_LIT:hello>" ) . starts_with ( "<STR_LIT>" ) ) <EOL> self . assertFalse ( StringType ( "<STR_LIT:hello>" ) . starts_with ( "<STR_LIT>" ) ) <EOL> def test_string_ends_with ( self ) : <EOL> self . assertTrue ( StringType ( "<STR_LIT:hello>" ) . ends_with ( "<STR_LIT>" ) ) <EOL> self . assertFalse ( StringType ( "<STR_LIT:hello>" ) . ends_with ( "<STR_LIT>" ) ) <EOL> self . assertFalse ( StringType ( "<STR_LIT:hello>" ) . ends_with ( "<STR_LIT>" ) ) <EOL> def test_string_contains ( self ) : <EOL> self . assertTrue ( StringType ( "<STR_LIT:hello>" ) . contains ( "<STR_LIT>" ) ) <EOL> self . assertTrue ( StringType ( "<STR_LIT:hello>" ) . contains ( "<STR_LIT>" ) ) <EOL> self . assertTrue ( StringType ( "<STR_LIT:hello>" ) . contains ( "<STR_LIT>" ) ) <EOL> self . assertFalse ( StringType ( "<STR_LIT:hello>" ) . contains ( "<STR_LIT>" ) ) <EOL> self . assertFalse ( StringType ( "<STR_LIT:hello>" ) . contains ( "<STR_LIT>" ) ) <EOL> def test_string_matches_regex ( self ) : <EOL> self . assertTrue ( StringType ( "<STR_LIT:hello>" ) . matches_regex ( r"<STR_LIT>" ) ) <EOL> self . assertFalse ( StringType ( "<STR_LIT:hello>" ) . matches_regex ( r"<STR_LIT>" ) ) <EOL> def test_non_empty ( self ) : <EOL> self . assertTrue ( StringType ( "<STR_LIT:hello>" ) . non_empty ( ) ) <EOL> self . assertFalse ( StringType ( "<STR_LIT>" ) . non_empty ( ) ) <EOL> self . assertFalse ( StringType ( None ) . non_empty ( ) ) <EOL> class NumericOperatorTests ( TestCase ) : <EOL> def test_instantiate ( self ) : <EOL> err_string = "<STR_LIT>" <EOL> with self . assertRaisesRegexp ( AssertionError , err_string ) : <EOL> NumericType ( "<STR_LIT:foo>" ) <EOL> def test_numeric_type_validates_and_casts_decimal ( self ) : <EOL> ten_dec = Decimal ( <NUM_LIT:10> ) <EOL> ten_int = <NUM_LIT:10> <EOL> ten_float = <NUM_LIT> <EOL> if sys . version_info [ <NUM_LIT:0> ] == <NUM_LIT:2> : <EOL> ten_long = long ( <NUM_LIT:10> ) <EOL> else : <EOL> ten_long = int ( <NUM_LIT:10> ) <EOL> ten_var_dec = NumericType ( ten_dec ) <EOL> ten_var_int = NumericType ( ten_int ) <EOL> ten_var_float = NumericType ( ten_float ) <EOL> ten_var_long = NumericType ( ten_long ) <EOL> self . assertTrue ( isinstance ( ten_var_dec . value , Decimal ) ) <EOL> self . assertTrue ( isinstance ( ten_var_int . value , Decimal ) ) <EOL> self . assertTrue ( isinstance ( ten_var_float . value , Decimal ) ) <EOL> self . assertTrue ( isinstance ( ten_var_long . value , Decimal ) ) <EOL> def test_numeric_equal_to ( self ) : <EOL> self . assertTrue ( NumericType ( <NUM_LIT:10> ) . equal_to ( <NUM_LIT:10> ) ) <EOL> self . assertTrue ( NumericType ( <NUM_LIT:10> ) . equal_to ( <NUM_LIT> ) ) <EOL> self . assertTrue ( NumericType ( <NUM_LIT:10> ) . equal_to ( <NUM_LIT> ) ) <EOL> self . assertTrue ( NumericType ( <NUM_LIT> ) . equal_to ( <NUM_LIT:10> ) ) <EOL> self . assertTrue ( NumericType ( Decimal ( '<STR_LIT>' ) ) . equal_to ( <NUM_LIT:10> ) ) <EOL> self . assertTrue ( NumericType ( <NUM_LIT:10> ) . equal_to ( Decimal ( '<STR_LIT>' ) ) ) <EOL> self . assertFalse ( NumericType ( <NUM_LIT:10> ) . equal_to ( <NUM_LIT> ) ) <EOL> self . assertFalse ( NumericType ( <NUM_LIT:10> ) . equal_to ( <NUM_LIT:11> ) ) <EOL> def test_other_value_not_numeric ( self ) : <EOL> error_string = "<STR_LIT>" <EOL> with self . assertRaisesRegexp ( AssertionError , error_string ) : <EOL> NumericType ( <NUM_LIT:10> ) . equal_to ( "<STR_LIT>" ) <EOL> def test_numeric_greater_than ( self ) : <EOL> self . assertTrue ( NumericType ( <NUM_LIT:10> ) . greater_than ( <NUM_LIT:1> ) ) <EOL> self . assertFalse ( NumericType ( <NUM_LIT:10> ) . greater_than ( <NUM_LIT:11> ) ) <EOL> self . assertTrue ( NumericType ( <NUM_LIT> ) . greater_than ( <NUM_LIT:10> ) ) <EOL> self . assertFalse ( NumericType ( <NUM_LIT> ) . greater_than ( <NUM_LIT:10> ) ) <EOL> self . assertTrue ( NumericType ( <NUM_LIT> ) . greater_than ( <NUM_LIT:10> ) ) <EOL> def test_numeric_greater_than_or_equal_to ( self ) : <EOL> self . assertTrue ( NumericType ( <NUM_LIT:10> ) . greater_than_or_equal_to ( <NUM_LIT:1> ) ) <EOL> self . assertFalse ( NumericType ( <NUM_LIT:10> ) . greater_than_or_equal_to ( <NUM_LIT:11> ) ) <EOL> self . assertTrue ( NumericType ( <NUM_LIT> ) . greater_than_or_equal_to ( <NUM_LIT:10> ) ) <EOL> self . assertTrue ( NumericType ( <NUM_LIT> ) . greater_than_or_equal_to ( <NUM_LIT:10> ) ) <EOL> self . assertTrue ( NumericType ( <NUM_LIT> ) . greater_than_or_equal_to ( <NUM_LIT:10> ) ) <EOL> self . assertTrue ( NumericType ( <NUM_LIT:10> ) . greater_than_or_equal_to ( <NUM_LIT:10> ) ) <EOL> def test_numeric_less_than ( self ) : <EOL> self . assertTrue ( NumericType ( <NUM_LIT:1> ) . less_than ( <NUM_LIT:10> ) ) <EOL> self . assertFalse ( NumericType ( <NUM_LIT:11> ) . less_than ( <NUM_LIT:10> ) ) <EOL> self . assertTrue ( NumericType ( <NUM_LIT:10> ) . less_than ( <NUM_LIT> ) ) <EOL> self . assertFalse ( NumericType ( <NUM_LIT:10> ) . less_than ( <NUM_LIT> ) ) <EOL> self . assertTrue ( NumericType ( <NUM_LIT:10> ) . less_than ( <NUM_LIT> ) ) <EOL> def test_numeric_less_than_or_equal_to ( self ) : <EOL> self . assertTrue ( NumericType ( <NUM_LIT:1> ) . less_than_or_equal_to ( <NUM_LIT:10> ) ) <EOL> self . assertFalse ( NumericType ( <NUM_LIT:11> ) . less_than_or_equal_to ( <NUM_LIT:10> ) ) <EOL> self . assertTrue ( NumericType ( <NUM_LIT:10> ) . less_than_or_equal_to ( <NUM_LIT> ) ) <EOL> self . assertTrue ( NumericType ( <NUM_LIT:10> ) . less_than_or_equal_to ( <NUM_LIT> ) ) <EOL> self . assertTrue ( NumericType ( <NUM_LIT:10> ) . less_than_or_equal_to ( <NUM_LIT> ) ) <EOL> self . assertTrue ( NumericType ( <NUM_LIT:10> ) . less_than_or_equal_to ( <NUM_LIT:10> ) ) <EOL> class BooleanOperatorTests ( TestCase ) : <EOL> def test_instantiate ( self ) : <EOL> err_string = "<STR_LIT>" <EOL> with self . assertRaisesRegexp ( AssertionError , err_string ) : <EOL> BooleanType ( "<STR_LIT:foo>" ) <EOL> err_string = "<STR_LIT>" <EOL> with self . assertRaisesRegexp ( AssertionError , err_string ) : <EOL> BooleanType ( None ) <EOL> def test_boolean_is_true_and_is_false ( self ) : <EOL> self . assertTrue ( BooleanType ( True ) . is_true ( ) ) <EOL> self . assertFalse ( BooleanType ( True ) . is_false ( ) ) <EOL> self . assertFalse ( BooleanType ( False ) . is_true ( ) ) <EOL> self . assertTrue ( BooleanType ( False ) . is_false ( ) ) <EOL> class SelectOperatorTests ( TestCase ) : <EOL> def test_contains ( self ) : <EOL> self . assertTrue ( SelectType ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) . contains ( <NUM_LIT:2> ) ) <EOL> self . assertFalse ( SelectType ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) . contains ( <NUM_LIT:3> ) ) <EOL> self . assertTrue ( SelectType ( [ <NUM_LIT:1> , <NUM_LIT:2> , "<STR_LIT:a>" ] ) . contains ( "<STR_LIT:A>" ) ) <EOL> def test_does_not_contain ( self ) : <EOL> self . assertTrue ( SelectType ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) . does_not_contain ( <NUM_LIT:3> ) ) <EOL> self . assertFalse ( SelectType ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) . does_not_contain ( <NUM_LIT:2> ) ) <EOL> self . assertFalse ( SelectType ( [ <NUM_LIT:1> , <NUM_LIT:2> , "<STR_LIT:a>" ] ) . does_not_contain ( "<STR_LIT:A>" ) ) <EOL> class SelectMultipleOperatorTests ( TestCase ) : <EOL> def test_contains_all ( self ) : <EOL> self . assertTrue ( SelectMultipleType ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) . <EOL> contains_all ( [ <NUM_LIT:2> , <NUM_LIT:1> ] ) ) <EOL> self . assertFalse ( SelectMultipleType ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) . <EOL> contains_all ( [ <NUM_LIT:2> , <NUM_LIT:3> ] ) ) <EOL> self . assertTrue ( SelectMultipleType ( [ <NUM_LIT:1> , <NUM_LIT:2> , "<STR_LIT:a>" ] ) . <EOL> contains_all ( [ <NUM_LIT:2> , <NUM_LIT:1> , "<STR_LIT:A>" ] ) ) <EOL> def test_is_contained_by ( self ) : <EOL> self . assertTrue ( SelectMultipleType ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) . <EOL> is_contained_by ( [ <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:3> ] ) ) <EOL> self . assertFalse ( SelectMultipleType ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) . <EOL> is_contained_by ( [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ) ) <EOL> self . assertTrue ( SelectMultipleType ( [ <NUM_LIT:1> , <NUM_LIT:2> , "<STR_LIT:a>" ] ) . <EOL> is_contained_by ( [ <NUM_LIT:2> , <NUM_LIT:1> , "<STR_LIT:A>" ] ) ) <EOL> def test_shares_at_least_one_element_with ( self ) : <EOL> self . assertTrue ( SelectMultipleType ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) . <EOL> shares_at_least_one_element_with ( [ <NUM_LIT:2> , <NUM_LIT:3> ] ) ) <EOL> self . assertFalse ( SelectMultipleType ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) . <EOL> shares_at_least_one_element_with ( [ <NUM_LIT:4> , <NUM_LIT:3> ] ) ) <EOL> self . assertTrue ( SelectMultipleType ( [ <NUM_LIT:1> , <NUM_LIT:2> , "<STR_LIT:a>" ] ) . <EOL> shares_at_least_one_element_with ( [ <NUM_LIT:4> , "<STR_LIT:A>" ] ) ) <EOL> def test_shares_exactly_one_element_with ( self ) : <EOL> self . assertTrue ( SelectMultipleType ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) . <EOL> shares_exactly_one_element_with ( [ <NUM_LIT:2> , <NUM_LIT:3> ] ) ) <EOL> self . assertFalse ( SelectMultipleType ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) . <EOL> shares_exactly_one_element_with ( [ <NUM_LIT:4> , <NUM_LIT:3> ] ) ) <EOL> self . assertTrue ( SelectMultipleType ( [ <NUM_LIT:1> , <NUM_LIT:2> , "<STR_LIT:a>" ] ) . <EOL> shares_exactly_one_element_with ( [ <NUM_LIT:4> , "<STR_LIT:A>" ] ) ) <EOL> self . assertFalse ( SelectMultipleType ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) . <EOL> shares_exactly_one_element_with ( [ <NUM_LIT:2> , <NUM_LIT:3> , "<STR_LIT:a>" ] ) ) <EOL> def test_shares_no_elements_with ( self ) : <EOL> self . assertTrue ( SelectMultipleType ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) . <EOL> shares_no_elements_with ( [ <NUM_LIT:4> , <NUM_LIT:3> ] ) ) <EOL> self . assertFalse ( SelectMultipleType ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) . <EOL> shares_no_elements_with ( [ <NUM_LIT:2> , <NUM_LIT:3> ] ) ) <EOL> self . assertFalse ( SelectMultipleType ( [ <NUM_LIT:1> , <NUM_LIT:2> , "<STR_LIT:a>" ] ) . <EOL> shares_no_elements_with ( [ <NUM_LIT:4> , "<STR_LIT:A>" ] ) ) </s>
