コード例 #1
0
    def wrap_watch(pattern, force=False):
        cmd = 'watch{0}'.format('-force' if force else '')
        msg = Fake({
            "_client": {
                "host": "stackexchange.com",
                "get_user": lambda id: Fake({
                    "name": "J F",
                    "id": id
                })
            },
            "owner": {
                "name": "ArtOfCode",
                "id": 121520
            },
            "room": {
                "id": 11540,
                "get_current_user_ids": lambda: [161943]
            },
            # Ouch, this is iffy
            # Prevent an error from deep inside do_blacklist
            "content_source": '!!/{0} {1}'.format(cmd, pattern)
        })
        msg.content = msg.content_source
        msg.room._client = msg._client

        return chatcommands.watch(pattern, alias_used=cmd, original_msg=msg)
コード例 #2
0
def test_bisect(command, test_text, expected_result):
    chatcommunicate.parse_room_config("test/test_rooms.yml")
    msg = Fake({
        "owner": {
            "name": "ArtOfCode",
            "id": 121520,
            "is_moderator": True
        },
        "room": {
            "_client": {
                "host": "stackexchange.com"
            },
            "id": 11540
        },
        "content_source": None
    })

    msg.content_source = "!!/{} {}".format(command, test_text)
    print('command:', command)
    print('test_text:', test_text)
    msg.content = msg.content_source
    # All of the substitution references used in the .format() for the expected result are named. Any which are numbers are
    # part of the expected results.
    expected_result = regex.sub(r"(\{\d+(?:,\d+)?\})", r'{\1}',
                                expected_result)
    formatted_expected_result = expected_result.format(
        test_text=test_text,
        bot_repo_slug=GlobalVars.bot_repo_slug,
        commit_id=GlobalVars.commit.id)
    chat_command = getattr(chatcommands, command)
    result = chat_command(None, original_msg=msg)
    print('formatted_expected_result:', formatted_expected_result)
    print('                   result:', result)
    assert result == formatted_expected_result