<s> import datetime <EOL> import logging <EOL> from staticconf import validation , errors <EOL> from testing . testifycompat import ( <EOL> assert_equal , <EOL> assert_raises_and_contains , <EOL> ) <EOL> class TestValidation ( object ) : <EOL> def test_validate_string ( self ) : <EOL> assert_equal ( None , validation . validate_string ( None ) ) <EOL> assert_equal ( '<STR_LIT>' , validation . validate_string ( '<STR_LIT>' ) ) <EOL> assert_equal ( '<STR_LIT>' , validation . validate_string ( <NUM_LIT> ) ) <EOL> class TestDateTimeValidation ( object ) : <EOL> def test_validate_datetime ( self ) : <EOL> actual = validation . validate_datetime ( "<STR_LIT>" ) <EOL> expected = datetime . datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> ) <EOL> assert_equal ( actual , expected ) <EOL> def test_validate_datetime_pm_format ( self ) : <EOL> actual = validation . validate_datetime ( "<STR_LIT>" ) <EOL> expected = datetime . datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:5> ) <EOL> assert_equal ( actual , expected ) <EOL> def test_validate_datetime_already_datetime ( self ) : <EOL> expected = datetime . datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:5> ) <EOL> actual = validation . validate_datetime ( expected ) <EOL> assert_equal ( actual , expected ) <EOL> def test_validate_date ( self ) : <EOL> actual = validation . validate_date ( "<STR_LIT>" ) <EOL> expected = datetime . date ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT> ) <EOL> assert_equal ( actual , expected ) <EOL> def test_validate_date_already_date ( self ) : <EOL> expected = datetime . date ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT> ) <EOL> actual = validation . validate_date ( expected ) <EOL> assert_equal ( actual , expected ) <EOL> def test_validate_time ( self ) : <EOL> actual = validation . validate_time ( "<STR_LIT>" ) <EOL> expected = datetime . time ( <NUM_LIT:4> , <NUM_LIT:12> , <NUM_LIT> ) <EOL> assert_equal ( actual , expected ) <EOL> def test_validate_time_pm_format ( self ) : <EOL> actual = validation . validate_time ( "<STR_LIT>" ) <EOL> expected = datetime . time ( <NUM_LIT:16> , <NUM_LIT:12> , <NUM_LIT> ) <EOL> assert_equal ( actual , expected ) <EOL> def test_validate_time_already_time ( self ) : <EOL> expected = datetime . time ( <NUM_LIT:16> , <NUM_LIT:12> , <NUM_LIT> ) <EOL> actual = validation . validate_time ( expected ) <EOL> assert_equal ( actual , expected ) <EOL> class TestIterableValidation ( object ) : <EOL> def test_validate_list ( self ) : <EOL> assert_equal ( [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] , validation . validate_list ( ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ) ) ) <EOL> def test_validate_set ( self ) : <EOL> expected = set ( [ <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:1> ] ) <EOL> actual = validation . validate_set ( [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:2> ] ) <EOL> assert_equal ( expected , actual ) <EOL> class TestRegexValidation ( object ) : <EOL> def test_validate_regex_success ( self ) : <EOL> pattern = '<STR_LIT>' <EOL> actual = validation . validate_regex ( pattern ) <EOL> assert_equal ( pattern , actual . pattern ) <EOL> def test_validate_regex_failed ( self ) : <EOL> pattern = "<STR_LIT>" <EOL> assert_raises_and_contains ( <EOL> errors . ValidationError , <EOL> pattern , <EOL> validation . validate_regex , <EOL> pattern ) <EOL> def test_validate_regex_none ( self ) : <EOL> assert_raises_and_contains ( <EOL> errors . ValidationError , <EOL> '<STR_LIT:None>' , <EOL> validation . validate_regex , <EOL> None ) <EOL> class TestBuildListOfTypeValidator ( object ) : <EOL> def test_build_list_of_type_ints_success ( self ) : <EOL> validator = validation . build_list_type_validator ( <EOL> validation . validate_int ) <EOL> assert_equal ( validator ( [ '<STR_LIT:0>' , '<STR_LIT:1>' , '<STR_LIT:2>' ] ) , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> def test_build_list_of_type_float_failed ( self ) : <EOL> validator = validation . build_list_type_validator ( <EOL> validation . validate_float ) <EOL> assert_raises_and_contains ( <EOL> errors . ValidationError , '<STR_LIT>' , validator , [ '<STR_LIT>' , '<STR_LIT:a>' ] ) <EOL> def test_build_list_of_type_empty_list ( self ) : <EOL> validator = validation . build_list_type_validator ( <EOL> validation . validate_string ) <EOL> assert_equal ( validator ( [ ] ) , [ ] ) <EOL> def test_build_list_of_type_not_a_list ( self ) : <EOL> validator = validation . build_list_type_validator ( <EOL> validation . validate_any ) <EOL> assert_raises_and_contains ( <EOL> errors . ValidationError , '<STR_LIT>' , validator , None ) <EOL> class TestBuildMappingTypeValidator ( object ) : <EOL> def test_build_map_from_list_of_pairs ( self ) : <EOL> pair_validator = validation . build_map_type_validator ( lambda i : i ) <EOL> expected = { <NUM_LIT:0> : <NUM_LIT:0> , <NUM_LIT:1> : <NUM_LIT:1> , <NUM_LIT:2> : <NUM_LIT:2> } <EOL> assert_equal ( pair_validator ( enumerate ( range ( <NUM_LIT:3> ) ) ) , expected ) <EOL> def test_build_map_from_list_of_dicts ( self ) : <EOL> def map_by_id ( d ) : <EOL> return d [ '<STR_LIT:id>' ] , d [ '<STR_LIT:value>' ] <EOL> map_validator = validation . build_map_type_validator ( map_by_id ) <EOL> expected = { '<STR_LIT:a>' : '<STR_LIT:b>' , '<STR_LIT:c>' : '<STR_LIT:d>' } <EOL> source = [ dict ( id = '<STR_LIT:a>' , value = '<STR_LIT:b>' ) , dict ( id = '<STR_LIT:c>' , value = '<STR_LIT:d>' ) ] <EOL> assert_equal ( map_validator ( source ) , expected ) <EOL> class TestValidateLogLevel ( object ) : <EOL> def test_valid_log_level ( self ) : <EOL> assert_equal ( validation . validate_log_level ( '<STR_LIT>' ) , logging . WARN ) <EOL> assert_equal ( validation . validate_log_level ( '<STR_LIT>' ) , logging . DEBUG ) <EOL> def test_invalid_log_level ( self ) : <EOL> assert_raises_and_contains ( <EOL> errors . ValidationError , <EOL> '<STR_LIT>' , <EOL> validation . validate_log_level , <EOL> '<STR_LIT>' ) </s>
