Commit 421a2a55 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Rename the client method send_message to send_command

parent 6ccb4d11
Loading
Loading
Loading
Loading
+14 −14
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ from wpa_supplicant.client import base


@mock.patch('wpa_supplicant.util.connect_unix_datagram', new_callable=anyio_mock.AsyncMock)
@mock.patch('wpa_supplicant.client.base.BaseClient.send_message', new_callable=anyio_mock.AsyncMock)
@mock.patch('wpa_supplicant.client.base.BaseClient.send_command', new_callable=anyio_mock.AsyncMock)
class ConnectTests(unittest.TestCase):
	"""
	Tests for the connect() method
@@ -69,7 +69,7 @@ class ConnectTests(unittest.TestCase):

class SendMessageTests(unittest.TestCase):
	"""
	Tests for the send_message() method
	Tests for the send_command() method
	"""

	def setUp(self):
@@ -86,7 +86,7 @@ class SendMessageTests(unittest.TestCase):
		"""
		async with self.client as client:
			client.sock.recv.return_value = b"OK"
			assert await client.send_message("SOME_COMMAND") is None
			assert await client.send_command("SOME_COMMAND") is None

	@anyio_mock.with_anyio()
	async def test_simple_expect(self):
@@ -95,7 +95,7 @@ class SendMessageTests(unittest.TestCase):
		"""
		async with self.client as client:
			client.sock.recv.return_value = b"PONG"
			assert await client.send_message("PING", expect="PONG") is None
			assert await client.send_command("PING", expect="PONG") is None

	@anyio_mock.with_anyio()
	async def test_simple_no_expect(self):
@@ -105,9 +105,9 @@ class SendMessageTests(unittest.TestCase):
		async with self.client as client:
			client.sock.recv.return_value = b"DING"
			with self.assertRaises(errors.UnexpectedResponseError):
				await client.send_message("PING")
				await client.send_command("PING")
			with self.assertRaises(errors.UnexpectedResponseError):
				await client.send_message("PING", expect="PONG")
				await client.send_command("PING", expect="PONG")

	@anyio_mock.with_anyio()
	async def test_simple_convert(self):
@@ -117,7 +117,7 @@ class SendMessageTests(unittest.TestCase):
		async with self.client as client:
			client.sock.recv.return_value = b"FOO\nBAR\nBAZ\n"
			self.assertListEqual(
				await client.send_message(
				await client.send_command(
					"SOME_COMMAND",
					convert=lambda x: x.splitlines(),
				),
@@ -132,7 +132,7 @@ class SendMessageTests(unittest.TestCase):
		async with self.client as client:
			client.sock.recv.return_value = b"FOO\nBAR\nBAZ\n"
			self.assertListEqual(
				await client.send_message(
				await client.send_command(
					"SOME_COMMAND",
					convert=lambda x: x.splitlines(),
					expect="PONG",
@@ -148,7 +148,7 @@ class SendMessageTests(unittest.TestCase):
		async with self.client as client:
			client.sock.recv.return_value = b"FAIL"
			with self.assertRaises(errors.CommandFailed):
				await client.send_message("SOME_COMMAND")
				await client.send_command("SOME_COMMAND")

	@anyio_mock.with_anyio()
	async def test_simple_bad_command(self):
@@ -158,7 +158,7 @@ class SendMessageTests(unittest.TestCase):
		async with self.client as client:
			client.sock.recv.return_value = b"UNKNOWN COMMAND"
			with self.assertRaises(ValueError):
				await client.send_message("SOME_COMMAND")
				await client.send_command("SOME_COMMAND")

	@anyio_mock.with_anyio()
	async def test_simple_too_large(self):
@@ -168,7 +168,7 @@ class SendMessageTests(unittest.TestCase):
		async with self.client as client:
			client.sock.send.side_effect = lambda b: len(b) / 2
			with self.assertRaises(errors.MessageTooLargeError):
				await client.send_message("SOME_COMMAND")
				await client.send_command("SOME_COMMAND")

	@anyio_mock.with_anyio()
	async def test_interleaved(self):
@@ -182,7 +182,7 @@ class SendMessageTests(unittest.TestCase):
				b"OK",
				b"<2>SOME-MESSAGE"
			]
			assert await client.send_message("SOME_COMMAND") is None
			assert await client.send_command("SOME_COMMAND") is None


class EventTests(unittest.TestCase):
@@ -269,11 +269,11 @@ class EventTests(unittest.TestCase):
				b"FOO",
			]

			assert await client.send_message("SOME_COMMAND") is None
			assert await client.send_command("SOME_COMMAND") is None

			prio, evt, args = await client.event("EXAMPLE-EVENT")
			assert prio == 4
			assert evt == "EXAMPLE-EVENT"
			assert args is None

			assert await client.send_message("SOME_COMMAND", expect="FOO") is None
			assert await client.send_command("SOME_COMMAND", expect="FOO") is None
+4 −4
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@ class BaseClient:

		async with anyio.fail_after(1):
			self.sock = await util.connect_unix_datagram(path.as_posix())
			await self.send_message(consts.COMMAND_PING, expect=consts.RESPONSE_PONG)
			await self.send_command(consts.COMMAND_PING, expect=consts.RESPONSE_PONG)

	async def disconnect(self):
		"""
@@ -104,7 +104,7 @@ class BaseClient:
		if self.sock:
			await self.sock.close()

	async def send_message(self,
	async def send_command(self,
			message: str,
			*args: str,
			seperator: str = '\t',
@@ -226,7 +226,7 @@ class BaseClient:
			client = self.client
			assert client._eventcount >= 0
			if client._eventcount == 0:
				await client.send_message(consts.COMMAND_ATTACH)
				await client.send_command(consts.COMMAND_ATTACH)
			client._eventcount += 1

		async def __aexit__(self, *exc_info):
@@ -237,7 +237,7 @@ class BaseClient:
				if __debug__: # On it's own for compiler optimisation
					if exc_info[0]:
						client.logger.debug(f"Detaching due to {exc_info[0].__name__}")
				await client.send_message(consts.COMMAND_DETACH)
				await client.send_command(consts.COMMAND_DETACH)


class ReplyManager:
+1 −1
Original line number Diff line number Diff line
@@ -29,4 +29,4 @@ class InterfaceClient(BaseClient):

	async def connect(self, path: consts.Path):
		await super().connect(path)
		self.name = await self.send_message(consts.COMMAND_IFNAME, convert=str)
		self.name = await self.send_command(consts.COMMAND_IFNAME, convert=str)
+3 −3
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ class MasterClient(BaseClient):
		"""
		Return a set of the interfaces currently managed by the daemon
		"""
		return await self.send_message(
		return await self.send_command(
			consts.COMMAND_INTERFACES,
			convert=lambda x: x.splitlines(),
		)
@@ -51,7 +51,7 @@ class MasterClient(BaseClient):
		Add a network interface to the daemon's control interfaces
		"""
		ctrl_iface = f"DIR={self.ctrl_dir} GROUP={self.ctrl_dir.group()}"
		await self.send_message(
		await self.send_command(
			consts.COMMAND_INTERFACE_ADD,
			ifname, '', driver, ctrl_iface, driver_param,
		)
@@ -60,7 +60,7 @@ class MasterClient(BaseClient):
		"""
		Remove a network interface from the daemon's control
		"""
		await self.send_message(consts.COMMAND_INTERFACE_REMOVE, ifname)
		await self.send_command(consts.COMMAND_INTERFACE_REMOVE, ifname)

	async def connect_interface(self, ifname: str) -> InterfaceClient:
		"""