Skip to content

Commit

Permalink
(#23) blocking out tests for BspLump refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
snake-biscuits committed May 8, 2023
1 parent b60e1fa commit 8cdcbf4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
14 changes: 6 additions & 8 deletions bsp_tool/lumps.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,22 @@ def decompressed(stream: Stream, lump_header: LumpHeader) -> (Stream, LumpHeader
return stream, lump_header


def create_BspLump(stream: Stream, lump_header: LumpHeader, LumpClass: object = None) -> BspLump:
def create_RawBspLump(stream: Stream, lump_header: LumpHeader) -> RawBspLump:
if hasattr(lump_header, "fourCC"):
stream, lump_header = decompressed(stream, lump_header)
if not hasattr(lump_header, "filename"):
return BspLump.from_header(stream, lump_header, LumpClass)
return RawBspLump.from_header(stream, lump_header)
else:
return ExternalBspLump.from_header(lump_header, LumpClass)
return ExternalRawBspLump.from_header(lump_header)


def create_RawBspLump(stream: Stream, lump_header: LumpHeader) -> RawBspLump:
def create_BspLump(stream: Stream, lump_header: LumpHeader, LumpClass: object = None) -> BspLump:
if hasattr(lump_header, "fourCC"):
stream, lump_header = decompressed(stream, lump_header)
if not hasattr(lump_header, "filename"):
return RawBspLump.from_header(stream, lump_header)
return BspLump.from_header(stream, lump_header, LumpClass)
else:
return ExternalRawBspLump.from_header(lump_header)
return ExternalBspLump.from_header(lump_header, LumpClass)


def create_BasicBspLump(stream: Stream, lump_header: LumpHeader, LumpClass: object) -> BasicBspLump:
Expand Down Expand Up @@ -222,8 +222,6 @@ def __delitem__(self, index: Union[int, slice]):

def __getitem__(self, index: Union[int, slice]):
"""Reads bytes from self.stream & returns LumpClass(es)"""
# read bytes -> struct.unpack tuples -> LumpClass
# NOTE: BspLump[index] = LumpClass(entry)
if isinstance(index, int):
index = _remap_negative_index(index, self._length)
if index in self._changes:
Expand Down
18 changes: 18 additions & 0 deletions tests/test_lumps.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ class LumpClass_basic(base.MappedArray):
_format = "3H"


class TestRawBspLump:
"""test the changes system & bytearray-like behaviour"""
# TODO: tests to ensure RawBspLump behaves like a bytearray
def test_concat(self):
header = LumpHeader_basic(offset=0, length=8)
stream = io.BytesIO(bytes([*range(8)]))
lump = lumps.RawBspLump.from_header(stream, header)
lump += bytes([*range(8, 16)])
assert len(lump) == 16
for i, x in enumerate(lump):
assert i == x


class TestBspLump:
@pytest.mark.xfail(reason="not yet implemented")
def test_implicit_change(self):
Expand All @@ -53,3 +66,8 @@ def test_implicit_change(self):
assert lump[0].x == 1
lump[0].x += 1
assert lump[0].x == 2


# TODO: external lump test files as part of test maps (Issue #16)
# TODO: TestGameLump
# TODO: TestDarkMessiahSPGameLump

0 comments on commit 8cdcbf4

Please sign in to comment.