<s> import confuse <EOL> import os <EOL> import collections <EOL> from . import _root , unittest <EOL> class ValidConfigTest ( unittest . TestCase ) : <EOL> def test_validate_simple_dict ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : <NUM_LIT:5> } ) <EOL> valid = config . get ( { '<STR_LIT:foo>' : confuse . Integer ( ) } ) <EOL> self . assertEqual ( valid [ '<STR_LIT:foo>' ] , <NUM_LIT:5> ) <EOL> def test_default_value ( self ) : <EOL> config = _root ( { } ) <EOL> valid = config . get ( { '<STR_LIT:foo>' : confuse . Integer ( <NUM_LIT:8> ) } ) <EOL> self . assertEqual ( valid [ '<STR_LIT:foo>' ] , <NUM_LIT:8> ) <EOL> def test_undeclared_key_raises_keyerror ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : <NUM_LIT:5> } ) <EOL> valid = config . get ( { '<STR_LIT:foo>' : confuse . Integer ( ) } ) <EOL> with self . assertRaises ( KeyError ) : <EOL> valid [ '<STR_LIT:bar>' ] <EOL> def test_undeclared_key_ignored_from_input ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : <NUM_LIT:5> , '<STR_LIT:bar>' : <NUM_LIT:6> } ) <EOL> valid = config . get ( { '<STR_LIT:foo>' : confuse . Integer ( ) } ) <EOL> with self . assertRaises ( KeyError ) : <EOL> valid [ '<STR_LIT:bar>' ] <EOL> def test_int_template_shortcut ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : <NUM_LIT:5> } ) <EOL> valid = config . get ( { '<STR_LIT:foo>' : int } ) <EOL> self . assertEqual ( valid [ '<STR_LIT:foo>' ] , <NUM_LIT:5> ) <EOL> def test_int_default_shortcut ( self ) : <EOL> config = _root ( { } ) <EOL> valid = config . get ( { '<STR_LIT:foo>' : <NUM_LIT:9> } ) <EOL> self . assertEqual ( valid [ '<STR_LIT:foo>' ] , <NUM_LIT:9> ) <EOL> def test_attribute_access ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : <NUM_LIT:5> } ) <EOL> valid = config . get ( { '<STR_LIT:foo>' : confuse . Integer ( ) } ) <EOL> self . assertEqual ( valid . foo , <NUM_LIT:5> ) <EOL> def test_missing_required_value_raises_error_on_validate ( self ) : <EOL> config = _root ( { } ) <EOL> with self . assertRaises ( confuse . NotFoundError ) : <EOL> config . get ( { '<STR_LIT:foo>' : confuse . Integer ( ) } ) <EOL> def test_none_as_default ( self ) : <EOL> config = _root ( { } ) <EOL> valid = config . get ( { '<STR_LIT:foo>' : confuse . Integer ( None ) } ) <EOL> self . assertIsNone ( valid [ '<STR_LIT:foo>' ] ) <EOL> def test_wrong_type_raises_error_on_validate ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) <EOL> with self . assertRaises ( confuse . ConfigTypeError ) : <EOL> config . get ( { '<STR_LIT:foo>' : confuse . Integer ( ) } ) <EOL> def test_validate_individual_value ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : <NUM_LIT:5> } ) <EOL> valid = config [ '<STR_LIT:foo>' ] . get ( confuse . Integer ( ) ) <EOL> self . assertEqual ( valid , <NUM_LIT:5> ) <EOL> def test_nested_dict_template ( self ) : <EOL> config = _root ( { <EOL> '<STR_LIT:foo>' : { '<STR_LIT:bar>' : <NUM_LIT:9> } , <EOL> } ) <EOL> valid = config . get ( { <EOL> '<STR_LIT:foo>' : { '<STR_LIT:bar>' : confuse . Integer ( ) } , <EOL> } ) <EOL> self . assertEqual ( valid [ '<STR_LIT:foo>' ] [ '<STR_LIT:bar>' ] , <NUM_LIT:9> ) <EOL> def test_nested_attribute_access ( self ) : <EOL> config = _root ( { <EOL> '<STR_LIT:foo>' : { '<STR_LIT:bar>' : <NUM_LIT:8> } , <EOL> } ) <EOL> valid = config . get ( { <EOL> '<STR_LIT:foo>' : { '<STR_LIT:bar>' : confuse . Integer ( ) } , <EOL> } ) <EOL> self . assertEqual ( valid . foo . bar , <NUM_LIT:8> ) <EOL> class AsTemplateTest ( unittest . TestCase ) : <EOL> def test_plain_int_as_template ( self ) : <EOL> typ = confuse . as_template ( int ) <EOL> self . assertIsInstance ( typ , confuse . Integer ) <EOL> self . assertEqual ( typ . default , confuse . REQUIRED ) <EOL> def test_concrete_int_as_template ( self ) : <EOL> typ = confuse . as_template ( <NUM_LIT:2> ) <EOL> self . assertIsInstance ( typ , confuse . Integer ) <EOL> self . assertEqual ( typ . default , <NUM_LIT:2> ) <EOL> def test_plain_string_as_template ( self ) : <EOL> typ = confuse . as_template ( str ) <EOL> self . assertIsInstance ( typ , confuse . String ) <EOL> self . assertEqual ( typ . default , confuse . REQUIRED ) <EOL> def test_concrete_string_as_template ( self ) : <EOL> typ = confuse . as_template ( '<STR_LIT:foo>' ) <EOL> self . assertIsInstance ( typ , confuse . String ) <EOL> self . assertEqual ( typ . default , '<STR_LIT:foo>' ) <EOL> @ unittest . skipIf ( confuse . PY3 , "<STR_LIT>" ) <EOL> def test_unicode_type_as_template ( self ) : <EOL> typ = confuse . as_template ( unicode ) <EOL> self . assertIsInstance ( typ , confuse . String ) <EOL> self . assertEqual ( typ . default , confuse . REQUIRED ) <EOL> @ unittest . skipIf ( confuse . PY3 , "<STR_LIT>" ) <EOL> def test_basestring_as_template ( self ) : <EOL> typ = confuse . as_template ( basestring ) <EOL> self . assertIsInstance ( typ , confuse . String ) <EOL> self . assertEqual ( typ . default , confuse . REQUIRED ) <EOL> def test_dict_as_template ( self ) : <EOL> typ = confuse . as_template ( { '<STR_LIT:key>' : <NUM_LIT:9> } ) <EOL> self . assertIsInstance ( typ , confuse . MappingTemplate ) <EOL> self . assertIsInstance ( typ . subtemplates [ '<STR_LIT:key>' ] , confuse . Integer ) <EOL> self . assertEqual ( typ . subtemplates [ '<STR_LIT:key>' ] . default , <NUM_LIT:9> ) <EOL> def test_nested_dict_as_template ( self ) : <EOL> typ = confuse . as_template ( { '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT:2> } } ) <EOL> self . assertIsInstance ( typ , confuse . MappingTemplate ) <EOL> self . assertIsInstance ( typ . subtemplates [ '<STR_LIT>' ] , <EOL> confuse . MappingTemplate ) <EOL> self . assertIsInstance ( typ . subtemplates [ '<STR_LIT>' ] . subtemplates [ '<STR_LIT>' ] , <EOL> confuse . Integer ) <EOL> self . assertEqual ( typ . subtemplates [ '<STR_LIT>' ] . subtemplates [ '<STR_LIT>' ] <EOL> . default , <NUM_LIT:2> ) <EOL> def test_list_as_template ( self ) : <EOL> typ = confuse . as_template ( list ( ) ) <EOL> self . assertIsInstance ( typ , confuse . OneOf ) <EOL> self . assertEqual ( typ . default , confuse . REQUIRED ) <EOL> def test_set_as_template ( self ) : <EOL> typ = confuse . as_template ( set ( ) ) <EOL> self . assertIsInstance ( typ , confuse . Choice ) <EOL> def test_float_type_as_tempalte ( self ) : <EOL> typ = confuse . as_template ( float ) <EOL> self . assertIsInstance ( typ , confuse . Number ) <EOL> self . assertEqual ( typ . default , confuse . REQUIRED ) <EOL> def test_none_as_template ( self ) : <EOL> typ = confuse . as_template ( None ) <EOL> self . assertIs ( type ( typ ) , confuse . Template ) <EOL> self . assertEqual ( typ . default , confuse . REQUIRED ) <EOL> def test_dict_type_as_template ( self ) : <EOL> typ = confuse . as_template ( dict ) <EOL> self . assertIsInstance ( typ , confuse . TypeTemplate ) <EOL> self . assertEqual ( typ . typ , collections . Mapping ) <EOL> self . assertEqual ( typ . default , confuse . REQUIRED ) <EOL> def test_list_type_as_template ( self ) : <EOL> typ = confuse . as_template ( list ) <EOL> self . assertIsInstance ( typ , confuse . TypeTemplate ) <EOL> self . assertEqual ( typ . typ , collections . Sequence ) <EOL> self . assertEqual ( typ . default , confuse . REQUIRED ) <EOL> def test_set_type_as_template ( self ) : <EOL> typ = confuse . as_template ( set ) <EOL> self . assertIsInstance ( typ , confuse . TypeTemplate ) <EOL> self . assertEqual ( typ . typ , set ) <EOL> self . assertEqual ( typ . default , confuse . REQUIRED ) <EOL> def test_other_type_as_template ( self ) : <EOL> class MyClass ( object ) : <EOL> pass <EOL> typ = confuse . as_template ( MyClass ) <EOL> self . assertIsInstance ( typ , confuse . TypeTemplate ) <EOL> self . assertEqual ( typ . typ , MyClass ) <EOL> self . assertEqual ( typ . default , confuse . REQUIRED ) <EOL> class StringTemplateTest ( unittest . TestCase ) : <EOL> def test_validate_string ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) <EOL> valid = config . get ( { '<STR_LIT:foo>' : confuse . String ( ) } ) <EOL> self . assertEqual ( valid [ '<STR_LIT:foo>' ] , '<STR_LIT:bar>' ) <EOL> def test_string_default_value ( self ) : <EOL> config = _root ( { } ) <EOL> valid = config . get ( { '<STR_LIT:foo>' : confuse . String ( '<STR_LIT>' ) } ) <EOL> self . assertEqual ( valid [ '<STR_LIT:foo>' ] , '<STR_LIT>' ) <EOL> def test_pattern_matching ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : '<STR_LIT:bar>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> valid = config . get ( { '<STR_LIT:foo>' : confuse . String ( pattern = '<STR_LIT>' ) } ) <EOL> self . assertEqual ( valid [ '<STR_LIT:foo>' ] , '<STR_LIT:bar>' ) <EOL> with self . assertRaises ( confuse . ConfigValueError ) : <EOL> config . get ( { '<STR_LIT>' : confuse . String ( pattern = '<STR_LIT:!>' ) } ) <EOL> def test_string_template_shortcut ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) <EOL> valid = config . get ( { '<STR_LIT:foo>' : str } ) <EOL> self . assertEqual ( valid [ '<STR_LIT:foo>' ] , '<STR_LIT:bar>' ) <EOL> def test_string_default_shortcut ( self ) : <EOL> config = _root ( { } ) <EOL> valid = config . get ( { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) <EOL> self . assertEqual ( valid [ '<STR_LIT:foo>' ] , '<STR_LIT:bar>' ) <EOL> def test_check_string_type ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : <NUM_LIT:5> } ) <EOL> with self . assertRaises ( confuse . ConfigTypeError ) : <EOL> config . get ( { '<STR_LIT:foo>' : confuse . String ( ) } ) <EOL> class NumberTest ( unittest . TestCase ) : <EOL> def test_validate_int_as_number ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : <NUM_LIT:2> } ) <EOL> valid = config [ '<STR_LIT:foo>' ] . get ( confuse . Number ( ) ) <EOL> self . assertIsInstance ( valid , int ) <EOL> self . assertEqual ( valid , <NUM_LIT:2> ) <EOL> def test_validate_float_as_number ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : <NUM_LIT> } ) <EOL> valid = config [ '<STR_LIT:foo>' ] . get ( confuse . Number ( ) ) <EOL> self . assertIsInstance ( valid , float ) <EOL> self . assertEqual ( valid , <NUM_LIT> ) <EOL> def test_validate_string_as_number ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) <EOL> with self . assertRaises ( confuse . ConfigTypeError ) : <EOL> config [ '<STR_LIT:foo>' ] . get ( confuse . Number ( ) ) <EOL> class ChoiceTest ( unittest . TestCase ) : <EOL> def test_validate_good_choice_in_list ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : <NUM_LIT:2> } ) <EOL> valid = config [ '<STR_LIT:foo>' ] . get ( confuse . Choice ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:8> , <NUM_LIT:16> ] ) ) <EOL> self . assertEqual ( valid , <NUM_LIT:2> ) <EOL> def test_validate_bad_choice_in_list ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : <NUM_LIT:3> } ) <EOL> with self . assertRaises ( confuse . ConfigValueError ) : <EOL> config [ '<STR_LIT:foo>' ] . get ( confuse . Choice ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:8> , <NUM_LIT:16> ] ) ) <EOL> def test_validate_good_choice_in_dict ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : <NUM_LIT:2> } ) <EOL> valid = config [ '<STR_LIT:foo>' ] . get ( confuse . Choice ( { <NUM_LIT:2> : '<STR_LIT>' , <NUM_LIT:4> : '<STR_LIT>' } ) ) <EOL> self . assertEqual ( valid , '<STR_LIT>' ) <EOL> def test_validate_bad_choice_in_dict ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : <NUM_LIT:3> } ) <EOL> with self . assertRaises ( confuse . ConfigValueError ) : <EOL> config [ '<STR_LIT:foo>' ] . get ( confuse . Choice ( { <NUM_LIT:2> : '<STR_LIT>' , <NUM_LIT:4> : '<STR_LIT>' } ) ) <EOL> class OneOfTest ( unittest . TestCase ) : <EOL> def test_default_value ( self ) : <EOL> config = _root ( { } ) <EOL> valid = config [ '<STR_LIT:foo>' ] . get ( confuse . OneOf ( [ ] , default = '<STR_LIT:bar>' ) ) <EOL> self . assertEqual ( valid , '<STR_LIT:bar>' ) <EOL> def test_validate_good_choice_in_list ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : <NUM_LIT:2> } ) <EOL> valid = config [ '<STR_LIT:foo>' ] . get ( confuse . OneOf ( [ <EOL> confuse . String ( ) , <EOL> confuse . Integer ( ) , <EOL> ] ) ) <EOL> self . assertEqual ( valid , <NUM_LIT:2> ) <EOL> def test_validate_first_good_choice_in_list ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : <NUM_LIT> } ) <EOL> valid = config [ '<STR_LIT:foo>' ] . get ( confuse . OneOf ( [ <EOL> confuse . Integer ( ) , <EOL> confuse . Number ( ) , <EOL> ] ) ) <EOL> self . assertEqual ( valid , <NUM_LIT:3> ) <EOL> def test_validate_no_choice_in_list ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : None } ) <EOL> with self . assertRaises ( confuse . ConfigValueError ) : <EOL> config [ '<STR_LIT:foo>' ] . get ( confuse . OneOf ( [ <EOL> confuse . String ( ) , <EOL> confuse . Integer ( ) , <EOL> ] ) ) <EOL> def test_validate_bad_template ( self ) : <EOL> class BadTemplate ( object ) : <EOL> pass <EOL> config = _root ( { } ) <EOL> with self . assertRaises ( confuse . ConfigTemplateError ) : <EOL> config . get ( confuse . OneOf ( [ BadTemplate ( ) ] ) ) <EOL> del BadTemplate <EOL> class StrSeqTest ( unittest . TestCase ) : <EOL> def test_string_list ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : [ '<STR_LIT:bar>' , '<STR_LIT>' ] } ) <EOL> valid = config [ '<STR_LIT:foo>' ] . get ( confuse . StrSeq ( ) ) <EOL> self . assertEqual ( valid , [ '<STR_LIT:bar>' , '<STR_LIT>' ] ) <EOL> def test_string_tuple ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : ( '<STR_LIT:bar>' , '<STR_LIT>' ) } ) <EOL> valid = config [ '<STR_LIT:foo>' ] . get ( confuse . StrSeq ( ) ) <EOL> self . assertEqual ( valid , [ '<STR_LIT:bar>' , '<STR_LIT>' ] ) <EOL> def test_whitespace_separated_string ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : '<STR_LIT>' } ) <EOL> valid = config [ '<STR_LIT:foo>' ] . get ( confuse . StrSeq ( ) ) <EOL> self . assertEqual ( valid , [ '<STR_LIT:bar>' , '<STR_LIT>' ] ) <EOL> def test_invalid_type ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : <NUM_LIT:9> } ) <EOL> with self . assertRaises ( confuse . ConfigTypeError ) : <EOL> config [ '<STR_LIT:foo>' ] . get ( confuse . StrSeq ( ) ) <EOL> def test_invalid_sequence_type ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : [ '<STR_LIT:bar>' , <NUM_LIT> ] } ) <EOL> with self . assertRaises ( confuse . ConfigTypeError ) : <EOL> config [ '<STR_LIT:foo>' ] . get ( confuse . StrSeq ( ) ) <EOL> class FilenameTest ( unittest . TestCase ) : <EOL> def test_filename_relative_to_working_dir ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) <EOL> valid = config [ '<STR_LIT:foo>' ] . get ( confuse . Filename ( cwd = '<STR_LIT>' ) ) <EOL> self . assertEqual ( valid , os . path . realpath ( '<STR_LIT>' ) ) <EOL> def test_filename_relative_to_sibling ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : '<STR_LIT:/>' , '<STR_LIT:bar>' : '<STR_LIT>' } ) <EOL> valid = config . get ( { <EOL> '<STR_LIT:foo>' : confuse . Filename ( ) , <EOL> '<STR_LIT:bar>' : confuse . Filename ( relative_to = '<STR_LIT:foo>' ) <EOL> } ) <EOL> self . assertEqual ( valid . foo , os . path . realpath ( '<STR_LIT:/>' ) ) <EOL> self . assertEqual ( valid . bar , os . path . realpath ( '<STR_LIT>' ) ) <EOL> def test_filename_working_dir_overrides_sibling ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) <EOL> valid = config . get ( { <EOL> '<STR_LIT:foo>' : confuse . Filename ( cwd = '<STR_LIT>' , relative_to = '<STR_LIT>' ) <EOL> } ) <EOL> self . assertEqual ( valid . foo , os . path . realpath ( '<STR_LIT>' ) ) <EOL> def test_filename_relative_to_sibling_with_recursion ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : '<STR_LIT:/>' , '<STR_LIT:bar>' : '<STR_LIT:r>' , '<STR_LIT>' : '<STR_LIT:z>' } ) <EOL> with self . assertRaises ( confuse . ConfigTemplateError ) : <EOL> config . get ( { <EOL> '<STR_LIT:foo>' : confuse . Filename ( relative_to = '<STR_LIT:bar>' ) , <EOL> '<STR_LIT:bar>' : confuse . Filename ( relative_to = '<STR_LIT>' ) , <EOL> '<STR_LIT>' : confuse . Filename ( relative_to = '<STR_LIT:foo>' ) <EOL> } ) <EOL> def test_filename_relative_to_self ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) <EOL> with self . assertRaises ( confuse . ConfigTemplateError ) : <EOL> config . get ( { <EOL> '<STR_LIT:foo>' : confuse . Filename ( relative_to = '<STR_LIT:foo>' ) <EOL> } ) <EOL> def test_filename_relative_to_sibling_needs_siblings ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) <EOL> with self . assertRaises ( confuse . ConfigTemplateError ) : <EOL> config [ '<STR_LIT:foo>' ] . get ( confuse . Filename ( relative_to = '<STR_LIT:bar>' ) ) <EOL> def test_filename_relative_to_sibling_needs_template ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : '<STR_LIT:/>' , '<STR_LIT:bar>' : '<STR_LIT>' } ) <EOL> with self . assertRaises ( confuse . ConfigTemplateError ) : <EOL> config . get ( { <EOL> '<STR_LIT:bar>' : confuse . Filename ( relative_to = '<STR_LIT:foo>' ) <EOL> } ) <EOL> def test_filename_with_non_file_source ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : '<STR_LIT>' } ) <EOL> valid = config [ '<STR_LIT:foo>' ] . get ( confuse . Filename ( ) ) <EOL> self . assertEqual ( valid , os . path . join ( os . getcwd ( ) , '<STR_LIT:foo>' , '<STR_LIT:bar>' ) ) <EOL> def test_filename_with_file_source ( self ) : <EOL> source = confuse . ConfigSource ( { '<STR_LIT:foo>' : '<STR_LIT>' } , <EOL> filename = '<STR_LIT>' ) <EOL> config = _root ( source ) <EOL> config . config_dir = lambda : '<STR_LIT>' <EOL> valid = config [ '<STR_LIT:foo>' ] . get ( confuse . Filename ( ) ) <EOL> self . assertEqual ( valid , os . path . realpath ( '<STR_LIT>' ) ) <EOL> def test_filename_with_default_source ( self ) : <EOL> source = confuse . ConfigSource ( { '<STR_LIT:foo>' : '<STR_LIT>' } , <EOL> filename = '<STR_LIT>' , <EOL> default = True ) <EOL> config = _root ( source ) <EOL> config . config_dir = lambda : '<STR_LIT>' <EOL> valid = config [ '<STR_LIT:foo>' ] . get ( confuse . Filename ( ) ) <EOL> self . assertEqual ( valid , os . path . realpath ( '<STR_LIT>' ) ) <EOL> def test_filename_wrong_type ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : <NUM_LIT:8> } ) <EOL> with self . assertRaises ( confuse . ConfigTypeError ) : <EOL> config [ '<STR_LIT:foo>' ] . get ( confuse . Filename ( ) ) <EOL> class BaseTemplateTest ( unittest . TestCase ) : <EOL> def test_base_template_accepts_any_value ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : <NUM_LIT> } ) <EOL> valid = config [ '<STR_LIT:foo>' ] . get ( confuse . Template ( ) ) <EOL> self . assertEqual ( valid , <NUM_LIT> ) <EOL> def test_base_template_required ( self ) : <EOL> config = _root ( { } ) <EOL> with self . assertRaises ( confuse . NotFoundError ) : <EOL> config [ '<STR_LIT:foo>' ] . get ( confuse . Template ( ) ) <EOL> def test_base_template_with_default ( self ) : <EOL> config = _root ( { } ) <EOL> valid = config [ '<STR_LIT:foo>' ] . get ( confuse . Template ( '<STR_LIT:bar>' ) ) <EOL> self . assertEqual ( valid , '<STR_LIT:bar>' ) <EOL> class TypeTemplateTest ( unittest . TestCase ) : <EOL> def test_correct_type ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : set ( ) } ) <EOL> valid = config [ '<STR_LIT:foo>' ] . get ( confuse . TypeTemplate ( set ) ) <EOL> self . assertEqual ( valid , set ( ) ) <EOL> def test_incorrect_type ( self ) : <EOL> config = _root ( { '<STR_LIT:foo>' : dict ( ) } ) <EOL> with self . assertRaises ( confuse . ConfigTypeError ) : <EOL> config [ '<STR_LIT:foo>' ] . get ( confuse . TypeTemplate ( set ) ) <EOL> def test_missing_required_value ( self ) : <EOL> config = _root ( { } ) <EOL> with self . assertRaises ( confuse . NotFoundError ) : <EOL> config [ '<STR_LIT:foo>' ] . get ( confuse . TypeTemplate ( set ) ) <EOL> def test_default_value ( self ) : <EOL> config = _root ( { } ) <EOL> valid = config [ '<STR_LIT:foo>' ] . get ( confuse . TypeTemplate ( set , set ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) ) ) <EOL> self . assertEqual ( valid , set ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) ) </s>
