Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ happens **on your PC, from your own copy of the game**.
Discord: https://discord.gg/rexed
<br>

CA 8T3ztDSKxYK15SUBseqLeviqQwfcG9wUeDGP1wjBpump

## Project status

**Early. The game does not boot yet.** Everything that can be done without the game's executable is in place, so
Expand Down
21 changes: 18 additions & 3 deletions make_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,21 @@ def choose_game() -> str:
if not interactive:
fail("More than one copy found: choose one with --game.")
while True:
pick = input("Which one? ").strip()
try:
pick = input("Which one? ").strip()
except EOFError: # Ctrl+Z / Ctrl+D, or a console that gives no input
fail("No copy chosen: choose one with --game.")
if pick.isdigit() and 1 <= int(pick) <= len(found):
return found[int(pick) - 1][0]
if not interactive:
fail("Your game files weren't found. Give the folder with --game.")
print("Your game files weren't found automatically. Paste the folder that holds MicrosoftGame.Config "
"and the .rpf archives.")
while True:
d = input("Game folder: ").strip().strip('"')
try:
d = input("Game folder: ").strip().strip('"')
except EOFError:
fail("No folder given. Give the folder with --game.")
if d and match_version(d):
return d
print(" That folder isn't a supported version of the game. Try again.")
Expand Down Expand Up @@ -822,5 +828,14 @@ def main() -> int:
return 0


def cli() -> int:
"""main(), with Ctrl+C reported in one line instead of a traceback: every stage resumes on the next run."""
try:
return main()
except KeyboardInterrupt:
print("\nStopped. Run it again to continue where it left off.", file=sys.stderr)
return 130


if __name__ == "__main__":
sys.exit(main())
sys.exit(cli())
54 changes: 54 additions & 0 deletions tests/test_make_game_interrupt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""make_game.py: end of input at a prompt and Ctrl+C give one line, not a traceback (no game files needed).

python -I tests/test_make_game_interrupt.py
"""
import contextlib
import io
import os
import sys
import unittest
from unittest.mock import patch

ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if ROOT not in sys.path:
sys.path.insert(0, ROOT)
import make_game # noqa: E402

COPY = {"title": "Xbox Series package", "version": "1.0.2.1"}


class PromptWithoutInput(unittest.TestCase):
def choose(self, found):
err = io.StringIO()
with (patch("make_game.find_dumps", return_value=found), patch("make_game.log"),
patch.object(sys, "stdin", **{"isatty.return_value": True}),
patch("builtins.input", side_effect=EOFError), contextlib.redirect_stdout(io.StringIO()),
contextlib.redirect_stderr(err), self.assertRaises(SystemExit) as stop):
make_game.choose_game()
return stop.exception.code, err.getvalue()

def test_game_folder_prompt(self):
code, err = self.choose([])
self.assertEqual(code, 1)
self.assertIn("Give the folder with --game", err)

def test_which_copy_prompt(self):
code, err = self.choose([("D:/a", COPY), ("D:/b", COPY)])
self.assertEqual(code, 1)
self.assertIn("choose one with --game", err)


class CtrlC(unittest.TestCase):
def test_one_line_and_exit_130(self):
err = io.StringIO()
with patch("make_game.main", side_effect=KeyboardInterrupt), contextlib.redirect_stderr(err):
self.assertEqual(make_game.cli(), 130)
self.assertEqual(err.getvalue().strip(), "Stopped. Run it again to continue where it left off.")

def test_other_exit_codes_pass_through(self):
with patch("make_game.main", return_value=0):
self.assertEqual(make_game.cli(), 0)


if __name__ == "__main__":
unittest.main()