コード例 #1
0
 def test_load_engine_options__exlucde_defaults_false__modified_options__after_save__loads_modified_options(self):
     with tempfile.NamedTemporaryFile(mode='r+') as options_file:
         modified_options = {'string_none': 'test', 'spin': 100, 'combo': 'two', 'check_true': False}
         options_file.writelines(settings_loader.engine_options_file_lines(TEST_ENGINE_OPTIONS, modified_options))
         options_file.seek(0)
         options = settings_loader.load_engine_options(TEST_ENGINE_OPTIONS, options_file, False)
         all_options = {
             name: modified_options[name] if name in modified_options else value
             for name, value in TEST_ENGINE_OPTIONS_DICT.items()
         }
         self.assertEqual(all_options, options)
コード例 #2
0
 def test_load_engine_options__modified_options__after_save__loads_modified_options(self):
     with tempfile.NamedTemporaryFile(mode='r+') as options_file:
         modified_options: engine.ConfigMapping = {
             'string_none': 'test',
             'spin': 100,
             'combo': 'two',
             'check_true': False
         }
         options_file.writelines(settings_loader.engine_options_file_lines(TEST_ENGINE_OPTIONS, modified_options))
         options_file.seek(0)
         options = settings_loader.load_engine_options(TEST_ENGINE_OPTIONS, options_file)
         self.assertEqual(modified_options, options)
コード例 #3
0
 def test_engine_options_file_lines__default_options(self):
     expected_file_lines = [
         'string_none=                         # type=string\n',
         'string_blank=                        # type=string\n',
         'string_empty=<empty>                 # type=string\n',
         'string_something=something           # type=string\n',
         'spin=0                               # type=spin, min=-100, max=100\n',
         'combo=one                            # type=combo, var=[\'one\', \'two\', \'three\']\n',
         'check_true=True                      # type=check\n',
         'check_false=False                    # type=check\n',
     ]
     self.assertEqual(
         expected_file_lines,
         settings_loader.engine_options_file_lines(TEST_ENGINE_OPTIONS, TEST_ENGINE_OPTIONS_DICT))
コード例 #4
0
 def test_engine_options_file_lines__longer_string__more_whitespace(self):
     expected_file_lines = [
         'string_none=                                       # type=string\n',
         'string_blank=                                      # type=string\n',
         'string_empty=<empty>                               # type=string\n',
         'string_something=this is a longer string           # type=string\n',
         'spin=0                                             # type=spin, min=-100, max=100\n',
         'combo=one                                          # type=combo, var=[\'one\', \'two\', \'three\']\n',
         'check_true=True                                    # type=check\n',
         'check_false=False                                  # type=check\n',
     ]
     modified_options = dict(TEST_ENGINE_OPTIONS_DICT)
     modified_options['string_something'] = 'this is a longer string'
     self.assertEqual(
         expected_file_lines, settings_loader.engine_options_file_lines(TEST_ENGINE_OPTIONS, modified_options))
コード例 #5
0
ファイル: opex.py プロジェクト: Eirik0/opening-explorer
def load_all_engine_options(settings: Json) -> Dict[str, engine.ConfigMapping]:
    """Loads engine options."""
    engine_options: Dict[str, engine.ConfigMapping] = {}
    for engine_setting in typing.cast(List[Json], settings['engines']):
        nickname = typing.cast(str, engine_setting['nickname'])
        path = typing.cast(str, engine_setting['path'])
        with engine.SimpleEngine.popen_uci(path) as uci_engine:
            default_options = [option for _, option in uci_engine.options.items()]
        engine_options_directory = settings['engine_options_directory']
        options_file_path = f'{engine_options_directory}\\{nickname}.uci'
        ensure_file_exists(options_file_path)
        with open(options_file_path, 'r+') as options_file:
            simple_options = settings_loader.load_engine_options_simple(options_file)
            settings_loader.check_engine_options(default_options, simple_options)
            options_file.seek(0)
            options_with_defaults = settings_loader.load_engine_options(default_options, options_file, False)
            options_file.seek(0)
            if simple_options != options_with_defaults:
                options_file.writelines(
                    settings_loader.engine_options_file_lines(default_options, options_with_defaults))
                options_file.seek(0)
            engine_options[nickname] = settings_loader.load_engine_options(default_options, options_file)
    return engine_options