def test_create_node_and_save(tmp_path, echoes_game_data, skip_qtbot): # Setup tmp_path.joinpath("test-game", "game").mkdir(parents=True) tmp_path.joinpath("human-readable").mkdir() db_path = Path(tmp_path.joinpath("test-game", "game")) window = DataEditorWindow(echoes_game_data, db_path, True, True) window.set_warning_dialogs_disabled(True) skip_qtbot.addWidget(window) # Run window._do_create_node("Some Node", None) window._save_as_internal_database() # Assert exported_data = data_reader.read_split_file(db_path) exported_game = data_reader.decode_data(exported_data) pretty_print.write_human_readable_game(exported_game, tmp_path.joinpath("human-readable")) new_files = { f.name: f.read_text("utf-8") for f in tmp_path.joinpath("human-readable").glob("*.txt") } existing_files = { f.name: f.read_text("utf-8") for f in tmp_path.joinpath("test-game", "game").glob("*.txt") } assert list(new_files.keys()) == list(existing_files.keys()) assert new_files == existing_files
def test_save_database_integrity_failure(tmp_path, echoes_game_data, skip_qtbot, mocker): # Setup mock_find_database_errors = mocker.patch( "randovania.game_description.integrity_check.find_database_errors", return_value=["DB Errors", "Unknown"]) mock_write_human_readable_game = mocker.patch( "randovania.game_description.pretty_print.write_human_readable_game") mock_create_new = mocker.patch( "randovania.gui.lib.scroll_message_box.ScrollMessageBox.create_new") mock_create_new.return_value.exec_.return_value = QtWidgets.QMessageBox.No tmp_path.joinpath("test-game", "game").mkdir(parents=True) tmp_path.joinpath("human-readable").mkdir() db_path = Path(tmp_path.joinpath("test-game", "game")) window = DataEditorWindow(echoes_game_data, db_path, True, True) skip_qtbot.addWidget(window) # Run window._save_as_internal_database() # Assert mock_find_database_errors.assert_called_once_with(window.game_description) mock_write_human_readable_game.assert_not_called() mock_create_new.assert_called_once_with( window, QtWidgets.QMessageBox.Icon.Critical, "Integrity Check", "Database has the following errors:\n\nDB Errors\n\nUnknown\n\nIgnore?", QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No)
def test_create_node_and_save(mock_prime2_human_readable_path, mock_prime2_json_path, tmpdir, echoes_game_data, skip_qtbot): # Setup mock_prime2_human_readable_path.return_value = Path(tmpdir).joinpath( "human") mock_prime2_json_path.return_value = Path(tmpdir).joinpath("database") window = DataEditorWindow(echoes_game_data, True) skip_qtbot.addWidget(window) # Run window._do_create_node("Some Node") window._save_as_internal_database() # Assert with mock_prime2_json_path.return_value.open() as data_file: exported_data = json.load(data_file) exported_game = data_reader.decode_data(exported_data) output = io.StringIO() data_writer.write_human_readable_world_list(exported_game, output) assert mock_prime2_human_readable_path.return_value.read_text( "utf-8") == output.getvalue()
def test_create_node_and_save(tmpdir, echoes_game_data, skip_qtbot): # Setup db_path = Path(tmpdir.join("game.json")) window = DataEditorWindow(echoes_game_data, db_path, True, True) skip_qtbot.addWidget(window) # Run window._do_create_node("Some Node") window._save_as_internal_database() # Assert with db_path.open() as data_file: exported_data = json.load(data_file) exported_game = data_reader.decode_data(exported_data) output = io.StringIO() randovania.game_description.pretty_print.write_human_readable_world_list( exported_game, output) assert Path( tmpdir.join("game.txt")).read_text("utf-8") == output.getvalue()