Test suite modernization
This commit is contained in:
parent
0969f7c2f6
commit
52fdfd0347
141 changed files with 9947 additions and 4665 deletions
|
|
@ -9,40 +9,32 @@ import sys
|
|||
|
||||
def test_remove_by_entity():
|
||||
"""Test removing entities by passing the entity object"""
|
||||
|
||||
|
||||
# Create a test scene and grid
|
||||
scene_name = "test_entity_remove"
|
||||
_scene = mcrfpy.Scene(scene_name)
|
||||
|
||||
|
||||
# Create a grid (entities need a grid)
|
||||
grid = mcrfpy.Grid() # Default 2x2 grid is fine for testing
|
||||
_scene.children.append(grid) # TODO: Replace _scene with correct Scene object
|
||||
|
||||
grid = mcrfpy.Grid(grid_size=(30, 30), pos=(0, 0), size=(300, 300))
|
||||
_scene.children.append(grid)
|
||||
|
||||
# Get the entity collection
|
||||
entities = grid.entities
|
||||
|
||||
# Create some test entities
|
||||
# Entity() creates entities with default position (0,0)
|
||||
entity1 = mcrfpy.Entity()
|
||||
entity1.x = 5
|
||||
entity1.y = 5
|
||||
|
||||
entity2 = mcrfpy.Entity()
|
||||
entity2.x = 10
|
||||
entity2.y = 10
|
||||
|
||||
entity3 = mcrfpy.Entity()
|
||||
entity3.x = 15
|
||||
entity3.y = 15
|
||||
|
||||
|
||||
# Create some test entities - position is set via constructor tuple (grid coords)
|
||||
# Entity.x/.y requires grid attachment, so append first, then check
|
||||
entity1 = mcrfpy.Entity((5, 5))
|
||||
entity2 = mcrfpy.Entity((10, 10))
|
||||
entity3 = mcrfpy.Entity((15, 15))
|
||||
|
||||
# Add entities to the collection
|
||||
entities.append(entity1)
|
||||
entities.append(entity2)
|
||||
entities.append(entity3)
|
||||
|
||||
|
||||
print(f"Initial entity count: {len(entities)}")
|
||||
assert len(entities) == 3, "Should have 3 entities"
|
||||
|
||||
|
||||
# Test 1: Remove an entity that exists
|
||||
print("\nTest 1: Remove existing entity")
|
||||
entities.remove(entity2)
|
||||
|
|
@ -50,53 +42,51 @@ def test_remove_by_entity():
|
|||
assert entity1 in entities, "Entity1 should still be in collection"
|
||||
assert entity2 not in entities, "Entity2 should not be in collection"
|
||||
assert entity3 in entities, "Entity3 should still be in collection"
|
||||
print("✓ Successfully removed entity2")
|
||||
|
||||
print(" Successfully removed entity2")
|
||||
|
||||
# Test 2: Try to remove an entity that's not in the collection
|
||||
print("\nTest 2: Remove non-existent entity")
|
||||
try:
|
||||
entities.remove(entity2) # Already removed
|
||||
assert False, "Should have raised ValueError"
|
||||
except ValueError as e:
|
||||
print(f"✓ Got expected ValueError: {e}")
|
||||
|
||||
print(f" Got expected ValueError: {e}")
|
||||
|
||||
# Test 3: Try to remove with wrong type
|
||||
print("\nTest 3: Remove with wrong type")
|
||||
try:
|
||||
entities.remove(42) # Not an Entity
|
||||
assert False, "Should have raised TypeError"
|
||||
except TypeError as e:
|
||||
print(f"✓ Got expected TypeError: {e}")
|
||||
|
||||
print(f" Got expected TypeError: {e}")
|
||||
|
||||
# Test 4: Try to remove with None
|
||||
print("\nTest 4: Remove with None")
|
||||
try:
|
||||
entities.remove(None)
|
||||
assert False, "Should have raised TypeError"
|
||||
except TypeError as e:
|
||||
print(f"✓ Got expected TypeError: {e}")
|
||||
|
||||
print(f" Got expected TypeError: {e}")
|
||||
|
||||
# Test 5: Verify grid property is cleared (C++ internal)
|
||||
print("\nTest 5: Grid property handling")
|
||||
# Create a new entity and add it
|
||||
entity4 = mcrfpy.Entity()
|
||||
entity4.x = 20
|
||||
entity4.y = 20
|
||||
entity4 = mcrfpy.Entity((20, 20))
|
||||
entities.append(entity4)
|
||||
# Note: grid property is managed internally in C++ and not exposed to Python
|
||||
|
||||
|
||||
# Remove it - this clears the C++ grid reference internally
|
||||
entities.remove(entity4)
|
||||
print("✓ Grid property handling (managed internally in C++)")
|
||||
|
||||
print(" Grid property handling (managed internally in C++)")
|
||||
|
||||
# Test 6: Remove all entities one by one
|
||||
print("\nTest 6: Remove all entities")
|
||||
entities.remove(entity1)
|
||||
entities.remove(entity3)
|
||||
assert len(entities) == 0, "Collection should be empty"
|
||||
print("✓ Successfully removed all entities")
|
||||
|
||||
print("\n✅ All tests passed!")
|
||||
print(" Successfully removed all entities")
|
||||
|
||||
print("\nAll tests passed!")
|
||||
return True
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
@ -104,7 +94,7 @@ if __name__ == "__main__":
|
|||
success = test_remove_by_entity()
|
||||
sys.exit(0 if success else 1)
|
||||
except Exception as e:
|
||||
print(f"\n❌ Test failed with exception: {e}")
|
||||
print(f"\nTest failed with exception: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
sys.exit(1)
|
||||
sys.exit(1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue