Skip to content

irc: make log_raw() method testable, and test it#2723

Open
dgw wants to merge 2 commits intomasterfrom
test_log_raw
Open

irc: make log_raw() method testable, and test it#2723
dgw wants to merge 2 commits intomasterfrom
test_log_raw

Conversation

@dgw
Copy link
Member

@dgw dgw commented Feb 4, 2026

Description

With the call to self.bot.log_raw() living in the AsyncioBackend's read handler, there was no way to trigger it from tests. (Well… no way without doing a lot of other work.)

Moving the call inside AbstractBot.on_message() (which is called for every incoming line anyway) makes the raw log testable via a caplog fixture, so we can prove that the bot is logging IRC traffic.

The new test case proves a point in #2721, but does not close any actual issues.

Checklist

  • I have read CONTRIBUTING.md
  • I can and do license this contribution under the EFLv2
  • No issues are reported by make qa (runs make lint and make test)
    • Honestly, I was wary of tripping up another of the few test cases that also uses caplog, but no: All passed locally.
  • I have tested the functionality of the things this change touches
    • It's literally a new test case :)

Notes

There was one wee oddity with literal \r\n appearing in the outgoing line but not in the incoming one. I added a fix commit addressing it, in lieu of scope creep (making the MockIRCServer ensure a trailing \r\n).

dgw added 2 commits February 4, 2026 03:47
With the call to `self.bot.log_raw()` living in the `AsyncioBackend`'s
read handler, there was no way to trigger it from tests.

Moving the call inside `AbstractBot.on_message()` (which is called for
every incoming line anyway) makes the raw log testable via a `caplog`
fixture, so we can prove that the bot is logging IRC traffic.

There's one wee oddity with literal `\r\n` appearing in the outgoing
line but not in the incoming one. It would be ideal if those were
consistent with each other, but I haven't looked into that yet.
In the real bot, `AsyncioBackend` uses asyncio's `readuntil()`, which
will include the separator `\r\n` in returned lines. Our `MockIRCServer`
doesn't modify the line passed to its `message()` method; if it doesn't
have a separator at the end, the bot will receive a message with no
separator. But the `log_raw()` test needs to prove that a separator gets
logged correctly for incoming messages, so let's make sure it's present.
@dgw dgw added this to the 8.1.0 milestone Feb 4, 2026
@dgw dgw requested a review from a team February 4, 2026 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant