mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-29 08:15:18 -04:00
tests: more improvements to test suite coverage
This commit is contained in:
parent
98c82ddb9c
commit
ba010168cf
@ -1,8 +1,12 @@
|
||||
from panda3d.core import BitArray
|
||||
from panda3d.core import BitArray, SparseArray
|
||||
import pickle
|
||||
import pytest
|
||||
|
||||
|
||||
def test_bitarray_type():
|
||||
assert BitArray.get_class_type().name == "BitArray"
|
||||
|
||||
|
||||
def test_bitarray_constructor():
|
||||
assert BitArray().is_zero()
|
||||
assert BitArray(0).is_zero()
|
||||
@ -18,8 +22,31 @@ def test_bitarray_constructor():
|
||||
assert BitArray(-10000000000000000000)
|
||||
|
||||
|
||||
def test_bitarray_constructor_sparse():
|
||||
# Create a BitArray from a SparseArray.
|
||||
ba = BitArray(SparseArray.all_on())
|
||||
assert ba.is_all_on()
|
||||
|
||||
ba = BitArray(SparseArray())
|
||||
assert ba.is_zero()
|
||||
|
||||
sa = SparseArray()
|
||||
sa.set_range(3, 64)
|
||||
sa.set_range(0, 1)
|
||||
sa.clear_range(60, 2)
|
||||
ba = BitArray(sa)
|
||||
exp = 0b1111100111111111111111111111111111111111111111111111111111111111001
|
||||
assert ba.__getstate__() == exp
|
||||
|
||||
sa.invert_in_place()
|
||||
ba = BitArray(sa)
|
||||
assert ba.__getstate__() == ~exp
|
||||
|
||||
|
||||
def test_bitarray_allon():
|
||||
assert BitArray.all_on().is_all_on()
|
||||
assert BitArray.all_on().get_highest_on_bit() == -1
|
||||
assert BitArray.all_on().get_highest_off_bit() == -1
|
||||
|
||||
|
||||
def test_bitarray_nonzero():
|
||||
@ -36,6 +63,41 @@ def test_bitarray_invert():
|
||||
assert ~~BitArray(123) == BitArray(123)
|
||||
|
||||
|
||||
def test_bitarray_set_word():
|
||||
# Non-inverted
|
||||
expected = 9876 | (123456 << (BitArray.num_bits_per_word * 3))
|
||||
ba = BitArray(0)
|
||||
ba.set_word(0, 9876)
|
||||
ba.set_word(3, 123456)
|
||||
assert ba.__getstate__() == expected
|
||||
assert not ba.is_all_on()
|
||||
|
||||
# Inverted
|
||||
ba = BitArray(0)
|
||||
ba.invert_in_place()
|
||||
ba.set_word(2, 1234)
|
||||
full_word = (1 << BitArray.num_bits_per_word) - 1
|
||||
expected = ~((full_word & ~1234) << (BitArray.num_bits_per_word * 2))
|
||||
assert ba.__getstate__() == expected
|
||||
assert not ba.is_all_on()
|
||||
|
||||
|
||||
def test_bitarray_clear():
|
||||
ba = BitArray(1234)
|
||||
ba.clear()
|
||||
assert ba.is_zero()
|
||||
assert not ba.is_all_on()
|
||||
assert ba.get_highest_on_bit() == -1
|
||||
assert ba.get_highest_off_bit() == -1
|
||||
|
||||
ba = BitArray.all_on()
|
||||
ba.clear()
|
||||
assert ba.is_zero()
|
||||
assert not ba.is_all_on()
|
||||
assert ba.get_highest_on_bit() == -1
|
||||
assert ba.get_highest_off_bit() == -1
|
||||
|
||||
|
||||
def test_bitarray_getstate():
|
||||
assert BitArray().__getstate__() == 0
|
||||
assert BitArray(0).__getstate__() == 0
|
||||
|
@ -8,6 +8,10 @@ double_num_bits = DoubleBitMaskNative.get_max_num_bits()
|
||||
quad_num_bits = QuadBitMaskNative.get_max_num_bits()
|
||||
|
||||
|
||||
def test_bitmask_type():
|
||||
assert BitMask16.get_class_type().name == "BitMask16"
|
||||
|
||||
|
||||
def test_bitmask_allon():
|
||||
assert BitMask16.all_on().is_all_on()
|
||||
assert BitMask32.all_on().is_all_on()
|
||||
@ -34,6 +38,13 @@ def test_bitmask_overflow():
|
||||
with pytest.raises(OverflowError):
|
||||
QuadBitMaskNative(1 << quad_num_bits)
|
||||
|
||||
with pytest.raises(Exception):
|
||||
DoubleBitMaskNative(-1)
|
||||
|
||||
|
||||
def test_bitmask_repr():
|
||||
repr(BitMask16(0)) == ' 0000 0000 0000 0000'
|
||||
|
||||
|
||||
def test_bitmask_int():
|
||||
assert int(BitMask16()) == 0
|
||||
@ -68,3 +79,10 @@ def test_bitmask_pickle():
|
||||
data = pickle.dumps(mask1, -1)
|
||||
mask2 = pickle.loads(data)
|
||||
assert mask1 == mask2
|
||||
|
||||
assert pickle.loads(pickle.dumps(DoubleBitMaskNative(0), -1)).is_zero()
|
||||
|
||||
mask1 = DoubleBitMaskNative(0xffff0001)
|
||||
data = pickle.dumps(mask1, -1)
|
||||
mask2 = pickle.loads(data)
|
||||
assert mask1 == mask2
|
||||
|
64
tests/putil/test_buttonhandle.py
Normal file
64
tests/putil/test_buttonhandle.py
Normal file
@ -0,0 +1,64 @@
|
||||
from panda3d.core import ButtonHandle
|
||||
from panda3d.core import GamepadButton
|
||||
from panda3d.core import KeyboardButton
|
||||
from panda3d.core import MouseButton
|
||||
|
||||
|
||||
def test_buttonhandle_type():
|
||||
assert ButtonHandle.get_class_type().name == "ButtonHandle"
|
||||
|
||||
|
||||
def test_buttonhandle_none():
|
||||
none = ButtonHandle.none()
|
||||
assert none.index == 0
|
||||
assert none.name == "none"
|
||||
assert none == ButtonHandle.none()
|
||||
assert none.alias == none
|
||||
assert repr(none) == "none"
|
||||
assert str(none) == "none"
|
||||
|
||||
|
||||
def test_gamepadbutton_joystick():
|
||||
# The first one is called "trigger"
|
||||
assert GamepadButton.trigger() == GamepadButton.joystick(0)
|
||||
assert GamepadButton.joystick(0).name == "trigger"
|
||||
|
||||
for i in range(1, 8):
|
||||
btn = GamepadButton.joystick(i)
|
||||
assert btn.name == "joystick" + str(i + 1)
|
||||
|
||||
|
||||
def test_keyboardbutton_ascii():
|
||||
assert KeyboardButton.space() == KeyboardButton.ascii_key(' ')
|
||||
assert KeyboardButton.backspace() == KeyboardButton.ascii_key('\x08')
|
||||
assert KeyboardButton.tab() == KeyboardButton.ascii_key('\x09')
|
||||
assert KeyboardButton.enter() == KeyboardButton.ascii_key('\x0d')
|
||||
assert KeyboardButton.escape() == KeyboardButton.ascii_key('\x1b')
|
||||
|
||||
assert KeyboardButton.ascii_key(' ').name == 'space'
|
||||
assert KeyboardButton.ascii_key('\x08').name == 'backspace'
|
||||
assert KeyboardButton.ascii_key('\x09').name == 'tab'
|
||||
assert KeyboardButton.ascii_key('\x0d').name == 'enter'
|
||||
assert KeyboardButton.ascii_key('\x1b').name == 'escape'
|
||||
assert KeyboardButton.ascii_key('\x7f').name == 'delete'
|
||||
|
||||
assert KeyboardButton.ascii_key('a').name == 'a'
|
||||
|
||||
|
||||
def test_mousebutton():
|
||||
btns = [MouseButton.one(),
|
||||
MouseButton.two(),
|
||||
MouseButton.three(),
|
||||
MouseButton.four(),
|
||||
MouseButton.five()]
|
||||
|
||||
for i, btn in enumerate(btns):
|
||||
assert MouseButton.button(i) == btn
|
||||
assert MouseButton.is_mouse_button(btn)
|
||||
|
||||
assert MouseButton.button(5) == ButtonHandle.none()
|
||||
|
||||
assert MouseButton.is_mouse_button(MouseButton.wheel_up())
|
||||
assert MouseButton.is_mouse_button(MouseButton.wheel_down())
|
||||
assert MouseButton.is_mouse_button(MouseButton.wheel_left())
|
||||
assert MouseButton.is_mouse_button(MouseButton.wheel_right())
|
@ -1,23 +1,34 @@
|
||||
import time
|
||||
|
||||
def test_get_frame_time(clockobj):
|
||||
|
||||
def test_clock_get_frame_time(clockobj):
|
||||
current_time = clockobj.get_frame_time()
|
||||
time.sleep(2)
|
||||
time.sleep(0.2)
|
||||
assert clockobj.get_frame_time() == current_time
|
||||
|
||||
def test_jump_frame_time(clockobj):
|
||||
|
||||
def test_clock_jump_frame_time(clockobj):
|
||||
current_time = clockobj.get_frame_time()
|
||||
clockobj.tick()
|
||||
assert clockobj.get_frame_time() == current_time + clockobj.get_frame_time()
|
||||
|
||||
def test_get_real_time(clockobj):
|
||||
|
||||
def test_clock_get_real_time(clockobj):
|
||||
current_time = clockobj.get_real_time()
|
||||
time.sleep(2)
|
||||
time.sleep(0.2)
|
||||
assert current_time != clockobj.get_real_time()
|
||||
|
||||
def test_get_dt(clockobj):
|
||||
|
||||
def test_clock_get_dt(clockobj):
|
||||
clockobj.tick()
|
||||
first_tick = clockobj.get_frame_time()
|
||||
clockobj.tick()
|
||||
second_tick = clockobj.get_frame_time()
|
||||
assert clockobj.get_dt() == second_tick - first_tick
|
||||
|
||||
|
||||
def test_clock_reset(clockobj):
|
||||
clockobj.reset()
|
||||
assert clockobj.get_dt() == 0
|
||||
assert clockobj.get_frame_time() == 0
|
||||
assert clockobj.get_real_time() < 0.01
|
||||
|
@ -111,6 +111,17 @@ def test_datagram_pickle():
|
||||
assert pickle.loads(pickle.dumps(dg, -1)) == dg
|
||||
|
||||
|
||||
def test_datagram_cow():
|
||||
dg1 = core.Datagram()
|
||||
dg1.append_data(b'1234')
|
||||
|
||||
dg2 = core.Datagram(dg1)
|
||||
dg2.append_data(b'5678')
|
||||
|
||||
assert dg1.get_message() == b'1234'
|
||||
assert dg2.get_message() == b'12345678'
|
||||
|
||||
|
||||
def test_iterator(datagram_small):
|
||||
"""This tests Datagram/DatagramIterator, and sort of serves as a self-check
|
||||
of the test fixtures too."""
|
||||
|
@ -33,3 +33,53 @@ def test_modifierbuttons_cow():
|
||||
btns3.add_button("escape")
|
||||
assert tuple(btns2.buttons) == ("space",)
|
||||
assert tuple(btns3.buttons) == ("space", "escape")
|
||||
|
||||
|
||||
def test_modifierbuttons_assign():
|
||||
# Tests assignment operator.
|
||||
btns1 = ModifierButtons()
|
||||
btns1.add_button("space")
|
||||
|
||||
btns2 = ModifierButtons()
|
||||
btns2.assign(btns1)
|
||||
|
||||
assert btns1 == btns2
|
||||
assert tuple(btns1.buttons) == tuple(btns2.buttons)
|
||||
|
||||
|
||||
def test_modifierbuttons_state():
|
||||
btns = ModifierButtons()
|
||||
btns.add_button("alt")
|
||||
btns.add_button("shift")
|
||||
btns.add_button("control")
|
||||
assert not btns.is_any_down()
|
||||
|
||||
# Not tracked
|
||||
btns.button_down("enter")
|
||||
assert not btns.is_any_down()
|
||||
|
||||
# Tracked
|
||||
btns.button_down("shift")
|
||||
assert btns.is_any_down()
|
||||
assert not btns.is_down(0)
|
||||
assert btns.is_down(1)
|
||||
assert not btns.is_down(2)
|
||||
|
||||
btns.button_up("shift")
|
||||
assert not btns.is_any_down()
|
||||
assert not btns.is_down(0)
|
||||
assert not btns.is_down(1)
|
||||
assert not btns.is_down(2)
|
||||
|
||||
btns.button_down("alt")
|
||||
btns.button_down("shift")
|
||||
assert btns.is_any_down()
|
||||
assert btns.is_down(0)
|
||||
assert btns.is_down(1)
|
||||
assert not btns.is_down(2)
|
||||
|
||||
btns.all_buttons_up()
|
||||
assert not btns.is_any_down()
|
||||
assert not btns.is_down(0)
|
||||
assert not btns.is_down(1)
|
||||
assert not btns.is_down(2)
|
||||
|
@ -2,6 +2,10 @@ from panda3d import core
|
||||
import pickle
|
||||
|
||||
|
||||
def test_sparse_array_type():
|
||||
assert core.SparseArray.get_class_type().name == "SparseArray"
|
||||
|
||||
|
||||
def test_sparse_array_set_bit_to():
|
||||
"""Tests SparseArray behavior for set_bit_to()."""
|
||||
|
||||
|
@ -103,3 +103,10 @@ def test_updateseq_old():
|
||||
assert not (seq != old)
|
||||
assert not (seq > old)
|
||||
assert not (seq < old)
|
||||
|
||||
|
||||
def test_updateseq_clear():
|
||||
seq = UpdateSeq(UpdateSeq.fresh())
|
||||
seq.clear()
|
||||
assert seq == UpdateSeq.initial()
|
||||
assert seq.is_initial()
|
||||
|
21
tests/showbase/test_ShowBase.py
Normal file
21
tests/showbase/test_ShowBase.py
Normal file
@ -0,0 +1,21 @@
|
||||
from direct.showbase.ShowBase import ShowBase
|
||||
import sys
|
||||
|
||||
if sys.version_info >= (3, 0):
|
||||
import builtins
|
||||
else:
|
||||
import __builtin__ as builtins
|
||||
|
||||
|
||||
def test_showbase_create_destroy():
|
||||
sb = ShowBase(windowType='none')
|
||||
try:
|
||||
assert builtins.base == sb
|
||||
finally:
|
||||
sb.destroy()
|
||||
sb = None
|
||||
|
||||
assert not hasattr(builtins, 'base')
|
||||
assert not hasattr(builtins, 'run')
|
||||
assert not hasattr(builtins, 'loader')
|
||||
assert not hasattr(builtins, 'taskMgr')
|
Loading…
x
Reference in New Issue
Block a user