class UDPSocketConnectionTest: def setup_method(self): socket = Mock() socket.recvfrom = Mock() socket.sendto = Mock() with patch("socket.socket") as create_socket: create_socket.return_value = socket self.connection = UDPSocketConnection(("localhost", 1234)) def test_flush(self): with pytest.raises(TypeError): self.connection.flush() def test_receive(self): with pytest.raises(TypeError): self.connection.receive("") def test_remaining(self): assert self.connection.remaining() == 65535 def test_read(self): self.connection.socket.recvfrom.return_value = [bytearray.fromhex("7FAA")] assert self.connection.read(2) == bytearray.fromhex("7FAA") def test_write(self): self.connection.write(bytearray.fromhex("7FAA")) self.connection.socket.sendto.assert_called_once_with(bytearray.fromhex("7FAA"), ("localhost", 1234))
class UDPSocketConnectionTest(TestCase): def setUp(self): socket = Mock() socket.recvfrom = Mock() socket.sendto = Mock() with patch("socket.socket") as create_socket: create_socket.return_value = socket self.connection = UDPSocketConnection(("localhost", 1234)) def test_flush(self): self.assertRaises(TypeError, self.connection.flush) def test_receive(self): self.assertRaises(TypeError, self.connection.receive, "") def test_remaining(self): self.assertEqual(self.connection.remaining(), 65535) def test_read(self): self.connection.socket.recvfrom.return_value = [bytearray.fromhex("7FAA")] self.assertEqual(self.connection.read(2), bytearray.fromhex("7FAA")) def test_write(self): self.connection.write(bytearray.fromhex("7FAA")) self.connection.socket.sendto.assert_called_once_with(bytearray.fromhex("7FAA"), ("localhost", 1234))
class UDPSocketConnectionTest(TestCase): def setUp(self): socket = Mock() socket.recvfrom = Mock() socket.sendto = Mock() with patch("socket.socket") as create_socket: create_socket.return_value = socket self.connection = UDPSocketConnection(("localhost", 1234)) def test_flush(self): self.assertRaises(TypeError, self.connection.flush) def test_receive(self): self.assertRaises(TypeError, self.connection.receive, "") def test_remaining(self): self.assertEqual(self.connection.remaining(), 65535) def test_read(self): self.connection.socket.recvfrom.return_value = [ bytearray.fromhex("7FAA") ] self.assertEqual(self.connection.read(2), bytearray.fromhex("7FAA")) def test_write(self): self.connection.write(bytearray.fromhex("7FAA")) self.connection.socket.sendto.assert_called_once_with( bytearray.fromhex("7FAA"), ("localhost", 1234))