Fix: 1.16.5 is erroneously marked as unsupported
[pyCraft.git] / tests / test_backward_compatible.py
blobd929eac2f12ec6cc838a54700b01fda28861279d
1 import unittest
3 from minecraft import SUPPORTED_PROTOCOL_VERSIONS
4 from minecraft import utility
5 from minecraft.networking.connection import ConnectionContext
6 from minecraft.networking import packets
7 from minecraft.networking import types
8 from minecraft.networking.packets import clientbound
9 from minecraft.networking.packets import serverbound
12 class LegacyPacketNamesTest(unittest.TestCase):
13 def test_legacy_packets_equal_current_packets(self):
14 self.assertEqual(packets.KeepAlivePacket,
15 packets.AbstractKeepAlivePacket)
17 self.assertEqual(packets.state_handshake_clientbound,
18 clientbound.handshake.get_packets)
19 self.assertEqual(packets.HandShakePacket,
20 serverbound.handshake.HandShakePacket)
21 self.assertEqual(packets.state_handshake_serverbound,
22 serverbound.handshake.get_packets)
24 self.assertEqual(packets.ResponsePacket,
25 clientbound.status.ResponsePacket)
26 self.assertEqual(packets.PingPacketResponse,
27 clientbound.status.PingResponsePacket)
28 self.assertEqual(packets.state_status_clientbound,
29 clientbound.status.get_packets)
30 self.assertEqual(packets.RequestPacket,
31 serverbound.status.RequestPacket)
32 self.assertEqual(packets.PingPacket,
33 serverbound.status.PingPacket)
34 self.assertEqual(packets.state_status_serverbound,
35 serverbound.status.get_packets)
37 self.assertEqual(packets.DisconnectPacket,
38 clientbound.login.DisconnectPacket)
39 self.assertEqual(packets.EncryptionRequestPacket,
40 clientbound.login.EncryptionRequestPacket)
41 self.assertEqual(packets.LoginSuccessPacket,
42 clientbound.login.LoginSuccessPacket)
43 self.assertEqual(packets.SetCompressionPacket,
44 clientbound.login.SetCompressionPacket)
45 self.assertEqual(packets.state_login_clientbound,
46 clientbound.login.get_packets)
47 self.assertEqual(packets.LoginStartPacket,
48 serverbound.login.LoginStartPacket)
49 self.assertEqual(packets.EncryptionResponsePacket,
50 serverbound.login.EncryptionResponsePacket)
51 self.assertEqual(packets.state_login_serverbound,
52 serverbound.login.get_packets)
54 self.assertEqual(packets.KeepAlivePacketClientbound,
55 clientbound.play.KeepAlivePacket)
56 self.assertEqual(packets.KeepAlivePacketServerbound,
57 serverbound.play.KeepAlivePacket)
58 self.assertEqual(packets.JoinGamePacket,
59 clientbound.play.JoinGamePacket)
60 self.assertEqual(packets.ChatMessagePacket,
61 clientbound.play.ChatMessagePacket)
62 self.assertEqual(packets.PlayerPositionAndLookPacket,
63 clientbound.play.PlayerPositionAndLookPacket)
64 self.assertEqual(packets.DisconnectPacketPlayState,
65 clientbound.play.DisconnectPacket)
66 self.assertEqual(packets.SetCompressionPacketPlayState,
67 clientbound.play.SetCompressionPacket)
68 self.assertEqual(packets.PlayerListItemPacket,
69 clientbound.play.PlayerListItemPacket)
70 self.assertEqual(packets.MapPacket,
71 clientbound.play.MapPacket)
72 self.assertEqual(packets.state_playing_clientbound,
73 clientbound.play.get_packets)
74 self.assertEqual(packets.ChatPacket,
75 serverbound.play.ChatPacket)
76 self.assertEqual(packets.PositionAndLookPacket,
77 serverbound.play.PositionAndLookPacket)
78 self.assertEqual(packets.TeleportConfirmPacket,
79 serverbound.play.TeleportConfirmPacket)
80 self.assertEqual(packets.AnimationPacketServerbound,
81 serverbound.play.AnimationPacket)
82 self.assertEqual(packets.state_playing_serverbound,
83 serverbound.play.get_packets)
86 class LegacyTypesTest(unittest.TestCase):
87 def test_legacy_types(self):
88 self.assertIsInstance(types.FixedPointInteger, types.FixedPoint)
89 self.assertEqual(types.FixedPointInteger.denominator, 32)
91 for attr in ('descriptor', 'overridable_descriptor',
92 'overridable_property', 'attribute_alias',
93 'multi_attribute_alias', 'attribute_transform',
94 'class_and_instancemethod'):
95 self.assertEqual(getattr(types, attr), getattr(utility, attr))
98 class ClassMemberAliasesTest(unittest.TestCase):
99 def test_alias_values(self):
100 self.assertEqual(serverbound.play.AnimationPacket.HAND_MAIN,
101 types.RelativeHand.MAIN)
102 self.assertEqual(serverbound.play.AnimationPacket.HAND_OFF,
103 types.RelativeHand.OFF)
105 self.assertEqual(serverbound.play.ClientSettingsPacket.Hand.LEFT,
106 types.AbsoluteHand.LEFT)
107 self.assertEqual(serverbound.play.ClientSettingsPacket.Hand.RIGHT,
108 types.AbsoluteHand.RIGHT)
110 def test_block_change_packet(self):
111 context = ConnectionContext()
112 context.protocol_version = SUPPORTED_PROTOCOL_VERSIONS[-1]
113 bi, bm = 358, 9
114 packet = clientbound.play.BlockChangePacket(blockId=bi, blockMeta=bm)
115 self.assertEqual((packet.blockId, packet.blockMeta), (bi, bm))
116 self.assertEqual(packet.blockStateId, packet.block_state_id)
118 def test_join_game_packet(self):
119 GameMode = types.GameMode
120 context = ConnectionContext()
121 for pure_game_mode in (GameMode.SURVIVAL, GameMode.CREATIVE,
122 GameMode.ADVENTURE, GameMode.SPECTATOR):
123 for is_hardcore in (False, True):
124 context.protocol_version = 70
125 game_mode = \
126 pure_game_mode | GameMode.HARDCORE \
127 if is_hardcore else pure_game_mode
129 packet = clientbound.play.JoinGamePacket()
130 packet.game_mode = game_mode
131 packet.context = context
132 self.assertEqual(packet.pure_game_mode, pure_game_mode)
133 self.assertEqual(packet.is_hardcore, is_hardcore)
135 del packet.context
136 del packet.is_hardcore
137 packet.context = context
138 self.assertEqual(packet.game_mode, packet.pure_game_mode)
140 del packet.context
141 del packet.game_mode
142 packet.context = context
143 self.assertFalse(hasattr(packet, 'is_hardcore'))
145 packet = clientbound.play.JoinGamePacket()
146 packet.pure_game_mode = game_mode
147 packet.is_hardcore = is_hardcore
148 packet.context = context
149 self.assertEqual(packet.game_mode, game_mode)
151 context.protocol_version = 738
152 game_mode = pure_game_mode | GameMode.HARDCORE
154 packet = clientbound.play.JoinGamePacket()
155 packet.game_mode = game_mode
156 packet.is_hardcore = is_hardcore
157 packet.context = context
158 self.assertEqual(packet.game_mode, game_mode)
159 self.assertEqual(packet.pure_game_mode, game_mode)
160 self.assertEqual(packet.is_hardcore, is_hardcore)
162 del packet.context
163 packet.is_hardcore = is_hardcore
164 packet.context = context
165 self.assertEqual(packet.game_mode, game_mode)
166 self.assertEqual(packet.pure_game_mode, game_mode)
168 with self.assertRaises(AttributeError):
169 del packet.pure_game_mode
171 def test_entity_position_delta_packet(self):
172 packet = clientbound.play.EntityPositionDeltaPacket()
173 packet.delta_x = -32768
174 packet.delta_y = 33
175 packet.delta_z = 32767
176 self.assertEqual(packet.delta_x_float, -8.0)
177 self.assertEqual(packet.delta_y_float, 0.008056640625)
178 self.assertEqual(packet.delta_z_float, 7.999755859375)
179 self.assertEqual(packet.delta_x, -32768)
180 self.assertEqual(packet.delta_y, 33)
181 self.assertEqual(packet.delta_z, 32767)