From 1da55ba690ff4205e977869a9ce61c37d5ab37b8 Mon Sep 17 00:00:00 2001 From: snake-biscuits <36507175+snake-biscuits@users.noreply.github.com> Date: Sat, 21 May 2022 10:59:56 +0100 Subject: [PATCH] Created more bugs trying to tackle Issue #23 --- bsp_tool/lumps/__init__.py | 18 ++++++---- pytest_all_bsps.log | 69 ++++++++++++++++++++++++++++---------- 2 files changed, 63 insertions(+), 24 deletions(-) diff --git a/bsp_tool/lumps/__init__.py b/bsp_tool/lumps/__init__.py index f83e7b0a..079ae351 100644 --- a/bsp_tool/lumps/__init__.py +++ b/bsp_tool/lumps/__init__.py @@ -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)]) diff --git a/pytest_all_bsps.log b/pytest_all_bsps.log index a69b1562..ab44d1d7 100644 --- a/pytest_all_bsps.log +++ b/pytest_all_bsps.log @@ -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 @@ -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%] @@ -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 = + + 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 = , index = slice(0, None, None) +value = [, 'uv': )>, 'normal': , 'colour': }>, ...] + + 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: @@ -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] @@ -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] @@ -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% @@ -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) ===========