mirror of
https://github.com/ammaraskar/pyCraft.git
synced 2024-11-21 17:56:30 +01:00
Fix tests to work with new Angle type@
This commit is contained in:
parent
22008c5c5c
commit
93f6d269da
@ -4,8 +4,7 @@ from minecraft.networking.packets import (
|
||||
|
||||
from minecraft.networking.types import (
|
||||
Integer, FixedPointInteger, UnsignedByte, Byte, Boolean, UUID, Short,
|
||||
VarInt, Double, Float, String, Enum, Difficulty, Dimension, GameMode,
|
||||
Angle
|
||||
VarInt, Double, Float, String, Enum, Difficulty, Dimension, GameMode, Angle
|
||||
)
|
||||
|
||||
from .combat_event_packet import CombatEventPacket
|
||||
|
@ -127,7 +127,7 @@ class Angle(Type):
|
||||
@staticmethod
|
||||
def send(value, socket):
|
||||
# Normalize angle between 0 and 255 and convert to int.
|
||||
UnsignedByte.send(int(255 * (value / 360)), socket)
|
||||
UnsignedByte.send(round(255 * (value / 360)), socket)
|
||||
|
||||
|
||||
class VarInt(Type):
|
||||
|
@ -201,7 +201,7 @@ class TestReadWritePackets(unittest.TestCase):
|
||||
pos_look = PositionAndLook(
|
||||
position=(Vector(68.0, 38.0, 76.0) if context.protocol_version
|
||||
>= 100 else Vector(68, 38, 76)),
|
||||
yaw=16, pitch=23)
|
||||
yaw=263.494, pitch=180)
|
||||
velocity = Vector(21, 55, 41)
|
||||
entity_id, type_name, type_id = 49846, 'EGG', EntityType.EGG
|
||||
|
||||
@ -235,8 +235,10 @@ class TestReadWritePackets(unittest.TestCase):
|
||||
packet2.data = 0
|
||||
if context.protocol_version < 49:
|
||||
del packet2.velocity
|
||||
self._test_read_write_packet(packet, context)
|
||||
self._test_read_write_packet(packet2, context)
|
||||
self._test_read_write_packet(packet, context,
|
||||
yaw=360/255, pitch=360/255)
|
||||
self._test_read_write_packet(packet2, context,
|
||||
yaw=360/255, pitch=360/255)
|
||||
|
||||
def test_sound_effect_packet(self):
|
||||
for protocol_version in TEST_VERSIONS:
|
||||
@ -254,7 +256,12 @@ class TestReadWritePackets(unittest.TestCase):
|
||||
clientbound.play.SoundEffectPacket.SoundCategory.NEUTRAL
|
||||
self._test_read_write_packet(packet, context)
|
||||
|
||||
def _test_read_write_packet(self, packet_in, context=None):
|
||||
def _test_read_write_packet(self, packet_in, context=None, **kwargs):
|
||||
"""
|
||||
If kwargs are specified, the key will be tested against the
|
||||
respective delta value. Useful for testing FixedPointNumbers
|
||||
where there is precision lost in the resulting value.
|
||||
"""
|
||||
if context is None:
|
||||
for protocol_version in TEST_VERSIONS:
|
||||
logging.debug('protocol_version = %r' % protocol_version)
|
||||
@ -272,4 +279,12 @@ class TestReadWritePackets(unittest.TestCase):
|
||||
packet_out = type(packet_in)(context=context)
|
||||
packet_out.read(packet_buffer)
|
||||
self.assertIs(type(packet_in), type(packet_out))
|
||||
|
||||
for packet_attr, precision in kwargs.items():
|
||||
packet_attribute_in = packet_in.__dict__.pop(packet_attr)
|
||||
packet_attribute_out = packet_out.__dict__.pop(packet_attr)
|
||||
self.assertAlmostEqual(packet_attribute_in,
|
||||
packet_attribute_out,
|
||||
delta=precision)
|
||||
|
||||
self.assertEqual(packet_in.__dict__, packet_out.__dict__)
|
||||
|
@ -60,7 +60,8 @@ class SerializationTest(unittest.TestCase):
|
||||
self.assertAlmostEqual(
|
||||
test_data, deserialized, delta=1.0/32.0)
|
||||
elif data_type is Angle:
|
||||
self.assertAlmostEqual(test_data, deserialized, delta=360/255)
|
||||
self.assertAlmostEqual(test_data, deserialized,
|
||||
delta=360/255)
|
||||
elif data_type is Float or data_type is Double:
|
||||
self.assertAlmostEquals(test_data, deserialized, 3)
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user