Skip to content

Instantly share code, notes, and snippets.

@rene-armida
Created November 2, 2012 15:01
Show Gist options
  • Save rene-armida/4001865 to your computer and use it in GitHub Desktop.
Save rene-armida/4001865 to your computer and use it in GitHub Desktop.
Behave pretty formatter raises AssertionError when handling nested regex groups
Feature: matchers
# passes fine
Scenario: regex, no nested groups, matching
Given that I am testing behave
When I try to use a regex matcher for unnested groups
Then I should have to call step_matcher
# both of the following trigger AssertionError
Scenario: regex, nested groups, no match
Given that I am testing behave
When I try to use a regex matcher for nested
Then I should have to call step_matcher
Scenario: regex, nested groups, match
Given that I am testing behave
When I try to use a regex matcher for nested groups
Then I should have to call step_matcher
(venv)marmida@monolith:~/develop/behave_matchers$ behave
Feature: matchers # features/matchers.feature:1
Scenario: regex, no nested groups, matching # features/matchers.feature:5
Given that I am testing behave # features/steps/steps.py:6 0.00s
When I try to use a regex matcher for unnested groups # features/steps/steps.py:13 0.00s
Then I should have to call step_matcher # features/steps/steps.py:18 0.00s
Scenario: regex, nested groups, no match # features/matchers.feature:12
Given that I am testing behave # features/steps/steps.py:6 0.00s
When I try to use a regex matcher for nestedTraceback (most recent call last):
File "/home/marmida/develop/behave_matchers/venv/bin/behave", line 8, in <module>
load_entry_point('behave==1.2.2', 'console_scripts', 'behave')()
File "/home/marmida/develop/behave_matchers/venv/local/lib/python2.7/site-packages/behave/__main__.py", line 93, in main
failed = runner.run()
File "/home/marmida/develop/behave_matchers/venv/local/lib/python2.7/site-packages/behave/runner.py", line 436, in run
return self.run_with_paths()
File "/home/marmida/develop/behave_matchers/venv/local/lib/python2.7/site-packages/behave/runner.py", line 461, in run_with_paths
failed = feature.run(self)
File "/home/marmida/develop/behave_matchers/venv/local/lib/python2.7/site-packages/behave/model.py", line 236, in run
failed = scenario.run(runner)
File "/home/marmida/develop/behave_matchers/venv/local/lib/python2.7/site-packages/behave/model.py", line 433, in run
if not step.run(runner):
File "/home/marmida/develop/behave_matchers/venv/local/lib/python2.7/site-packages/behave/model.py", line 744, in run
runner.formatter.match(match)
File "/home/marmida/develop/behave_matchers/venv/local/lib/python2.7/site-packages/behave/formatter/pretty.py", line 126, in match
self._match.location, self.monochrome)
File "/home/marmida/develop/behave_matchers/venv/local/lib/python2.7/site-packages/behave/formatter/pretty.py", line 285, in print_step
self.stream.write(arg_format.text(arg.original))
File "/home/marmida/develop/behave_matchers/venv/local/lib/python2.7/site-packages/behave/formatter/pretty.py", line 30, in text
assert isinstance(text, unicode)
AssertionError
(venv)marmida@monolith:~/develop/behave_matchers$ behave --no-capture --format plain
Feature: matchers
Scenario: regex, no nested groups, matching
Given that I am testing behave ... passed in 0.00s
{u'foo': u'unnested groups'}
When I try to use a regex matcher for unnested groups ... passed in 0.00s
Then I should have to call step_matcher ... passed in 0.00s
Scenario: regex, nested groups, no match
Given that I am testing behave ... passed in 0.00s
{u'foo': u'nested', u'bar': None}
When I try to use a regex matcher for nested ... passed in 0.00s
Then I should have to call step_matcher ... passed in 0.00s
Scenario: regex, nested groups, match
Given that I am testing behave ... passed in 0.00s
{u'foo': u'nested groups', u'bar': u' groups'}
When I try to use a regex matcher for nested groups ... passed in 0.00s
Then I should have to call step_matcher ... passed in 0.00s
1 feature passed, 0 failed, 0 skipped
3 scenarios passed, 0 failed, 0 skipped
9 steps passed, 0 failed, 0 skipped, 0 undefined
Took 0m0.0s
'test behave.step_matcher'
from behave import *
# import pdb; pdb.set_trace()
@given(u'that I am testing behave')
def impl(context):
pass
step_matcher('re')
# flat groups, no nesting - works fine
@when(u'I try to use a regex matcher for (?P<foo>unnested groups)')
def impl(context, *args, **kwargs):
print kwargs
# a plain string run via regex - works
@then(u'I should have to call step_matcher')
def impl(context):
pass
# nested groups don't work if they don't match - works with plain formatter only
# same results with or without the inner group matching
@when(u'I try to use a regex matcher for (?P<foo>nested(?P<bar> groups)?)')
def impl(context, *args, **kwargs):
print kwargs
@rene-armida
Copy link
Author

Fixed the subgroup so it actually matches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment