def test_load_settings__missing_key_to_dict__is_populated(self):
     with tempfile.NamedTemporaryFile(mode='r+') as settings_file:
         settings = settings_loader.load_settings(settings_file)
         del settings['data_directory']
         json.dump(settings, settings_file)
         settings_file.seek(0)
         self.assertEqual(settings_loader.load_default_settings(), settings_loader.load_settings(settings_file))
 def test_load_settings__missing_subkey__is_populated(self):
     with tempfile.NamedTemporaryFile(mode='r+') as settings_file:
         settings = settings_loader.load_settings(settings_file)
         del engine_settings(settings)[0]['nickname']
         json.dump(settings, settings_file)
         settings_file.seek(0)
         self.assertEqual(settings_loader.load_default_settings(), settings_loader.load_settings(settings_file))
 def test_load_settings__use_defaults_false__after_save__loads_default_keys(self):
     with tempfile.NamedTemporaryFile(mode='r+') as settings_file:
         default_settings = settings_loader.load_default_settings()
         default_settings['data_directory'] = ''
         default_settings['engine_options_directory'] = ''
         settings = settings_loader.load_settings(settings_file, False)
         json.dump(settings, settings_file)
         settings_file.seek(0)
         self.assertEqual(default_settings, settings_loader.load_settings(settings_file, False))
 def test_load_settings__missing_key_in_list__other_keys_preserved(self):
     with tempfile.NamedTemporaryFile(mode='r+') as settings_file:
         settings = settings_loader.load_settings(settings_file)
         engine_settings(settings)[0]['nickname'] = 'test1'
         engine_settings(settings).append({'nickname': 'test2'})
         json.dump(settings, settings_file)
         settings_file.seek(0)
         settings = settings_loader.load_settings(settings_file)
         self.assertTrue('engines' in settings)
         self.assertEqual(2, len(engine_settings(settings)))
         self.assertEqual({'nickname': 'test1', 'path': ''}, engine_settings(settings)[0])
         self.assertEqual({'nickname': 'test2', 'path': ''}, engine_settings(settings)[1])
예제 #5
0
def load_settings() -> Json:
    """Loads json settings."""
    ensure_file_exists('opex-settings.json')
    with open('opex-settings.json', 'r+') as settings_file:
        settings_simple = settings_loader.load_settings_simple(settings_file)
        settings_file.seek(0)
        settings_no_defaults = settings_loader.load_settings(settings_file, False)
        settings_file.seek(0)
        if settings_simple != settings_no_defaults:
            json.dump(settings_no_defaults, settings_file, indent=4, sort_keys=True)
            settings_file.seek(0)
        return settings_loader.load_settings(settings_file)
 def test_load_settings__use_defaults_false__empty_file__loads_default_keys(self):
     with tempfile.NamedTemporaryFile() as settings_file:
         default_settings = settings_loader.load_default_settings()
         default_settings['data_directory'] = ''
         default_settings['engine_options_directory'] = ''
         self.assertEqual(default_settings, settings_loader.load_settings(settings_file, False))
 def test_load_settings__empty_file__loads_defaults(self):
     with tempfile.NamedTemporaryFile() as settings_file:
         default_settings = settings_loader.load_default_settings()
         self.assertEqual(default_settings, settings_loader.load_settings(settings_file))
 def test_load_settings__after_save__default_values_are_populates(self):
     with tempfile.NamedTemporaryFile(mode='r+') as settings_file:
         settings = settings_loader.load_settings(settings_file, False)
         json.dump(settings, settings_file)
         settings_file.seek(0)
         self.assertEqual(settings_loader.load_default_settings(), settings_loader.load_settings(settings_file))