Skip to content

Commit

Permalink
improve breakpoint tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Baekalfen committed Feb 10, 2024
1 parent 149bf11 commit 42245a0
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions tests/test_breakpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


def test_debugprompt(default_rom, monkeypatch):
pyboy = PyBoy(default_rom, window_type="dummy", breakpoints="0:0100,-1:0", debug=False)
pyboy = PyBoy(default_rom, window_type="null", breakpoints="0:0100,-1:0", debug=False)
pyboy.set_emulation_speed(0)

# Break at 0, step once, continue, break at 100, continue
Expand All @@ -29,7 +29,7 @@ def test_debugprompt(default_rom, monkeypatch):

@pytest.mark.parametrize("commands", ["n\nc\n", "n\nn\nc\n", "c\nc\n", "n\nn\nn\nn\nn\nn\nc\n"])
def test_debugprompt2(default_rom, monkeypatch, commands):
pyboy = PyBoy(default_rom, window_type="dummy", breakpoints="-1:0,-1:3", debug=False)
pyboy = PyBoy(default_rom, window_type="null", breakpoints="-1:0,-1:3", debug=False)
pyboy.set_emulation_speed(0)

monkeypatch.setattr("sys.stdin", io.StringIO(commands))
Expand All @@ -41,7 +41,7 @@ def test_debugprompt2(default_rom, monkeypatch, commands):


def test_register_hooks(default_rom):
pyboy = PyBoy(default_rom, window_type="dummy")
pyboy = PyBoy(default_rom, window_type="null")
pyboy.set_emulation_speed(0)

mock = Mock()
Expand All @@ -55,7 +55,7 @@ def test_register_hooks(default_rom):


def test_register_hook_context(default_rom):
pyboy = PyBoy(default_rom, window_type="dummy")
pyboy = PyBoy(default_rom, window_type="null")
pyboy.set_emulation_speed(0)

def _inner_callback(context):
Expand All @@ -72,16 +72,33 @@ def _inner_callback(context):
assert len(_context) == 1


def test_register_hook_print(default_rom, capfd):
pyboy = PyBoy(default_rom, window_type="null")
pyboy.set_emulation_speed(0)

def _inner_callback(context):
print(context)

bank = -1 # "ROM bank number" for bootrom
addr = 0xFC # Address of last instruction. Expected to execute once.
pyboy.hook_register(bank, addr, _inner_callback, "Hello!")
for _ in range(120):
pyboy.tick()

out, err = capfd.readouterr()
assert out == "Hello!\n"


def test_symbols_none(default_rom):
pyboy = PyBoy(default_rom, window_type="dummy")
pyboy = PyBoy(default_rom, window_type="null")
pyboy.set_emulation_speed(0)

with pytest.raises(ValueError):
pyboy._lookup_symbol("Main.waitVBlank")


def test_symbols_auto_locate():
pyboy = PyBoy("extras/default_rom/default_rom.gb", window_type="dummy")
pyboy = PyBoy("extras/default_rom/default_rom.gb", window_type="null")
pyboy.set_emulation_speed(0)

_bank, _addr = pyboy._lookup_symbol("Main.waitVBlank")
Expand All @@ -90,7 +107,7 @@ def test_symbols_auto_locate():


def test_symbols_path_locate(default_rom):
pyboy = PyBoy(default_rom, window_type="dummy", symbols_file="extras/default_rom/default_rom.sym")
pyboy = PyBoy(default_rom, window_type="null", symbols_file="extras/default_rom/default_rom.sym")
pyboy.set_emulation_speed(0)

_bank, _addr = pyboy._lookup_symbol("Main.waitVBlank")
Expand All @@ -99,7 +116,7 @@ def test_symbols_path_locate(default_rom):


def test_register_hook_label(default_rom):
pyboy = PyBoy(default_rom, window_type="dummy", symbols_file="extras/default_rom/default_rom.sym")
pyboy = PyBoy(default_rom, window_type="null", symbols_file="extras/default_rom/default_rom.sym")
pyboy.set_emulation_speed(0)

def _inner_callback(context):
Expand All @@ -117,7 +134,7 @@ def _inner_callback(context):


def test_register_hook_context2(default_rom):
pyboy = PyBoy(default_rom, window_type="dummy")
pyboy = PyBoy(default_rom, window_type="null")
pyboy.set_emulation_speed(0)

def _inner_callback(context):
Expand All @@ -136,7 +153,7 @@ def _inner_callback(context):


def test_register_hooks_double(default_rom):
pyboy = PyBoy(default_rom, window_type="dummy")
pyboy = PyBoy(default_rom, window_type="null")
pyboy.set_emulation_speed(0)

mock = Mock()
Expand All @@ -146,7 +163,7 @@ def test_register_hooks_double(default_rom):


def test_deregister_hooks(default_rom):
pyboy = PyBoy(default_rom, window_type="dummy")
pyboy = PyBoy(default_rom, window_type="null")
pyboy.set_emulation_speed(0)

mock = Mock()
Expand All @@ -163,7 +180,7 @@ def test_deregister_hooks(default_rom):


def test_deregister_hooks2(default_rom):
pyboy = PyBoy(default_rom, window_type="dummy")
pyboy = PyBoy(default_rom, window_type="null")
pyboy.set_emulation_speed(0)

mock = Mock()
Expand Down

0 comments on commit 42245a0

Please sign in to comment.