Skip to content

Commit

Permalink
Revert test deletion in "tools: deprecate regexp functions"
Browse files Browse the repository at this point in the history
This partially reverts commit 1f4df30.
  • Loading branch information
dgw committed Oct 11, 2020
1 parent 452818c commit 3176636
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions test/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from datetime import timedelta
import re

import pytest

from sopel import tools
from sopel.tools.time import seconds_to_human

Expand All @@ -16,6 +18,88 @@
"""


@pytest.fixture
def nick():
return 'Sopel'


@pytest.fixture
def alias_nicks():
return ['Soap', 'Pie']


@pytest.fixture
def prefix():
return '.'


@pytest.fixture
def prefix_regex():
re.escape(prefix())


@pytest.fixture
def command():
return 'testcmd'


@pytest.fixture
def groups(command):
return {
3: "three",
4: "four",
5: "five",
6: "six",
}


@pytest.fixture
def command_line(prefix, command, groups):
return "{}{} {}".format(prefix, command, ' '.join(groups.values()))


@pytest.fixture
def nickname_command_line(nick, command, groups):
return "{}: {} {}".format(nick, command, ' '.join(groups.values()))


def test_command_groups(prefix, command, groups, command_line):
regex = tools.get_command_regexp(prefix, command)
match = re.match(regex, command_line)
assert match.group(0) == command_line
assert match.group(1) == command
assert match.group(2) == ' '.join(groups.values())
assert match.group(3) == groups[3]
assert match.group(4) == groups[4]
assert match.group(5) == groups[5]
assert match.group(6) == groups[6]


def test_nickname_command_groups(command, nick, groups, nickname_command_line):
regex = tools.get_nickname_command_regexp(nick, command, [])
match = re.match(regex, nickname_command_line)
assert match.group(0) == nickname_command_line
assert match.group(1) == command
assert match.group(2) == ' '.join(groups.values())
assert match.group(3) == groups[3]
assert match.group(4) == groups[4]
assert match.group(5) == groups[5]
assert match.group(6) == groups[6]


def test_nickname_command_aliased(command, nick, alias_nicks, groups, nickname_command_line):
aliased_command_line = nickname_command_line.replace(nick, alias_nicks[0])
regex = tools.get_nickname_command_regexp(nick, command, alias_nicks)
match = re.match(regex, aliased_command_line)
assert match.group(0) == aliased_command_line
assert match.group(1) == command
assert match.group(2) == ' '.join(groups.values())
assert match.group(3) == groups[3]
assert match.group(4) == groups[4]
assert match.group(5) == groups[5]
assert match.group(6) == groups[6]


def test_get_sendable_message_default():
initial = 'aaaa'
text, excess = tools.get_sendable_message(initial)
Expand Down

0 comments on commit 3176636

Please sign in to comment.