<s> from __future__ import ( unicode_literals , division , absolute_import , print_function ) <EOL> import os <EOL> from powerline . lib . config import ConfigLoader <EOL> from tests import TestCase <EOL> from tests . lib . fsconfig import FSTree <EOL> FILE_ROOT = os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) <EOL> class LoadedList ( list ) : <EOL> def pop_all ( self ) : <EOL> try : <EOL> return self [ : ] <EOL> finally : <EOL> self [ : ] = ( ) <EOL> loaded = LoadedList ( ) <EOL> def on_load ( key ) : <EOL> loaded . append ( key ) <EOL> def check_file ( path ) : <EOL> if os . path . exists ( path ) : <EOL> return path <EOL> else : <EOL> raise IOError <EOL> class TestLoaderCondition ( TestCase ) : <EOL> def test_update_missing ( self ) : <EOL> loader = ConfigLoader ( run_once = True ) <EOL> fpath = os . path . join ( FILE_ROOT , '<STR_LIT>' ) <EOL> self . assertRaises ( IOError , loader . load , fpath ) <EOL> loader . register_missing ( check_file , on_load , fpath ) <EOL> loader . update ( ) <EOL> with FSTree ( { '<STR_LIT:file>' : { '<STR_LIT:test>' : <NUM_LIT:1> } } , root = FILE_ROOT ) : <EOL> loader . update ( ) <EOL> self . assertEqual ( loader . load ( fpath ) , { '<STR_LIT:test>' : <NUM_LIT:1> } ) <EOL> self . assertEqual ( loaded . pop_all ( ) , [ fpath ] ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from tests import main <EOL> main ( ) </s>
