<commit_before>"""
<https://ircv3.net/specs/extensions/away-notify-3.1>
"""

from irctest import cases


class AwayNotifyTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
    @cases.SpecificationSelector.requiredBySpecification("IRCv3.1")
    def testAwayNotify(self):
        """Basic away-notify test."""
        self.connectClient("foo", capabilities=["away-notify"], skip_if_cap_nak=True)
        self.getMessages(1)
        self.joinChannel(1, "#chan")

        self.connectClient("bar")
        self.getMessages(2)
        self.joinChannel(2, "#chan")
        self.getMessages(2)
        self.getMessages(1)

        self.sendLine(2, "AWAY :i'm going away")
        self.getMessages(2)

        messages = [msg for msg in self.getMessages(1) if msg.command == "AWAY"]
        self.assertEqual(len(messages), 1)
        awayNotify = messages[0]
        self.assertTrue(
            awayNotify.prefix.startswith("bar!"),
            "Unexpected away-notify source: %s" % (awayNotify.prefix,),
        )
        self.assertEqual(awayNotify.params, ["i'm going away"])

    @cases.SpecificationSelector.requiredBySpecification("IRCv3.2")
    def testAwayNotifyOnJoin(self):
        """The away-notify specification states:
        "Clients will be sent an AWAY message [...] when a user joins
        and has an away message set."
        """
        self.connectClient("foo", capabilities=["away-notify"], skip_if_cap_nak=True)
        self.getMessages(1)
        self.joinChannel(1, "#chan")

        self.connectClient("bar")
        self.getMessages(2)
        self.sendLine(2, "AWAY :i'm already away")
        self.getMessages(2)

        self.joinChannel(2, "#chan")
        self.getMessages(2)

        messages = [msg for msg in self.getMessages(1) if msg.command == "AWAY"]
        self.assertEqual(len(messages), 1)
        awayNotify = messages[0]
        self.assertTrue(
            awayNotify.prefix.startswith("bar!"),
            "Unexpected away-notify source: %s" % (awayNotify.prefix,),
        )
        self.assertEqual(awayNotify.params, ["i'm already away"])
<commit_msg>away_notify: Better errors<commit_after>"""
<https://ircv3.net/specs/extensions/away-notify-3.1>
"""

from irctest import cases


class AwayNotifyTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
    @cases.SpecificationSelector.requiredBySpecification("IRCv3.1")
    def testAwayNotify(self):
        """Basic away-notify test."""
        self.connectClient("foo", capabilities=["away-notify"], skip_if_cap_nak=True)
        self.getMessages(1)
        self.joinChannel(1, "#chan")

        self.connectClient("bar")
        self.getMessages(2)
        self.joinChannel(2, "#chan")
        self.getMessages(2)
        self.getMessages(1)

        self.sendLine(2, "AWAY :i'm going away")
        self.getMessages(2)

        awayNotify = self.getMessage(1)
        self.assertMessageEqual(awayNotify, command="AWAY", params=["i'm going away"])
        self.assertTrue(
            awayNotify.prefix.startswith("bar!"),
            "Unexpected away-notify source: %s" % (awayNotify.prefix,),
        )

    @cases.SpecificationSelector.requiredBySpecification("IRCv3.2")
    def testAwayNotifyOnJoin(self):
        """The away-notify specification states:
        "Clients will be sent an AWAY message [...] when a user joins
        and has an away message set."
        """
        self.connectClient("foo", capabilities=["away-notify"], skip_if_cap_nak=True)
        self.getMessages(1)
        self.joinChannel(1, "#chan")

        self.connectClient("bar")
        self.getMessages(2)
        self.sendLine(2, "AWAY :i'm already away")
        self.getMessages(2)

        self.joinChannel(2, "#chan")
        self.getMessages(2)

        messages = [msg for msg in self.getMessages(1) if msg.command == "AWAY"]
        self.assertEqual(
            len(messages),
            1,
            "Someone away joined a channel, "
            "but users in the channel did not get AWAY messages.",
        )
        awayNotify = messages[0]
        self.assertMessageEqual(awayNotify, command="AWAY", params=["i'm already away"])
        self.assertTrue(
            awayNotify.prefix.startswith("bar!"),
            "Unexpected away-notify source: %s" % (awayNotify.prefix,),
        )

{'fraction_non_alphanumeric': 0.13307013469577333, 'fraction_numerical': 0.012540640966093822, 'mean_word_length': 2.6780529461998293, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7544782', 'n_tokens_mistral': 1292, 'n_tokens_neox': 1263, 'n_words': 253}