Skip to content

Aligning with asyncio recommendations in test #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions tests/test_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,29 @@ async def test_eventworker() -> None:
transport = mock.Mock()
transport.write = mock.Mock()
transport.is_closing = mock.Mock()
protocol._drain_helper = make_mocked_coro()

loop = asyncio.get_event_loop()
writer = asyncio.StreamWriter(transport, protocol, None, loop)

worker: pytak.Worker = pytak.TXWorker(event_queue, {}, writer)

await worker.run_once()
remaining_event = await event_queue.get()
assert b"taco2" == remaining_event

popped = transport.write.mock_calls.pop()

# Python 3.7: popped[1][0]
# Python 3.8+: popped.args[0]
assert b"taco1" == popped[1][0]

protocol = mock.Mock()
protocol._drain_helper = mock.AsyncMock()

mock_reader = mock.Mock(spec=asyncio.StreamReader)
mock_writer = mock.Mock(spec=asyncio.StreamWriter)
mock_writer.transport = transport

mock_writer.write = transport.write

with mock.patch('asyncio.open_connection', new=mock.AsyncMock(return_value=(mock_reader, mock_writer))):
_, writer = await asyncio.open_connection()
worker: pytak.Worker = pytak.TXWorker(event_queue, {}, writer)

await worker.run_once()

remaining_event = await event_queue.get()
assert b"taco2" == remaining_event

popped = transport.write.mock_calls.pop()
# Python 3.7: popped[1][0]
# Python 3.8+: popped.args[0]
assert b"taco1" == popped[1][0]


def test_simple_cot_event_to_xml() -> None:
Expand Down