Test suite modernization
This commit is contained in:
parent
0969f7c2f6
commit
52fdfd0347
141 changed files with 9947 additions and 4665 deletions
|
|
@ -20,57 +20,56 @@ def test_keypress_validation(timer, runtime):
|
|||
|
||||
try:
|
||||
test.on_key = key_handler
|
||||
print("✓ Accepted valid function as key handler")
|
||||
print("OK: Accepted valid function as key handler")
|
||||
except Exception as e:
|
||||
print(f"✗ Rejected valid function: {e}")
|
||||
print(f"FAIL: Rejected valid function: {e}")
|
||||
raise
|
||||
|
||||
# Test 2: Valid callable (lambda)
|
||||
try:
|
||||
test.on_key = lambda k, a: None
|
||||
print("✓ Accepted valid lambda as key handler")
|
||||
print("OK: Accepted valid lambda as key handler")
|
||||
except Exception as e:
|
||||
print(f"✗ Rejected valid lambda: {e}")
|
||||
print(f"FAIL: Rejected valid lambda: {e}")
|
||||
raise
|
||||
|
||||
# Test 3: Invalid - string
|
||||
try:
|
||||
test.on_key = "not callable"
|
||||
print("✗ Should have rejected string as key handler")
|
||||
print("FAIL: Should have rejected string as key handler")
|
||||
except TypeError as e:
|
||||
print(f"✓ Correctly rejected string: {e}")
|
||||
print(f"OK: Correctly rejected string: {e}")
|
||||
except Exception as e:
|
||||
print(f"✗ Wrong exception type for string: {e}")
|
||||
print(f"FAIL: Wrong exception type for string: {e}")
|
||||
raise
|
||||
|
||||
# Test 4: Invalid - number
|
||||
try:
|
||||
test.on_key = 42
|
||||
print("✗ Should have rejected number as key handler")
|
||||
print("FAIL: Should have rejected number as key handler")
|
||||
except TypeError as e:
|
||||
print(f"✓ Correctly rejected number: {e}")
|
||||
print(f"OK: Correctly rejected number: {e}")
|
||||
except Exception as e:
|
||||
print(f"✗ Wrong exception type for number: {e}")
|
||||
print(f"FAIL: Wrong exception type for number: {e}")
|
||||
raise
|
||||
|
||||
# Test 5: Invalid - None
|
||||
# Test 5: None clears the callback (valid)
|
||||
try:
|
||||
test.on_key = None
|
||||
print("✗ Should have rejected None as key handler")
|
||||
except TypeError as e:
|
||||
print(f"✓ Correctly rejected None: {e}")
|
||||
assert test.on_key is None, "on_key should be None after clearing"
|
||||
print("OK: Accepted None to clear key handler")
|
||||
except Exception as e:
|
||||
print(f"✗ Wrong exception type for None: {e}")
|
||||
print(f"FAIL: Rejected None: {e}")
|
||||
raise
|
||||
|
||||
# Test 6: Invalid - dict
|
||||
try:
|
||||
test.on_key = {"not": "callable"}
|
||||
print("✗ Should have rejected dict as key handler")
|
||||
print("FAIL: Should have rejected dict as key handler")
|
||||
except TypeError as e:
|
||||
print(f"✓ Correctly rejected dict: {e}")
|
||||
print(f"OK: Correctly rejected dict: {e}")
|
||||
except Exception as e:
|
||||
print(f"✗ Wrong exception type for dict: {e}")
|
||||
print(f"FAIL: Wrong exception type for dict: {e}")
|
||||
raise
|
||||
|
||||
# Test 7: Valid callable class instance
|
||||
|
|
@ -80,14 +79,18 @@ def test_keypress_validation(timer, runtime):
|
|||
|
||||
try:
|
||||
test.on_key = KeyHandler()
|
||||
print("✓ Accepted valid callable class instance")
|
||||
print("OK: Accepted valid callable class instance")
|
||||
except Exception as e:
|
||||
print(f"✗ Rejected valid callable class: {e}")
|
||||
print(f"FAIL: Rejected valid callable class: {e}")
|
||||
raise
|
||||
|
||||
print("\n✅ keypressScene() validation test PASSED")
|
||||
print("\nPASS: keypressScene() validation test PASSED")
|
||||
sys.exit(0)
|
||||
|
||||
# Execute the test after a short delay
|
||||
import mcrfpy
|
||||
test_timer = mcrfpy.Timer("test", test_keypress_validation, 100, once=True)
|
||||
test_timer = mcrfpy.Timer("test", test_keypress_validation, 100, once=True)
|
||||
|
||||
# In headless mode, timers only fire via step()
|
||||
for _ in range(3):
|
||||
mcrfpy.step(0.05)
|
||||
Loading…
Add table
Add a link
Reference in a new issue