39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
import unittest
|
|
|
|
from munch import Munch
|
|
from minecraft.networking.modern import ClientTickEnd
|
|
|
|
from mosfet.game import Game
|
|
from mosfet.protocol.modern import PlayerCommandPacket
|
|
|
|
|
|
class FakeConnection:
|
|
def __init__(self):
|
|
self.packets = []
|
|
|
|
def write_packet(self, packet, force=False):
|
|
self.packets.append((packet, force))
|
|
|
|
|
|
class SprintControlTests(unittest.TestCase):
|
|
def test_start_and_stop_sprint_are_sent_once_each(self):
|
|
connection = FakeConnection()
|
|
game = Game.__new__(Game)
|
|
game.g = Munch(connection=connection, eid=23, sprinting=False)
|
|
|
|
self.assertTrue(game.set_sprinting(True))
|
|
self.assertFalse(game.set_sprinting(True))
|
|
self.assertTrue(game.set_sprinting(False))
|
|
|
|
commands = [packet for packet, _force in connection.packets
|
|
if isinstance(packet, PlayerCommandPacket)]
|
|
self.assertEqual([packet.action_id for packet in commands], [1, 2])
|
|
self.assertTrue(all(packet.entity_id == 23 for packet in commands))
|
|
self.assertTrue(all(isinstance(packet, ClientTickEnd)
|
|
for packet, _force in connection.packets[1::2]))
|
|
self.assertFalse(game.g.sprinting)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|