#NEWLINE# def test_load_configuration_file( ) : #NEWLINE# #INDENT# '\n    Test that we can read and write a config file.\n    ' #NEWLINE# config = ConfigurationLoader ( ) #NEWLINE# base_dir = os . path . dirname ( os . path . abspath ( __file__ ) ) #NEWLINE# config_path = os . path . join ( base_dir , 'tmp-configuration.json' ) #NEWLINE# config . configuration_file_path = config_path #NEWLINE# config_dict = config . load_configuration_file ( ) #NEWLINE# assert os . path . exists ( config_path ) , "Didn't write a config file!" #NEWLINE# assert ( config_dict == DEFAULT_CONFIG ) , "Config returned doesn't match default config" #NEWLINE# with open ( config_path , 'r' ) as f : #NEWLINE# #INDENT# written_config = json . load ( f ) #NEWLINE# #UNINDENT# assert ( written_config == DEFAULT_CONFIG ) , "Written config doesn't match default config" #NEWLINE# new_config = { #NEWLINE# #INDENT# 'window' : { #NEWLINE# #INDENT# 'width' : 813 , #NEWLINE# 'height' : 2450 , #NEWLINE# 'ticks_per_second' : 63 , #NEWLINE# 'resizeable' : False , #NEWLINE# 'exclusive_mouse' : False , #NEWLINE# #UNINDENT# } , #NEWLINE# 'controls' : { #NEWLINE# #INDENT# 'forward' : 'Z' , #NEWLINE# 'backward' : 'S' , #NEWLINE# 'right' : 'D' , #NEWLINE# 'left' : 'Q' , #NEWLINE# 'jump' : 'LSHIFT' , #NEWLINE# 'down' : 'TAB' , #NEWLINE# 'fly' : 'SPACE' , #NEWLINE# #UNINDENT# } , #NEWLINE# 'world' : { #NEWLINE# #INDENT# 'gravity' : 234.0 , #NEWLINE# 'player_height' : 123 , #NEWLINE# 'max_jump_height' : 34.1 , #NEWLINE# 'terminal_velocity' : 431 , #NEWLINE# 'walking_speed' : 12 , #NEWLINE# 'flying_speed' : 34 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# with open ( config_path , 'w' ) as f : #NEWLINE# #INDENT# json . dump ( new_config , f , indent = 4 ) #NEWLINE# #UNINDENT# opened_config = config . load_configuration_file ( ) #NEWLINE# assert ( opened_config == new_config ) , "Loaded config doesn't match what we wrote" #NEWLINE# os . remove ( config_path )