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
dcbf1aed
Commit
dcbf1aed
authored
Mar 07, 2012
by
Gabriel Falcao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
starting to work on tags
parent
4bbe6aef
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
83 additions
and
9 deletions
+83
-9
lettuce/core.py
+22
-0
requirements.txt
+3
-2
setup.py
+3
-3
tests/unit/test_feature_parser.py
+26
-3
tests/unit/test_scenario_parsing.py
+29
-1
No files found.
lettuce/core.py
View file @
dcbf1aed
...
...
@@ -18,6 +18,7 @@
import
re
import
codecs
import
unicodedata
from
itertools
import
chain
from
copy
import
deepcopy
from
lettuce
import
strings
from
lettuce
import
languages
...
...
@@ -499,6 +500,7 @@ class Scenario(object):
self
.
name
=
name
self
.
language
=
language
self
.
remaining_lines
=
remaining_lines
self
.
steps
=
self
.
_parse_remaining_lines
(
remaining_lines
,
with_file
,
original_string
)
...
...
@@ -517,6 +519,11 @@ class Scenario(object):
self
.
steps
,
self
.
outlines
,
with_file
,
original_string
))
self
.
_add_myself_to_steps
()
if
original_string
and
'@'
in
self
.
original_string
:
self
.
tags
=
self
.
_find_tags
()
else
:
self
.
tags
=
[]
@property
def
max_length
(
self
):
if
self
.
outlines
:
...
...
@@ -627,6 +634,21 @@ class Scenario(object):
for
step
in
self
.
solved_steps
:
step
.
scenario
=
self
def
_find_tags
(
self
):
first_line
=
self
.
remaining_lines
[
0
]
trim
=
lambda
x
:
x
.
strip
()
old_lines
=
map
(
trim
,
self
.
original_string
.
splitlines
())
tag_lines
=
[]
if
first_line
in
old_lines
:
tag_lines
=
old_lines
[:
old_lines
.
index
(
first_line
)
-
1
]
if
tag_lines
:
return
list
(
chain
(
*
map
(
self
.
_extract_tag
,
tag_lines
)))
def
_extract_tag
(
self
,
item
):
regex
=
re
.
compile
(
r'[@](\S+)'
)
return
regex
.
findall
(
item
)
def
_resolve_steps
(
self
,
steps
,
outlines
,
with_file
,
original_string
):
for
outline
in
outlines
:
for
step
in
steps
:
...
...
requirements.txt
View file @
dcbf1aed
...
...
@@ -4,4 +4,5 @@ django>=1.1.1
sphinx
lxml
tornado
coverage
\ No newline at end of file
coverage
sure
>=0.10.0
\ No newline at end of file
setup.py
View file @
dcbf1aed
...
...
@@ -30,7 +30,7 @@ def get_packages():
return
packages
required_modules
=
[]
required_modules
=
[
'sure'
]
if
sys
.
version_info
[:
2
]
<
(
2
,
6
):
required_modules
.
append
(
'multiprocessing'
)
...
...
@@ -40,10 +40,10 @@ setup(name='lettuce',
description
=
'Behaviour Driven Development for python'
,
author
=
u'Gabriel Falcao'
,
author_email
=
'gabriel@nacaolivre.org'
,
url
=
'http://
github.com/gabrielfalcao/lettuce
'
,
url
=
'http://
lettuce.it
'
,
packages
=
get_packages
(),
install_requires
=
required_modules
,
entry_points
=
{
'console_scripts'
:
[
'lettuce = lettuce.
lettuce_cli
:main'
],
'console_scripts'
:
[
'lettuce = lettuce.
bin
:main'
],
},
)
tests/unit/test_feature_parser.py
View file @
dcbf1aed
...
...
@@ -14,7 +14,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from
sure
import
that
from
lettuce.core
import
Scenario
from
lettuce.core
import
Feature
from
nose.tools
import
assert_equals
...
...
@@ -148,6 +148,16 @@ Feature: Big sentence
# And another one, very tiny
"""
FEATURE11
=
"""
Feature: Yay tags
@many @other
@basic
@tags @here @:)
Scenario: Holy tag, Batman
Given this scenario has tags
Then it can be inspected from within the object
"""
def
test_feature_has_repr
():
"Feature implements __repr__ nicely"
...
...
@@ -282,15 +292,17 @@ def test_feature_max_length_on_scenario_outline_keys():
assert_equals
(
feature1
.
max_length
,
68
)
assert_equals
(
feature2
.
max_length
,
68
)
def
test_description_on_long_named_feature
():
"Can parse the description on long named features"
feature
=
Feature
.
from_string
(
FEATURE3
)
assert_equals
(
feature
.
description
,
"In order to describe my features
\n
"
"I want to add description on them"
"I want to add description on them"
,
)
def
test_description_on_big_sentenced_steps
():
"Can parse the description on long sentenced steps"
feature
=
Feature
.
from_string
(
FEATURE4
)
...
...
@@ -298,11 +310,22 @@ def test_description_on_big_sentenced_steps():
feature
.
description
,
"As a clever guy
\n
"
"I want to describe this Feature
\n
"
"So that I can take care of my Scenario"
"So that I can take care of my Scenario"
,
)
def
test_comments
():
"It should ignore lines that start with #, despite white spaces"
feature
=
Feature
.
from_string
(
FEATURE10
)
assert_equals
(
feature
.
max_length
,
55
)
def
test_single_scenario_single_tag
():
"Features should have their scenarios parsed with tags"
feature
=
Feature
.
from_string
(
FEATURE11
)
first_scenario
=
feature
.
scenarios
[
0
]
assert
that
(
first_scenario
.
tags
)
.
deep_equals
([
'many'
,
'other'
,
'basic'
,
'tags'
,
'here'
,
':)'
])
tests/unit/test_scenario_parsing.py
View file @
dcbf1aed
...
...
@@ -175,6 +175,7 @@ Scenario: Adding some students to my university database
"""
from
sure
import
that
from
lettuce.core
import
Step
from
lettuce.core
import
Scenario
from
lettuce.core
import
Feature
...
...
@@ -300,7 +301,7 @@ def test_scenario_tables_are_solved_against_outlines():
[],
[]
]
scenario
=
Scenario
.
from_string
(
OUTLINED_SCENARIO_WITH_SUBSTITUTIONS_IN_TABLE
)
for
step
,
expected_hashes
in
zip
(
scenario
.
solved_steps
,
expected_hashes_per_step
):
assert_equals
(
type
(
step
),
Step
)
...
...
@@ -431,3 +432,30 @@ def test_commented_scenarios():
scenario
=
Scenario
.
from_string
(
COMMENTED_SCENARIO
)
assert_equals
(
scenario
.
name
,
u'Adding some students to my university database'
)
assert_equals
(
len
(
scenario
.
steps
),
4
)
def
test_scenario_has_tag
():
"A scenario object should be able to find at least one tag "
\
"on the first line"
scenario
=
Scenario
.
from_string
(
SCENARIO1
,
original_string
=
(
'@onetag
\n
'
+
SCENARIO1
.
strip
()))
assert
that
(
scenario
.
tags
)
.
deep_equals
([
'onetag'
])
def
test_scenario_has_tags_singleline
():
"A scenario object should be able to find many tags "
\
"on the first line"
scenario
=
Scenario
.
from_string
(
SCENARIO1
,
original_string
=
(
'@onetag @another @$
%
^&even-weird_chars
\n
'
+
SCENARIO1
.
strip
()))
assert
that
(
scenario
.
tags
)
.
deep_equals
([
'onetag'
,
'another'
,
'$
%
^&even-weird_chars'
,
])
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