Improve test coverage wrt protocol versions; other fixes/improvements

Improvements to the test suite:
* List release version names and numbers in minecraft/__init__.py.
* Make some tests, which previously ran for *all* protocol versions,
  run only for release protocol versions (to improve test performance).
* Make some tests, which previously ran only for the latest protocol
  version, run for all release protocol versions (to improve coverage).
* Print each protocol version being tested to the debug log, to help
  identify sources of errors.
* Use the `nose-timer' plugin to show the run time of each test.

Fix errors revealed by increased test coverage:
* Fix: SoundEffectPacket.Pitch is not serialised correctly for early
  protocol versions.
* Fix: handleExceptionTest finishes later than necessary because
  the test overrode an exception handler used internally by
  `_FakeServerTest', causing the server thread to time out after 4s.
* Add support for multiple exception handlers in `Connection'
  (required for the above).

Improvements to data descriptors:
* Make syntax of property declarations more consistent/Pythonic.
* Factor the definition of several aliasing properties into the
  utility methods `attribute_alias' and `multi_attribute_alias',
  which construct suitable data descriptors.
* Define and use the named tuple `Direction' for (pitch, yaw) values.
This commit is contained in:
joodicator committed 2019-05-14 18:41:58 +02:00
1 parent 6ef868bc5b
commit 7b1567c352
12 files changed
+318 -157

No files matched your search

@@ -1,6 +1,7 @@
from minecraft.networking.packets import Packet
from minecraft.networking.types import (
VarInt, Integer, UnsignedByte, Position, Vector, MutableRecord
VarInt, Integer, UnsignedByte, Position, Vector, MutableRecord,
attribute_alias, multi_attribute_alias,
)
@@ -20,19 +21,25 @@ class BlockChangePacket(Packet):
block_state_id = 0
# For protocols < 347: an accessor for (block_state_id >> 4).
@property
def blockId(self):
return self.block_state_id >> 4
@blockId.setter
def blockId(self, block_id):
self.block_state_id = (self.block_state_id & 0xF) | (block_id << 4)
blockId = property(lambda self: self.block_state_id >> 4, blockId)
# For protocols < 347: an accessor for (block_state_id & 0xF).
@property
def blockMeta(self):
return self.block_state_id & 0xF
@blockMeta.setter
def blockMeta(self, meta):
self.block_state_id = (self.block_state_id & ~0xF) | (meta & 0xF)
blockMeta = property(lambda self: self.block_state_id & 0xF, blockMeta)
# This alias is retained for backward compatibility.
def blockStateId(self, block_state_id):
self.block_state_id = block_state_id
blockStateId = property(lambda self: self.block_state_id, blockStateId)
blockStateId = attribute_alias('block_state_id')
class MultiBlockChangePacket(Packet):
@@ -54,24 +61,28 @@ class MultiBlockChangePacket(Packet):
super(MultiBlockChangePacket.Record, self).__init__(**kwds)
# Access the 'x', 'y', 'z' fields as a Vector of ints.
def position(self, position):
self.x, self.y, self.z = position
position = property(lambda r: Vector(r.x, r.y, r.z), position)
position = multi_attribute_alias(Vector, 'x', 'y', 'z')
# For protocols < 347: an accessor for (block_state_id >> 4).
@property
def blockId(self):
return self.block_state_id >> 4
@blockId.setter
def blockId(self, block_id):
self.block_state_id = self.block_state_id & 0xF | block_id << 4
blockId = property(lambda r: r.block_state_id >> 4, blockId)
# For protocols < 347: an accessor for (block_state_id & 0xF).
@property
def blockMeta(self):
return self.block_state_id & 0xF
@blockMeta.setter
def blockMeta(self, meta):
self.block_state_id = self.block_state_id & ~0xF | meta & 0xF
blockMeta = property(lambda r: r.block_state_id & 0xF, blockMeta)
# This alias is retained for backward compatibility.
def blockStateId(self, block_state_id):
self.block_state_id = block_state_id
blockStateId = property(lambda r: r.block_state_id, blockStateId)
blockStateId = attribute_alias('block_state_id')
def read(self, file_object):
h_position = UnsignedByte.read(file_object)