Skip to content

Commit

Permalink
Created more bugs trying to tackle Issue #23
Browse files Browse the repository at this point in the history
  • Loading branch information
snake-biscuits committed May 21, 2022
1 parent af724ba commit 1da55ba
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 24 deletions.
18 changes: 12 additions & 6 deletions bsp_tool/lumps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,20 @@ def __iadd__(self, other_bytes: bytes):
self._length += len(other_bytes)
self[start:] = other_bytes

def __setitem__(self, index: slice, value: Any):
def __setitem__(self, index: int | slice, value: Any):
"""remapping slices is allowed, but only slices"""
if not isinstance(index, slice):
raise TypeError(f"list indices must be integers or slices, not {type(index)}")
_slice = _remap_slice(index, self._length)
# TODO: allow slice assignment to act like insert/extend
for i, v in zip(range(_slice.start, _slice.stop, _slice.step), value):
if isinstance(index, int):
index = _remap_negative_index(index, self._length)
self._changes[index] = value
elif isinstance(index, slice):
# TODO: allow slice assignment to act like insert/extend
_slice = _remap_slice(index, self._length)
slice_indices = list(range(_slice.start, _slice.stop, _slice.step))
assert len(list(value)) == len(slice_indices), "slice insert/shorten not yet supported"
for i, v in zip(slice_indices, value):
self._changes[i] = v
else:
raise TypeError(f"list indices must be integers or slices, not {type(index)}")

def __iter__(self):
return iter([self[i] for i in range(self._length)])
Expand Down
69 changes: 51 additions & 18 deletions pytest_all_bsps.log
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
============================= test session starts =============================
platform win32 -- Python 3.9.12, pytest-6.2.4, py-1.10.0, pluggy-0.13.1 -- c:\users\jared\documents\github\bsp_tool\venv\scripts\python.exe
platform win32 -- Python 3.9.13, pytest-6.2.4, py-1.10.0, pluggy-0.13.1 -- c:\users\jared\documents\github\bsp_tool\venv\scripts\python.exe
cachedir: .pytest_cache
rootdir: C:\Users\Jared\Documents\GitHub\bsp_tool
plugins: cov-2.12.1
Expand Down Expand Up @@ -134,7 +134,7 @@ tests/test_bsplump.py::TestRawBspLump::test_list_conversion PASSED
tests/test_bsplump.py::TestRawBspLump::test_indexing PASSED [ 66%]
tests/test_bsplump.py::TestBspLump::test_list_conversion PASSED [ 67%]
tests/test_bsplump.py::TestBspLump::test_indexing PASSED [ 67%]
tests/test_bsplump.py::TestBspLump::test_del PASSED [ 68%]
tests/test_bsplump.py::TestBspLump::test_del FAILED [ 68%]
tests/test_bsplump.py::TestBspLump::test_setitem PASSED [ 68%]
tests/test_bsplump.py::TestBasicBspLump::test_its_basic PASSED [ 69%]
tests/test_bsplump.py::TestBasicBspLump::test_list_conversion PASSED [ 69%]
Expand Down Expand Up @@ -1169,6 +1169,38 @@ raw_entities = b'{\n"editorclass" "info_particle_system_clientside"\n"Visibility
E StopIteration

bsp_tool\branches\shared.py:69: StopIteration
____________________________ TestBspLump.test_del _____________________________

self = <tests.test_bsplump.TestBspLump object at 0x000001E20C5FBDF0>

def test_del(self):
for map_name in bsps:
lump = bsps[map_name].VERTICES
initial_length = len(lump)
> del lump[0]

tests\test_bsplump.py:72:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
bsp_tool\lumps\__init__.py:184: in __delitem__
self[index:] = self[index + 1:]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <BspLump(24 Vertex) at 0x000001E20B6B62E0>, index = slice(0, None, None)
value = [<Vertex {'position': <MappedArray (x: 192.0, y: -192.0, z: -192.0)>, 'uv': <MappedArray (texture: <MappedArray (u: -3...5)>)>, 'normal': <MappedArray (x: 0.0, y: -1.0, z: 0.0)>, 'colour': <MappedArray (r: 13, g: 13, b: 13, a: 255)>}>, ...]

def __setitem__(self, index: int | slice, value: Any):
"""remapping slices is allowed, but only slices"""
if isinstance(index, int):
index = _remap_negative_index(index, self._length)
self._changes[index] = value
elif isinstance(index, slice):
# TODO: allow slice assignment to act like insert/extend
_slice = _remap_slice(index, self._length)
slice_indices = list(range(_slice.start, _slice.stop, _slice.step))
> assert len(list(value)) == len(slice_indices), "slice insert/shorten not yet supported"
E AssertionError: slice insert/shorten not yet supported

bsp_tool\lumps\__init__.py:144: AssertionError
============================== warnings summary ===============================
tests/branches/test_branch_scripts.py::test_basic_branch_script[bsp_tool.branches.id_software.quake]
C:\Users\Jared\Documents\GitHub\bsp_tool\tests\branches\test_branch_scripts.py:81: UserWarning: Unused LumpClasses in branch script:
Expand All @@ -1177,24 +1209,24 @@ tests/branches/test_branch_scripts.py::test_basic_branch_script[bsp_tool.branche

tests/branches/test_branch_scripts.py::test_basic_branch_script[bsp_tool.branches.infinity_ward.call_of_duty1]
C:\Users\Jared\Documents\GitHub\bsp_tool\tests\branches\test_branch_scripts.py:81: UserWarning: Unused LumpClasses in branch script:
Node
PatchCollision
Portal
Light
Brush
Cell
DrawVertex
Model
AxisAlignedBoundingBox
CullGroup
Brush
Occluder
AxisAlignedBoundingBox
Model
PatchCollision
Node
Cell
Portal
Light
warnings.warn(UserWarning(warning_text))

tests/branches/test_branch_scripts.py::test_basic_branch_script[bsp_tool.branches.infinity_ward.call_of_duty2]
C:\Users\Jared\Documents\GitHub\bsp_tool\tests\branches\test_branch_scripts.py:81: UserWarning: Unused LumpClasses in branch script:
CollisionTriangle
Model
CollisionEdge
Model
CollisionTriangle
warnings.warn(UserWarning(warning_text))

tests/branches/test_branch_scripts.py::test_branch_script[bsp_tool.branches.arkane.dark_messiah_singleplayer]
Expand All @@ -1215,8 +1247,8 @@ tests/branches/test_branch_scripts.py::test_branch_script[bsp_tool.branches.resp

tests/branches/test_branch_scripts.py::test_branch_script[bsp_tool.branches.valve.orange_box_x360]
C:\Users\Jared\Documents\GitHub\bsp_tool\tests\branches\test_branch_scripts.py:123: UserWarning: Unused LumpClasses in branch script:
DisplacementInfo_x360
Primitive_x360
DisplacementInfo_x360
warnings.warn(UserWarning(warning_text))

tests/branches/test_branch_scripts.py::test_branch_script[bsp_tool.branches.valve.source]
Expand All @@ -1226,7 +1258,7 @@ tests/branches/test_branch_scripts.py::test_branch_script[bsp_tool.branches.valv

-- Docs: https://docs.pytest.org/en/stable/warnings.html

---------- coverage: platform win32, python 3.9.12-final-0 -----------
---------- coverage: platform win32, python 3.9.13-final-0 -----------
Name Stmts Miss Cover
---------------------------------------------------------------------------
bsp_tool\__init__.py 53 3 94%
Expand Down Expand Up @@ -1290,23 +1322,24 @@ bsp_tool\branches\vector.py 190 129 32%
bsp_tool\branches\x360.py 15 0 100%
bsp_tool\extensions\__init__.py 0 0 100%
bsp_tool\extensions\archive.py 70 70 0%
bsp_tool\extensions\decompile_rbsp.py 41 41 0%
bsp_tool\extensions\decompile_rbsp.py 42 42 0%
bsp_tool\extensions\decrypt_xor.py 11 11 0%
bsp_tool\extensions\diff.py 111 111 0%
bsp_tool\extensions\lightmaps.py 191 191 0%
bsp_tool\extensions\mprt.py 12 12 0%
bsp_tool\id_software.py 117 15 87%
bsp_tool\infinity_ward.py 69 10 86%
bsp_tool\lumps\__init__.py 341 91 73%
bsp_tool\lumps\__init__.py 343 95 72%
bsp_tool\raven.py 3 0 100%
bsp_tool\respawn.py 253 135 47%
bsp_tool\ritual.py 45 3 93%
bsp_tool\valve.py 136 68 50%
---------------------------------------------------------------------------
TOTAL 6965 1603 77%
TOTAL 6968 1608 77%

=========================== short test summary info ===========================
FAILED tests/test_bsp.py::test_load_bsp[E:/Mod-CSO2-map_dirs94] - AssertionEr...
FAILED tests/test_bsp.py::test_load_bsp[E:/Mod-Vindictus-map_dirs102] - Asser...
FAILED tests/test_bsp.py::test_load_bsp[E:/Mod-Titanfall/x360-map_dirs104] - ...
=========== 3 failed, 188 passed, 8 warnings in 13432.14s (3:43:52) ===========
FAILED tests/test_bsplump.py::TestBspLump::test_del - AssertionError: slice i...
=========== 4 failed, 187 passed, 8 warnings in 13689.11s (3:48:09) ===========

0 comments on commit 1da55ba

Please sign in to comment.