<s> import six <EOL> import unittest <EOL> import warnings <EOL> from scrapy . settings import ( BaseSettings , Settings , SettingsAttribute , <EOL> CrawlerSettings , SETTINGS_PRIORITIES , <EOL> get_settings_priority ) <EOL> from tests import mock <EOL> from . import default_settings <EOL> class SettingsGlobalFuncsTest ( unittest . TestCase ) : <EOL> def test_get_settings_priority ( self ) : <EOL> for prio_str , prio_num in six . iteritems ( SETTINGS_PRIORITIES ) : <EOL> self . assertEqual ( get_settings_priority ( prio_str ) , prio_num ) <EOL> self . assertEqual ( get_settings_priority ( <NUM_LIT> ) , <NUM_LIT> ) <EOL> class SettingsAttributeTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . attribute = SettingsAttribute ( '<STR_LIT:value>' , <NUM_LIT:10> ) <EOL> def test_set_greater_priority ( self ) : <EOL> self . attribute . set ( '<STR_LIT>' , <NUM_LIT:20> ) <EOL> self . assertEqual ( self . attribute . value , '<STR_LIT>' ) <EOL> self . assertEqual ( self . attribute . priority , <NUM_LIT:20> ) <EOL> def test_set_equal_priority ( self ) : <EOL> self . attribute . set ( '<STR_LIT>' , <NUM_LIT:10> ) <EOL> self . assertEqual ( self . attribute . value , '<STR_LIT>' ) <EOL> self . assertEqual ( self . attribute . priority , <NUM_LIT:10> ) <EOL> def test_set_less_priority ( self ) : <EOL> self . attribute . set ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> self . assertEqual ( self . attribute . value , '<STR_LIT:value>' ) <EOL> self . assertEqual ( self . attribute . priority , <NUM_LIT:10> ) <EOL> def test_overwrite_basesettings ( self ) : <EOL> original_dict = { '<STR_LIT>' : <NUM_LIT:10> , '<STR_LIT>' : <NUM_LIT:20> } <EOL> original_settings = BaseSettings ( original_dict , <NUM_LIT:0> ) <EOL> attribute = SettingsAttribute ( original_settings , <NUM_LIT:0> ) <EOL> new_dict = { '<STR_LIT>' : <NUM_LIT:11> , '<STR_LIT>' : <NUM_LIT> } <EOL> attribute . set ( new_dict , <NUM_LIT:10> ) <EOL> self . assertIsInstance ( attribute . value , BaseSettings ) <EOL> six . assertCountEqual ( self , attribute . value , new_dict ) <EOL> six . assertCountEqual ( self , original_settings , original_dict ) <EOL> new_settings = BaseSettings ( { '<STR_LIT>' : <NUM_LIT:12> } , <NUM_LIT:0> ) <EOL> attribute . set ( new_settings , <NUM_LIT:0> ) <EOL> six . assertCountEqual ( self , attribute . value , new_dict ) <EOL> attribute . set ( new_settings , <NUM_LIT:10> ) <EOL> six . assertCountEqual ( self , attribute . value , new_settings ) <EOL> def test_repr ( self ) : <EOL> self . assertEqual ( repr ( self . attribute ) , <EOL> "<STR_LIT>" ) <EOL> class BaseSettingsTest ( unittest . TestCase ) : <EOL> if six . PY3 : <EOL> assertItemsEqual = unittest . TestCase . assertCountEqual <EOL> def setUp ( self ) : <EOL> self . settings = BaseSettings ( ) <EOL> def test_set_new_attribute ( self ) : <EOL> self . settings . set ( '<STR_LIT>' , '<STR_LIT:value>' , <NUM_LIT:0> ) <EOL> self . assertIn ( '<STR_LIT>' , self . settings . attributes ) <EOL> attr = self . settings . attributes [ '<STR_LIT>' ] <EOL> self . assertIsInstance ( attr , SettingsAttribute ) <EOL> self . assertEqual ( attr . value , '<STR_LIT:value>' ) <EOL> self . assertEqual ( attr . priority , <NUM_LIT:0> ) <EOL> def test_set_settingsattribute ( self ) : <EOL> myattr = SettingsAttribute ( <NUM_LIT:0> , <NUM_LIT:30> ) <EOL> self . settings . set ( '<STR_LIT>' , myattr , <NUM_LIT:10> ) <EOL> self . assertEqual ( self . settings . get ( '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( self . settings . getpriority ( '<STR_LIT>' ) , <NUM_LIT:30> ) <EOL> def test_set_instance_identity_on_update ( self ) : <EOL> attr = SettingsAttribute ( '<STR_LIT:value>' , <NUM_LIT:0> ) <EOL> self . settings . attributes = { '<STR_LIT>' : attr } <EOL> self . settings . set ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:10> ) <EOL> self . assertIn ( '<STR_LIT>' , self . settings . attributes ) <EOL> self . assertIs ( attr , self . settings . attributes [ '<STR_LIT>' ] ) <EOL> def test_set_calls_settings_attributes_methods_on_update ( self ) : <EOL> attr = SettingsAttribute ( '<STR_LIT:value>' , <NUM_LIT:10> ) <EOL> with mock . patch . object ( attr , '<STR_LIT>' ) as mock_setattr , mock . patch . object ( attr , '<STR_LIT>' ) as mock_set : <EOL> self . settings . attributes = { '<STR_LIT>' : attr } <EOL> for priority in ( <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT:20> ) : <EOL> self . settings . set ( '<STR_LIT>' , '<STR_LIT>' , priority ) <EOL> mock_set . assert_called_once_with ( '<STR_LIT>' , priority ) <EOL> self . assertFalse ( mock_setattr . called ) <EOL> mock_set . reset_mock ( ) <EOL> mock_setattr . reset_mock ( ) <EOL> def test_setitem ( self ) : <EOL> settings = BaseSettings ( ) <EOL> settings . set ( '<STR_LIT:key>' , '<STR_LIT:a>' , '<STR_LIT:default>' ) <EOL> settings [ '<STR_LIT:key>' ] = '<STR_LIT:b>' <EOL> self . assertEqual ( settings [ '<STR_LIT:key>' ] , '<STR_LIT:b>' ) <EOL> self . assertEqual ( settings . getpriority ( '<STR_LIT:key>' ) , <NUM_LIT:20> ) <EOL> settings [ '<STR_LIT:key>' ] = '<STR_LIT:c>' <EOL> self . assertEqual ( settings [ '<STR_LIT:key>' ] , '<STR_LIT:c>' ) <EOL> settings [ '<STR_LIT>' ] = '<STR_LIT:x>' <EOL> self . assertIn ( '<STR_LIT>' , settings ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , '<STR_LIT:x>' ) <EOL> self . assertEqual ( settings . getpriority ( '<STR_LIT>' ) , <NUM_LIT:20> ) <EOL> def test_setdict_alias ( self ) : <EOL> with mock . patch . object ( self . settings , '<STR_LIT>' ) as mock_set : <EOL> self . settings . setdict ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <NUM_LIT:10> ) <EOL> self . assertEqual ( mock_set . call_count , <NUM_LIT:2> ) <EOL> calls = [ mock . call ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:10> ) , <EOL> mock . call ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:10> ) ] <EOL> mock_set . assert_has_calls ( calls , any_order = True ) <EOL> def test_setmodule_only_load_uppercase_vars ( self ) : <EOL> class ModuleMock ( ) : <EOL> UPPERCASE_VAR = '<STR_LIT:value>' <EOL> MIXEDcase_VAR = '<STR_LIT>' <EOL> lowercase_var = '<STR_LIT>' <EOL> self . settings . attributes = { } <EOL> self . settings . setmodule ( ModuleMock ( ) , <NUM_LIT:10> ) <EOL> self . assertIn ( '<STR_LIT>' , self . settings . attributes ) <EOL> self . assertNotIn ( '<STR_LIT>' , self . settings . attributes ) <EOL> self . assertNotIn ( '<STR_LIT>' , self . settings . attributes ) <EOL> self . assertEqual ( len ( self . settings . attributes ) , <NUM_LIT:1> ) <EOL> def test_setmodule_alias ( self ) : <EOL> with mock . patch . object ( self . settings , '<STR_LIT>' ) as mock_set : <EOL> self . settings . setmodule ( default_settings , <NUM_LIT:10> ) <EOL> mock_set . assert_any_call ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:10> ) <EOL> mock_set . assert_any_call ( '<STR_LIT>' , { '<STR_LIT:key>' : '<STR_LIT>' } , <NUM_LIT:10> ) <EOL> def test_setmodule_by_path ( self ) : <EOL> self . settings . attributes = { } <EOL> self . settings . setmodule ( default_settings , <NUM_LIT:10> ) <EOL> ctrl_attributes = self . settings . attributes . copy ( ) <EOL> self . settings . attributes = { } <EOL> self . settings . setmodule ( <EOL> '<STR_LIT>' , <NUM_LIT:10> ) <EOL> self . assertItemsEqual ( six . iterkeys ( self . settings . attributes ) , <EOL> six . iterkeys ( ctrl_attributes ) ) <EOL> for key in six . iterkeys ( ctrl_attributes ) : <EOL> attr = self . settings . attributes [ key ] <EOL> ctrl_attr = ctrl_attributes [ key ] <EOL> self . assertEqual ( attr . value , ctrl_attr . value ) <EOL> self . assertEqual ( attr . priority , ctrl_attr . priority ) <EOL> def test_update ( self ) : <EOL> settings = BaseSettings ( { '<STR_LIT>' : <NUM_LIT:0> } , priority = <NUM_LIT:0> ) <EOL> settings . set ( '<STR_LIT>' , <NUM_LIT:10> , priority = <NUM_LIT:50> ) <EOL> custom_settings = BaseSettings ( { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:11> } , <EOL> priority = <NUM_LIT:30> ) <EOL> custom_settings . set ( '<STR_LIT>' , None , priority = <NUM_LIT:50> ) <EOL> custom_dict = { '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : <NUM_LIT:12> , '<STR_LIT>' : None } <EOL> settings . update ( custom_dict , priority = <NUM_LIT:20> ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <NUM_LIT:2> ) <EOL> self . assertEqual ( settings . getpriority ( '<STR_LIT>' ) , <NUM_LIT:20> ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <NUM_LIT:10> ) <EOL> self . assertIn ( '<STR_LIT>' , settings ) <EOL> self . assertEqual ( settings . getpriority ( '<STR_LIT>' ) , <NUM_LIT:20> ) <EOL> settings . update ( custom_settings ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( settings . getpriority ( '<STR_LIT>' ) , <NUM_LIT:30> ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <NUM_LIT:10> ) <EOL> self . assertIn ( '<STR_LIT>' , settings ) <EOL> self . assertEqual ( settings . getpriority ( '<STR_LIT>' ) , <NUM_LIT:50> ) <EOL> settings . update ( { '<STR_LIT>' : <NUM_LIT:3> } , priority = <NUM_LIT:20> ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> def test_update_jsonstring ( self ) : <EOL> settings = BaseSettings ( { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : BaseSettings ( { '<STR_LIT:key>' : '<STR_LIT>' } ) } ) <EOL> settings . update ( '<STR_LIT>' ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <NUM_LIT:2> ) <EOL> settings . set ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] [ '<STR_LIT:key>' ] , "<STR_LIT>" ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> def test_delete ( self ) : <EOL> settings = BaseSettings ( { '<STR_LIT:key>' : None } ) <EOL> settings . set ( '<STR_LIT>' , None , priority = <NUM_LIT:50> ) <EOL> settings . delete ( '<STR_LIT:key>' ) <EOL> settings . delete ( '<STR_LIT>' ) <EOL> self . assertNotIn ( '<STR_LIT:key>' , settings ) <EOL> self . assertIn ( '<STR_LIT>' , settings ) <EOL> del settings [ '<STR_LIT>' ] <EOL> self . assertNotIn ( '<STR_LIT>' , settings ) <EOL> def test_get ( self ) : <EOL> test_configuration = { <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : '<STR_LIT:0>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:value>' , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:3> } , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> settings = self . settings <EOL> settings . attributes = { key : SettingsAttribute ( value , <NUM_LIT:0> ) for key , value <EOL> in six . iteritems ( test_configuration ) } <EOL> self . assertTrue ( settings . getbool ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( settings . getbool ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( settings . getbool ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( settings . getbool ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( settings . getbool ( '<STR_LIT>' , True ) ) <EOL> self . assertFalse ( settings . getbool ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( settings . getbool ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( settings . getbool ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( settings . getint ( '<STR_LIT>' ) , <NUM_LIT> ) <EOL> self . assertEqual ( settings . getint ( '<STR_LIT>' ) , <NUM_LIT> ) <EOL> self . assertEqual ( settings . getint ( '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( settings . getint ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( settings . getfloat ( '<STR_LIT>' ) , <NUM_LIT> ) <EOL> self . assertEqual ( settings . getfloat ( '<STR_LIT>' ) , <NUM_LIT> ) <EOL> self . assertEqual ( settings . getfloat ( '<STR_LIT>' ) , <NUM_LIT:0.0> ) <EOL> self . assertEqual ( settings . getfloat ( '<STR_LIT>' , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEqual ( settings . getlist ( '<STR_LIT>' ) , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings . getlist ( '<STR_LIT>' ) , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings . getlist ( '<STR_LIT>' ) , [ ] ) <EOL> self . assertEqual ( settings . getlist ( '<STR_LIT>' , [ '<STR_LIT:default>' ] ) , [ '<STR_LIT:default>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , '<STR_LIT:value>' ) <EOL> self . assertEqual ( settings . get ( '<STR_LIT>' ) , '<STR_LIT:value>' ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , None ) <EOL> self . assertEqual ( settings . get ( '<STR_LIT>' ) , None ) <EOL> self . assertEqual ( settings . get ( '<STR_LIT>' , '<STR_LIT:default>' ) , '<STR_LIT:default>' ) <EOL> self . assertEqual ( settings . getdict ( '<STR_LIT>' ) , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:3> } ) <EOL> self . assertEqual ( settings . getdict ( '<STR_LIT>' ) , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:3> } ) <EOL> self . assertEqual ( settings . getdict ( '<STR_LIT>' ) , { } ) <EOL> self . assertEqual ( settings . getdict ( '<STR_LIT>' , { '<STR_LIT>' : <NUM_LIT:5> } ) , { '<STR_LIT>' : <NUM_LIT:5> } ) <EOL> self . assertRaises ( ValueError , settings . getdict , '<STR_LIT>' ) <EOL> def test_getpriority ( self ) : <EOL> settings = BaseSettings ( { '<STR_LIT:key>' : '<STR_LIT:value>' } , priority = <NUM_LIT> ) <EOL> self . assertEqual ( settings . getpriority ( '<STR_LIT:key>' ) , <NUM_LIT> ) <EOL> self . assertEqual ( settings . getpriority ( '<STR_LIT>' ) , None ) <EOL> def test_getwithbase ( self ) : <EOL> s = BaseSettings ( { '<STR_LIT>' : BaseSettings ( { <NUM_LIT:1> : <NUM_LIT:1> , <NUM_LIT:2> : <NUM_LIT:2> } , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : BaseSettings ( { <NUM_LIT:1> : <NUM_LIT:10> , <NUM_LIT:3> : <NUM_LIT:30> } , '<STR_LIT:default>' ) , <EOL> '<STR_LIT>' : BaseSettings ( { <NUM_LIT:3> : <NUM_LIT> } , '<STR_LIT:default>' ) } ) <EOL> s [ '<STR_LIT>' ] . set ( <NUM_LIT:2> , <NUM_LIT:200> , '<STR_LIT>' ) <EOL> six . assertCountEqual ( self , s . getwithbase ( '<STR_LIT>' ) , <EOL> { <NUM_LIT:1> : <NUM_LIT:1> , <NUM_LIT:2> : <NUM_LIT:200> , <NUM_LIT:3> : <NUM_LIT:30> } ) <EOL> six . assertCountEqual ( self , s . getwithbase ( '<STR_LIT>' ) , s [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( s . getwithbase ( '<STR_LIT>' ) , { } ) <EOL> def test_maxpriority ( self ) : <EOL> self . assertEqual ( self . settings . maxpriority ( ) , <NUM_LIT:0> ) <EOL> self . settings . set ( '<STR_LIT:A>' , <NUM_LIT:0> , <NUM_LIT:10> ) <EOL> self . settings . set ( '<STR_LIT:B>' , <NUM_LIT:0> , <NUM_LIT:30> ) <EOL> self . assertEqual ( self . settings . maxpriority ( ) , <NUM_LIT:30> ) <EOL> def test_copy ( self ) : <EOL> values = { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> } <EOL> self . settings . setdict ( values ) <EOL> copy = self . settings . copy ( ) <EOL> self . settings . set ( '<STR_LIT>' , False ) <EOL> self . assertTrue ( copy . get ( '<STR_LIT>' ) ) <EOL> test_list = self . settings . get ( '<STR_LIT>' ) <EOL> test_list . append ( '<STR_LIT>' ) <EOL> self . assertListEqual ( copy . get ( '<STR_LIT>' ) , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> test_list_of_lists = self . settings . get ( '<STR_LIT>' ) <EOL> test_list_of_lists [ <NUM_LIT:0> ] . append ( '<STR_LIT>' ) <EOL> self . assertListEqual ( copy . get ( '<STR_LIT>' ) [ <NUM_LIT:0> ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_copy_to_dict ( self ) : <EOL> s = BaseSettings ( { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <NUM_LIT:1> , <NUM_LIT:2> ] , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : BaseSettings ( { <NUM_LIT:1> : <NUM_LIT:1> , <NUM_LIT:2> : <NUM_LIT:2> } , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : BaseSettings ( { <NUM_LIT:1> : <NUM_LIT:10> , <NUM_LIT:3> : <NUM_LIT:30> } , '<STR_LIT:default>' ) , <EOL> '<STR_LIT>' : BaseSettings ( { <NUM_LIT:3> : <NUM_LIT> } , '<STR_LIT:default>' ) } ) <EOL> self . assertDictEqual ( s . copy_to_dict ( ) , <EOL> { '<STR_LIT>' : { <NUM_LIT:3> : <NUM_LIT> } , <EOL> '<STR_LIT>' : { <NUM_LIT:1> : <NUM_LIT:10> , <NUM_LIT:3> : <NUM_LIT:30> } , <EOL> '<STR_LIT>' : { <NUM_LIT:1> : <NUM_LIT:1> , <NUM_LIT:2> : <NUM_LIT:2> } , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : [ <NUM_LIT:1> , <NUM_LIT:2> ] , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_freeze ( self ) : <EOL> self . settings . freeze ( ) <EOL> with self . assertRaises ( TypeError ) as cm : <EOL> self . settings . set ( '<STR_LIT>' , False ) <EOL> self . assertEqual ( str ( cm . exception ) , <EOL> "<STR_LIT>" ) <EOL> def test_frozencopy ( self ) : <EOL> frozencopy = self . settings . frozencopy ( ) <EOL> self . assertTrue ( frozencopy . frozen ) <EOL> self . assertIsNot ( frozencopy , self . settings ) <EOL> def test_deprecated_attribute_overrides ( self ) : <EOL> self . settings . set ( '<STR_LIT>' , '<STR_LIT>' , priority = '<STR_LIT>' ) <EOL> with warnings . catch_warnings ( record = True ) as w : <EOL> self . settings . overrides [ '<STR_LIT>' ] = '<STR_LIT:foo>' <EOL> self . assertIn ( "<STR_LIT>" , str ( w [ <NUM_LIT:0> ] . message ) ) <EOL> self . assertEqual ( self . settings . get ( '<STR_LIT>' ) , '<STR_LIT:foo>' ) <EOL> self . assertEqual ( self . settings . overrides . get ( '<STR_LIT>' ) , '<STR_LIT:foo>' ) <EOL> self . assertIn ( '<STR_LIT>' , self . settings . overrides ) <EOL> self . settings . overrides . update ( BAR = '<STR_LIT>' ) <EOL> self . assertEqual ( self . settings . get ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . assertEqual ( self . settings . overrides . get ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . settings . overrides . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( self . settings . get ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . settings . overrides . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( self . settings . get ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . assertEqual ( self . settings . overrides . get ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def test_deprecated_attribute_defaults ( self ) : <EOL> self . settings . set ( '<STR_LIT>' , '<STR_LIT>' , priority = '<STR_LIT:default>' ) <EOL> with warnings . catch_warnings ( record = True ) as w : <EOL> self . settings . defaults [ '<STR_LIT>' ] = '<STR_LIT:foo>' <EOL> self . assertIn ( "<STR_LIT>" , str ( w [ <NUM_LIT:0> ] . message ) ) <EOL> self . assertEqual ( self . settings . get ( '<STR_LIT>' ) , '<STR_LIT:foo>' ) <EOL> self . assertEqual ( self . settings . defaults . get ( '<STR_LIT>' ) , '<STR_LIT:foo>' ) <EOL> self . assertIn ( '<STR_LIT>' , self . settings . defaults ) <EOL> class SettingsTest ( unittest . TestCase ) : <EOL> if six . PY3 : <EOL> assertItemsEqual = unittest . TestCase . assertCountEqual <EOL> def setUp ( self ) : <EOL> self . settings = Settings ( ) <EOL> @ mock . patch . dict ( '<STR_LIT>' , { '<STR_LIT:default>' : <NUM_LIT:10> } ) <EOL> @ mock . patch ( '<STR_LIT>' , default_settings ) <EOL> def test_initial_defaults ( self ) : <EOL> settings = Settings ( ) <EOL> self . assertEqual ( len ( settings . attributes ) , <NUM_LIT:2> ) <EOL> self . assertIn ( '<STR_LIT>' , settings . attributes ) <EOL> attr = settings . attributes [ '<STR_LIT>' ] <EOL> self . assertIsInstance ( attr , SettingsAttribute ) <EOL> self . assertEqual ( attr . value , '<STR_LIT>' ) <EOL> self . assertEqual ( attr . priority , <NUM_LIT:10> ) <EOL> @ mock . patch . dict ( '<STR_LIT>' , { } ) <EOL> @ mock . patch ( '<STR_LIT>' , { } ) <EOL> def test_initial_values ( self ) : <EOL> settings = Settings ( { '<STR_LIT>' : '<STR_LIT:value>' } , <NUM_LIT:10> ) <EOL> self . assertEqual ( len ( settings . attributes ) , <NUM_LIT:1> ) <EOL> self . assertIn ( '<STR_LIT>' , settings . attributes ) <EOL> attr = settings . attributes [ '<STR_LIT>' ] <EOL> self . assertIsInstance ( attr , SettingsAttribute ) <EOL> self . assertEqual ( attr . value , '<STR_LIT:value>' ) <EOL> self . assertEqual ( attr . priority , <NUM_LIT:10> ) <EOL> @ mock . patch ( '<STR_LIT>' , default_settings ) <EOL> def test_autopromote_dicts ( self ) : <EOL> settings = Settings ( ) <EOL> mydict = settings . get ( '<STR_LIT>' ) <EOL> self . assertIsInstance ( mydict , BaseSettings ) <EOL> self . assertIn ( '<STR_LIT:key>' , mydict ) <EOL> self . assertEqual ( mydict [ '<STR_LIT:key>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( mydict . getpriority ( '<STR_LIT:key>' ) , <NUM_LIT:0> ) <EOL> @ mock . patch ( '<STR_LIT>' , default_settings ) <EOL> def test_getdict_autodegrade_basesettings ( self ) : <EOL> settings = Settings ( ) <EOL> mydict = settings . getdict ( '<STR_LIT>' ) <EOL> self . assertIsInstance ( mydict , dict ) <EOL> self . assertEqual ( len ( mydict ) , <NUM_LIT:1> ) <EOL> self . assertIn ( '<STR_LIT:key>' , mydict ) <EOL> self . assertEqual ( mydict [ '<STR_LIT:key>' ] , '<STR_LIT>' ) <EOL> class CrawlerSettingsTest ( unittest . TestCase ) : <EOL> def test_deprecated_crawlersettings ( self ) : <EOL> def _get_settings ( settings_dict = None ) : <EOL> settings_module = type ( '<STR_LIT>' , ( object , ) , settings_dict or { } ) <EOL> return CrawlerSettings ( settings_module ) <EOL> with warnings . catch_warnings ( record = True ) as w : <EOL> settings = _get_settings ( ) <EOL> self . assertIn ( "<STR_LIT>" , str ( w [ <NUM_LIT:0> ] . message ) ) <EOL> self . assertEqual ( settings . getint ( '<STR_LIT>' ) , <NUM_LIT> ) <EOL> settings . defaults [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . assertEqual ( settings . getint ( '<STR_LIT>' ) , <NUM_LIT> ) <EOL> settings = _get_settings ( { '<STR_LIT>' : '<STR_LIT:3>' } ) <EOL> self . assertEqual ( settings . getint ( '<STR_LIT>' ) , <NUM_LIT:3> ) <EOL> settings = _get_settings ( { '<STR_LIT>' : '<STR_LIT:3>' } ) <EOL> settings . overrides [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . assertEqual ( settings . getint ( '<STR_LIT>' ) , <NUM_LIT:15> ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
