Skip to content
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

Regex group support #130

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open

Regex group support #130

wants to merge 10 commits into from

Conversation

tribela
Copy link

@tribela tribela commented Jan 17, 2017

It support group name as kwargs for bot.respond_to method.

Related issue: #118

@jtatum
Copy link
Collaborator

jtatum commented Apr 8, 2017

This could use some unit tests.

Copy link
Collaborator

@jtatum jtatum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Jeong,

Thanks again for the contribution and for the tests. Did you have any luck running them? I noticed a small bug in the code that seems to be failing the tests when I try them out. My run is here: https://travis-ci.org/jtatum/slackbot/builds/221160048

The tests are a bit tricky to get working. I made a guide on how to do it. It's at https://github.com/lins05/slackbot/blob/develop/CONTRIBUTING.md#configure-tests

Even after correcting last_index to lastindex, I see the tests still fail with other issues. Please take a look and let me know what you think. If you have any problems getting them to run, ping me and I'll do my best to help!

kwargs = m.groupdict()
args = (
m.group(i)
for i in range(1, m.last_index + 1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re match objects don't have a last_index.

* Args are tuple. Not generator.
* Fix typo "lastindex".
* Yield 3 of None when none of plugins matched.
* Fix typo on testing module's filename.
* Fix category on testing message.
@tribela
Copy link
Author

tribela commented Apr 12, 2017

My mistake. lastindex not last_index.
And fixed some other issues.

Copy link
Collaborator

@jtatum jtatum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These updates are still failing functional tests. Please see my latest run at https://travis-ci.org/jtatum/slackbot/builds/223695036.

m.lastindex is None when pattern has no group.
has_matching_plugin = True
yield self.commands[category][matcher], to_utf8(m.groups())
yield self.commands[category][matcher], to_utf8(args), to_utf8(kwargs)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to_utf8 for now can only handle single string or list/tuple/set of strings, so you need to extend it to also handle dicts whose values are strings.


if not has_matching_plugin:
yield None, None
yield None, None, None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FakeFakePluginManager also need to be updated to return a 3-tuple.

args = tuple(
m.group(i)
for i in range(1, (m.lastindex or 0) + 1)
if i not in matcher.groupindex.values()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe sth. like:

args = (v for i, v in enumerate(m.groups()) if (i + 1) not in pattern.groupindex.values())

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also worth moving this to helper function in utils.py, e.g.

def extract_positional_and_named_groups(pattern, s):
    if isinstance(pattern, basestring):
        pattern = re.compile(pattern)
    m = re.match(pattern, s)
    kw = m.groupdict()
    a = [v for i, v in enumerate(m.groups()) if (i + 1) not in pattern.groupindex.values()]
    return a, kw

@lins05
Copy link
Collaborator

lins05 commented May 31, 2017

Return dictionary, not list.
@tribela
Copy link
Author

tribela commented Aug 9, 2017

Sorry. I was a dumb.
I fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants