<s> """<STR_LIT>""" <EOL> import os <EOL> import yaml <EOL> import unittest <EOL> import tempfile <EOL> from copy import copy <EOL> from confire . config import * <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT:password>' <EOL> class ConfigurationTests ( unittest . TestCase ) : <EOL> FIXTURE = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : [ "<STR_LIT>" , ] } , <EOL> "<STR_LIT:password>" : "<STR_LIT>" <EOL> } <EOL> def setUp ( self ) : <EOL> self . original_conf_paths = copy ( Configuration . CONF_PATHS ) <EOL> Configuration . CONF_PATHS = [ ] <EOL> self . config_file = tempfile . NamedTemporaryFile ( suffix = "<STR_LIT>" , delete = False ) . name <EOL> with open ( self . config_file , "<STR_LIT:w>" ) as conf : <EOL> yaml . dump ( self . FIXTURE , conf , default_flow_style = False ) <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT:password>' <EOL> def tearDown ( self ) : <EOL> Configuration . CONF_PATHS = self . original_conf_paths <EOL> os . remove ( self . config_file ) <EOL> os . environ . pop ( '<STR_LIT>' ) <EOL> assert '<STR_LIT>' not in os . environ <EOL> def test_search_path ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertGreater ( len ( self . original_conf_paths ) , <NUM_LIT:0> ) <EOL> def test_empty_conf_path ( self ) : <EOL> """<STR_LIT>""" <EOL> config = TestConfiguration . load ( ) <EOL> self . assertEquals ( len ( Configuration . CONF_PATHS ) , <NUM_LIT:0> ) <EOL> self . assertTrue ( config [ '<STR_LIT>' ] ) <EOL> self . assertIsNone ( config . get ( '<STR_LIT>' ) ) <EOL> def test_load_config ( self ) : <EOL> """<STR_LIT>""" <EOL> Configuration . CONF_PATHS . append ( self . config_file ) <EOL> config = TestConfiguration . load ( ) <EOL> self . assertIsNotNone ( config . get ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( config . get ( '<STR_LIT>' ) , "<STR_LIT>" ) <EOL> self . assertTrue ( isinstance ( config . get ( '<STR_LIT>' ) , NestedConfiguration ) ) <EOL> self . assertEqual ( config . get ( "<STR_LIT>" ) . get ( "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> def test_load_override ( self ) : <EOL> """<STR_LIT>""" <EOL> Configuration . CONF_PATHS . append ( self . config_file ) <EOL> config = TestConfiguration . load ( ) <EOL> self . assertFalse ( config [ "<STR_LIT>" ] ) <EOL> def test_configure_by_dict ( self ) : <EOL> """<STR_LIT>""" <EOL> config = TestConfiguration . load ( ) <EOL> config . configure ( { "<STR_LIT>" : <NUM_LIT> , "<STR_LIT:foo>" : "<STR_LIT:bar>" } ) <EOL> self . assertEqual ( config [ "<STR_LIT>" ] , <NUM_LIT> ) <EOL> self . assertEqual ( config [ "<STR_LIT:foo>" ] , "<STR_LIT:bar>" ) <EOL> def test_configure_by_conf ( self ) : <EOL> """<STR_LIT>""" <EOL> configa = TestConfiguration . load ( ) <EOL> configb = TestConfiguration . load ( ) <EOL> self . assertEqual ( configa [ "<STR_LIT>" ] , configb [ "<STR_LIT>" ] ) <EOL> configa . anoption = <NUM_LIT> <EOL> self . assertNotEqual ( configa [ "<STR_LIT>" ] , configb [ "<STR_LIT>" ] ) <EOL> configb . configure ( configa ) <EOL> self . assertEqual ( configa [ "<STR_LIT>" ] , configb [ "<STR_LIT>" ] ) <EOL> def test_configure_with_none ( self ) : <EOL> """<STR_LIT>""" <EOL> config = TestConfiguration . load ( ) <EOL> try : <EOL> config . configure ( None ) <EOL> except Exception : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_nested_configure ( self ) : <EOL> """<STR_LIT>""" <EOL> config = TestConfiguration . load ( ) <EOL> data = { "<STR_LIT>" : { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } , "<STR_LIT>" : "<STR_LIT>" } } <EOL> config . configure ( data ) <EOL> self . assertEqual ( type ( config . get ( '<STR_LIT>' ) ) , NestedConfiguration ) <EOL> self . assertEqual ( type ( config . get ( '<STR_LIT>' ) . get ( '<STR_LIT>' ) ) , SubNestedConfiguration ) <EOL> self . assertEqual ( config . get ( '<STR_LIT>' ) . get ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . assertEqual ( config . get ( '<STR_LIT>' ) . get ( '<STR_LIT>' ) . get ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def test_environ_configuration ( self ) : <EOL> """<STR_LIT>""" <EOL> config = TestConfiguration . load ( ) <EOL> self . assertEqual ( '<STR_LIT:password>' , config . get ( '<STR_LIT:password>' ) ) <EOL> def test_settings_file_environ_override ( self ) : <EOL> """<STR_LIT>""" <EOL> Configuration . CONF_PATHS . append ( self . config_file ) <EOL> config = TestConfiguration . load ( ) <EOL> self . assertEqual ( '<STR_LIT>' , config . get ( '<STR_LIT:password>' ) ) <EOL> def test_options ( self ) : <EOL> """<STR_LIT>""" <EOL> config = TestConfiguration . load ( ) <EOL> options = dict ( config . options ( ) ) <EOL> self . assertIn ( "<STR_LIT>" , options ) <EOL> self . assertIn ( "<STR_LIT>" , options ) <EOL> self . assertIn ( "<STR_LIT>" , options ) <EOL> self . assertNotIn ( "<STR_LIT>" , options ) <EOL> self . assertNotIn ( "<STR_LIT>" , options ) <EOL> self . assertNotIn ( "<STR_LIT>" , options ) <EOL> def test_get ( self ) : <EOL> """<STR_LIT>""" <EOL> config = TestConfiguration . load ( ) <EOL> self . assertTrue ( config . get ( "<STR_LIT>" ) ) <EOL> self . assertNotIn ( "<STR_LIT>" , dict ( config . options ( ) ) ) <EOL> self . assertEqual ( config . get ( "<STR_LIT>" , <NUM_LIT:1> ) , <NUM_LIT:1> ) <EOL> def test__get__ ( self ) : <EOL> """<STR_LIT>""" <EOL> config = TestConfiguration . load ( ) <EOL> self . assertTrue ( config [ "<STR_LIT>" ] ) <EOL> def test_case_insensitivity ( self ) : <EOL> """<STR_LIT>""" <EOL> config = TestConfiguration . load ( ) <EOL> self . assertTrue ( config [ "<STR_LIT>" ] ) <EOL> def test_key_error ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . assertRaises ( KeyError ) : <EOL> config = TestConfiguration . load ( ) <EOL> self . assertTrue ( config [ "<STR_LIT>" ] ) <EOL> @ unittest . skip <EOL> def test_configure_back_to_empty ( self ) : <EOL> """<STR_LIT>""" <EOL> Configuration . CONF_PATHS . append ( self . config_file ) <EOL> config = TestConfiguration . load ( ) <EOL> self . assertGreater ( len ( config . nested . empty ) , <NUM_LIT:0> , "<STR_LIT>" ) <EOL> config . configure ( NestedConfiguration ( ) ) <EOL> self . assertEqual ( config . nested . level , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( config . nested . empty ) , <NUM_LIT:0> ) <EOL> class SubNestedConfiguration ( Configuration ) : <EOL> level = <NUM_LIT:2> <EOL> class NestedConfiguration ( Configuration ) : <EOL> level = <NUM_LIT:1> <EOL> empty = [ ] <EOL> nested = SubNestedConfiguration ( ) <EOL> class TestConfiguration ( Configuration ) : <EOL> """<STR_LIT>""" <EOL> _notanopt = "<STR_LIT>" <EOL> NOTANOPT = "<STR_LIT>" <EOL> mysetting = True <EOL> anoption = <NUM_LIT> <EOL> paththere = "<STR_LIT>" <EOL> nested = NestedConfiguration ( ) <EOL> password = environ_setting ( '<STR_LIT>' ) <EOL> def amethod ( self ) : <EOL> return True </s>
