Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ThanatosGit committed Oct 10, 2024
1 parent b59ac70 commit 29cf504
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/mercury_engine_data_structures/romfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pathlib import Path
from typing import Iterator

from mercury_engine_data_structures.formats.Rom3ds import Rom3DS
from mercury_engine_data_structures.formats.rom3ds import Rom3DS


class RomFs(ABC):
Expand Down
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def samus_returns_path():
return Path(get_env_or_skip("SAMUS_RETURNS_PATH"))


@pytest.fixture(scope="session")
def samus_returns_roms_path():
return Path(get_env_or_skip("SAMUS_RETURNS_PATH_ROMS"))


@pytest.fixture(scope="session")
def dread_path_100():
return Path(get_env_or_skip("DREAD_1_0_0_PATH"))
Expand Down
16 changes: 16 additions & 0 deletions tests/formats/test_rom3ds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pytest

from mercury_engine_data_structures.formats.rom3ds import Rom3DS


@pytest.mark.parametrize("rom_ending", [".cxi", ".cia", ".3ds"])
def test_compare_pkg_sr(samus_returns_roms_path, rom_ending):
file_path = samus_returns_roms_path.joinpath("MSR" + rom_ending).as_posix()
with open(file_path, "rb") as file_stream:
rom = Rom3DS(file_path, file_stream)
# deactivated to not let other users tests fail when they use a NTSC version
# assert rom.get_title_id() == "00040000001BFB00"
# assert rom.is_pal()
assert rom.get_file_binary("gui/scripts/loadingscreen.lc")[:6] == b"\x1bLuaQ\x00"
assert rom.decompress_code()[:6] == b"\x07\x00\x00\xeb\x92#"
assert rom.exheader()[:8] == b"MATADORA"
9 changes: 9 additions & 0 deletions tests/test_file_tree_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import pytest

from mercury_engine_data_structures.file_tree_editor import FileTreeEditor
from mercury_engine_data_structures.game_check import Game
from mercury_engine_data_structures.romfs import PackedRomFs


def test_add_new_file_exists_romfs(dread_tree_100):
with pytest.raises(ValueError, match=re.escape("Asset already exists in:\nIn the RomFS")):
Expand All @@ -11,3 +15,8 @@ def test_add_new_file_exists_romfs(dread_tree_100):
def test_add_new_file_exists_pkg(dread_tree_100):
with pytest.raises(ValueError, match=re.escape("Asset already exists in:\npacks/maps/s010_cave/s010_cave.pkg")):
dread_tree_100.add_new_asset("maps/levels/c10_samus/s010_cave/s010_cave.brfld", b"boo", [])


def test_file_tree_editor_with_packed_romfs(samus_returns_roms_path):
tree = FileTreeEditor(PackedRomFs(samus_returns_roms_path.joinpath("MSR.3ds")), Game.SAMUS_RETURNS)
assert tree.does_asset_exists("actors/characters/alpha/charclasses/alpha.bmsad")

0 comments on commit 29cf504

Please sign in to comment.