Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lettuce
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
lettuce
Commits
f998ffbf
Commit
f998ffbf
authored
Aug 22, 2011
by
Gabriel Falcao
Browse files
Options
Browse Files
Download
Plain Diff
non-greedy regexes on step definition snippets. closes #155
parents
91c48025
1138d09f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
17 deletions
+10
-17
lettuce/core.py
+4
-11
tests/functional/test_runner.py
+6
-6
No files found.
lettuce/core.py
View file @
f998ffbf
...
...
@@ -194,30 +194,23 @@ class Step(object):
self
.
keys
=
tuple
(
keys
)
self
.
hashes
=
HashList
(
self
,
hashes
)
self
.
described_at
=
StepDescription
(
line
,
filename
)
self
.
proposed_method_name
,
self
.
proposed_sentence
=
self
.
propose_definition
()
def
propose_definition
(
self
):
sentence
=
unicode
(
self
.
original_sentence
)
method_name
=
sentence
groups
=
[
(
'"'
,
re
.
compile
(
r'("[^"]+")'
)
),
# double quotes
(
"'"
,
re
.
compile
(
r"('[^']+')"
)
),
# single quotes
(
'"'
,
re
.
compile
(
r'("[^"]+")'
)
,
r'"([^"]*)"'
),
(
"'"
,
re
.
compile
(
r"('[^']+')"
)
,
r"\'([^\']*)\'"
),
]
attribute_names
=
[]
for
char
,
group
in
groups
:
for
char
,
group
,
template
in
groups
:
match_groups
=
group
.
search
(
self
.
original_sentence
)
if
match_groups
:
for
index
,
match
in
enumerate
(
group
.
findall
(
sentence
)):
if
char
==
"'"
:
char
=
re
.
escape
(
char
)
sentence
=
sentence
.
replace
(
match
,
u'
%
s(.*)
%
s'
%
(
char
,
char
))
sentence
=
sentence
.
replace
(
match
,
template
)
group_name
=
u"group
%
d"
%
(
index
+
1
)
method_name
=
method_name
.
replace
(
match
,
group_name
)
attribute_names
.
append
(
group_name
)
...
...
tests/functional/test_runner.py
View file @
f998ffbf
...
...
@@ -714,7 +714,7 @@ def test_output_snippets_with_groups_within_double_quotes_colorless():
u"# -*- coding: utf-8 -*-
\n
"
u'from lettuce import step
\n
'
u'
\n
'
u'@step(u
\'
Given I have "(
.*)" and "(.
*)"
\'
)
\n
'
u'@step(u
\'
Given I have "(
[^
\"
]*)" and "([^
\"
]
*)"
\'
)
\n
'
u'def given_i_have_group1_and_group2(step, group1, group2):
\n
'
u' assert False,
\'
This step must be implemented
\'\n
'
)
...
...
@@ -742,7 +742,7 @@ def test_output_snippets_with_groups_within_double_quotes_colorful():
u"# -*- coding: utf-8 -*-
\n
"
u'from lettuce import step
\n
'
u'
\n
'
u'@step(u
\'
Given I have "(
.*)" and "(.
*)"
\'
)
\n
'
u'@step(u
\'
Given I have "(
[^"]*)" and "([^"]
*)"
\'
)
\n
'
u'def given_i_have_group1_and_group2(step, group1, group2):
\n
'
u' assert False,
\'
This step must be implemented
\'\033
[0m
\n
'
)
...
...
@@ -771,7 +771,7 @@ def test_output_snippets_with_groups_within_single_quotes_colorless():
u"# -*- coding: utf-8 -*-
\n
"
u'from lettuce import step
\n
'
u'
\n
'
u'@step(u
\'
Given I have
\\\'
(
.*)
\\\'
and
\\\'
(.
*)
\\\'\'
)
\n
'
u'@step(u
\'
Given I have
\\\'
(
[^
\\\'
]*)
\\\'
and
\\\'
([^
\\\'
]
*)
\\\'\'
)
\n
'
u'def given_i_have_group1_and_group2(step, group1, group2):
\n
'
u' assert False,
\'
This step must be implemented
\'\n
'
)
...
...
@@ -799,7 +799,7 @@ def test_output_snippets_with_groups_within_single_quotes_colorful():
u"# -*- coding: utf-8 -*-
\n
"
u'from lettuce import step
\n
'
u'
\n
'
u'@step(u
\'
Given I have
\\\'
(
.*)
\\\'
and
\\\'
(.
*)
\\\'\'
)
\n
'
u'@step(u
\'
Given I have
\\\'
(
[^
\\\'
]*)
\\\'
and
\\\'
([^
\\\'
]
*)
\\\'\'
)
\n
'
u'def given_i_have_group1_and_group2(step, group1, group2):
\n
'
u' assert False,
\'
This step must be implemented
\'\033
[0m
\n
'
)
...
...
@@ -828,7 +828,7 @@ def test_output_snippets_with_groups_within_redundant_quotes():
u"# -*- coding: utf-8 -*-
\n
"
u'from lettuce import step
\n
'
u'
\n
'
u'@step(u
\'
Given I have "(
.*)" and "(.
*)"
\'
)
\n
'
u'@step(u
\'
Given I have "(
[^"]*)" and "([^"]
*)"
\'
)
\n
'
u'def given_i_have_group1_and_group2(step, group1, group2):
\n
'
u' assert False,
\'
This step must be implemented
\'\n
'
)
...
...
@@ -864,7 +864,7 @@ def test_output_snippets_with_normalized_unicode_names():
u"@step(u'Dado que eu tenho palavrões e outras situações')
\n
"
u"def dado_que_eu_tenho_palavroes_e_outras_situacoes(step):
\n
"
u" assert False, 'This step must be implemented'
\n
"
u"@step(u'E várias palavras acentuadas são úteis, tais como:
\"
(
.
*)
\"
')
\n
"
u"@step(u'E várias palavras acentuadas são úteis, tais como:
\"
(
[^
\"
]
*)
\"
')
\n
"
u"def e_varias_palavras_acentuadas_sao_uteis_tais_como_group1(step, group1):
\n
"
u" assert False, 'This step must be implemented'
\n
"
u"@step(u'Então eu fico felizão')
\n
"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment