-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vaughn Kottler
authored and
Vaughn Kottler
committed
Jun 11, 2024
1 parent
622dc50
commit 7c4e94b
Showing
10 changed files
with
118 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
major: 4 | ||
minor: 4 | ||
patch: 6 | ||
minor: 5 | ||
patch: 0 | ||
entry: runtimepy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
""" | ||
Test the 'net.tcp.scpi' module. | ||
""" | ||
|
||
# built-in | ||
import asyncio | ||
|
||
# third-party | ||
from pytest import mark | ||
|
||
# module under test | ||
from runtimepy.net.tcp import TcpConnection | ||
from runtimepy.net.tcp.scpi import ScpiConnection | ||
|
||
|
||
class MockScpiConnection(TcpConnection): | ||
"""A sample connection class.""" | ||
|
||
async def process_binary(self, data: bytes) -> bool: | ||
"""Process a binary frame.""" | ||
return await self.process_text(data.decode()) | ||
|
||
async def process_text(self, data: str) -> bool: | ||
"""Process a text frame.""" | ||
|
||
for item in data.splitlines(): | ||
match item: | ||
case "*IDN?": | ||
self.send_text("Mock,Device,1.0") | ||
case _: | ||
self.logger.error("Didn't handle message '%s'.", item) | ||
|
||
return True | ||
|
||
|
||
@mark.asyncio | ||
async def test_scpi_connection_basic(): | ||
"""Test basic interactions with a SCPI connection pair.""" | ||
|
||
async with ScpiConnection.create_pair(peer=MockScpiConnection) as ( | ||
server, | ||
client, | ||
): | ||
event = asyncio.Event() | ||
|
||
# Start connection processing. | ||
processes = [ | ||
asyncio.create_task(server.process(stop_sig=event)), | ||
asyncio.create_task(client.process(stop_sig=event)), | ||
] | ||
|
||
# Initialize client. | ||
await client.initialized.wait() | ||
|
||
# We don't expect a response. | ||
await client.send_command("asdf", query=True, log=True, timeout=0.01) | ||
|
||
# End test. | ||
event.set() | ||
await asyncio.gather(*processes) |