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
af0d68f6
Commit
af0d68f6
authored
May 05, 2010
by
Gabriel Falcão
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
renamed Step's member "data_list" to "hashes" to look more likely cucumber :)
parent
336b9c38
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
34 additions
and
34 deletions
+34
-34
lettuce/core.py
+11
-11
lettuce/plugins/colored_shell_output.py
+6
-6
lettuce/plugins/shell_output.py
+6
-6
tests/functional/output_features/success_table/success_table_steps.py
+2
-2
tests/unit/test_core.py
+3
-3
tests/unit/test_feature_parser.py
+1
-1
tests/unit/test_scenario_parsing.py
+1
-1
tests/unit/test_step_parsing.py
+4
-4
No files found.
lettuce/core.py
View file @
af0d68f6
...
...
@@ -24,18 +24,18 @@ from lettuce.registry import CALLBACK_REGISTRY
from
lettuce.exceptions
import
ReasonToFail
from
lettuce.exceptions
import
NoDefinitionFound
def
parse_
data_list
(
lines
):
def
parse_
hashes
(
lines
):
keys
=
[]
data_list
=
[]
hashes
=
[]
if
lines
:
first_line
=
lines
.
pop
(
0
)
keys
=
strings
.
split_wisely
(
first_line
,
"|"
,
True
)
for
line
in
lines
:
values
=
strings
.
split_wisely
(
line
,
"|"
,
True
)
data_list
.
append
(
dict
(
zip
(
keys
,
values
)))
hashes
.
append
(
dict
(
zip
(
keys
,
values
)))
return
keys
,
data_list
return
keys
,
hashes
class
StepDefinition
(
object
):
"""A step definition is a wrapper for user-defined callbacks. It
...
...
@@ -122,10 +122,10 @@ class Step(object):
self
.
sentence
=
sentence
self
.
original_sentence
=
sentence
self
.
_remaining_lines
=
remaining_lines
keys
,
data_list
=
self
.
_parse_remaining_lines
(
remaining_lines
)
keys
,
hashes
=
self
.
_parse_remaining_lines
(
remaining_lines
)
self
.
keys
=
tuple
(
keys
)
self
.
data_list
=
list
(
data_list
)
self
.
hashes
=
list
(
hashes
)
self
.
described_at
=
StepDescription
(
line
,
filename
)
def
solve_and_clone
(
self
,
data
):
...
...
@@ -159,7 +159,7 @@ class Step(object):
max_length_original
=
len
(
self
.
original_sentence
)
+
self
.
indentation
max_length
=
max
([
max_length_original
,
max_length_sentence
])
for
data
in
self
.
data_list
:
for
data
in
self
.
hashes
:
key_size
=
self
.
_calc_key_length
(
data
)
if
key_size
>
max_length
:
max_length
=
key_size
...
...
@@ -177,15 +177,15 @@ class Step(object):
where
=
self
.
defined_at
return
strings
.
rfill
(
head
,
self
.
scenario
.
feature
.
max_length
+
1
,
append
=
'#
%
s:
%
d
\n
'
%
(
where
.
file
,
where
.
line
))
def
represent_
data_list
(
self
):
lines
=
strings
.
dicts_to_string
(
self
.
data_list
,
self
.
keys
)
.
splitlines
()
def
represent_
hashes
(
self
):
lines
=
strings
.
dicts_to_string
(
self
.
hashes
,
self
.
keys
)
.
splitlines
()
return
"
\n
"
.
join
([(
" "
*
self
.
table_indentation
)
+
line
for
line
in
lines
])
+
"
\n
"
def
__repr__
(
self
):
return
u'<Step: "
%
s">'
%
self
.
sentence
def
_parse_remaining_lines
(
self
,
lines
):
return
parse_
data_list
(
lines
)
return
parse_
hashes
(
lines
)
def
_get_match
(
self
,
ignore_case
):
matched
,
func
=
None
,
lambda
:
None
...
...
@@ -444,7 +444,7 @@ class Scenario(object):
outlines
=
[]
if
len
(
splitted
)
is
2
:
part
=
splitted
[
1
]
keys
,
outlines
=
parse_
data_list
(
strings
.
get_stripped_lines
(
part
))
keys
,
outlines
=
parse_
hashes
(
strings
.
get_stripped_lines
(
part
))
lines
=
strings
.
get_stripped_lines
(
string
)
scenario_line
=
lines
.
pop
(
0
)
...
...
lettuce/plugins/colored_shell_output.py
View file @
af0d68f6
...
...
@@ -58,8 +58,8 @@ def print_step_running(step):
string
=
step
.
represent_string
(
step
.
original_sentence
)
string
=
wrap_file_and_line
(
string
,
'
\033
[1;30m'
,
'
\033
[0m'
)
write_out
(
"
%
s
%
s"
%
(
color
,
string
))
if
step
.
data_list
:
for
line
in
step
.
represent_
data_list
()
.
splitlines
():
if
step
.
hashes
:
for
line
in
step
.
represent_
hashes
()
.
splitlines
():
write_out
(
"
\033
[1;30m
%
s
\033
[0m
\n
"
%
line
)
@after.each_step
...
...
@@ -67,8 +67,8 @@ def print_step_ran(step):
if
step
.
scenario
.
outlines
:
return
if
step
.
data_list
:
write_out
(
"
\033
[A"
*
(
len
(
step
.
data_list
)
+
1
))
if
step
.
hashes
:
write_out
(
"
\033
[A"
*
(
len
(
step
.
hashes
)
+
1
))
string
=
step
.
represent_string
(
step
.
original_sentence
)
...
...
@@ -94,8 +94,8 @@ def print_step_ran(step):
write_out
(
"
%
s
%
s
%
s"
%
(
prefix
,
color
,
string
))
if
step
.
data_list
:
for
line
in
step
.
represent_
data_list
()
.
splitlines
():
if
step
.
hashes
:
for
line
in
step
.
represent_
hashes
()
.
splitlines
():
write_out
(
"
%
s
%
s
\033
[0m
\n
"
%
(
color
,
line
))
if
step
.
failed
:
...
...
lettuce/plugins/shell_output.py
View file @
af0d68f6
...
...
@@ -27,16 +27,16 @@ def wrt(what):
@before.each_step
def
print_step_running
(
step
):
wrt
(
step
.
represent_string
(
step
.
original_sentence
))
if
step
.
data_list
:
wrt
(
step
.
represent_
data_list
())
if
step
.
hashes
:
wrt
(
step
.
represent_
hashes
())
@after.each_step
def
print_step_ran
(
step
):
if
step
.
scenario
.
outlines
:
return
if
step
.
data_list
:
wrt
(
"
\033
[A"
*
(
len
(
step
.
data_list
)
+
1
))
if
step
.
hashes
:
wrt
(
"
\033
[A"
*
(
len
(
step
.
hashes
)
+
1
))
if
step
.
defined_at
:
wrt
(
"
\033
[A"
+
step
.
represent_string
(
step
.
original_sentence
))
...
...
@@ -44,8 +44,8 @@ def print_step_ran(step):
else
:
wrt
(
step
.
represent_string
(
step
.
original_sentence
)
.
rstrip
()
+
" (undefined)
\n
"
)
if
step
.
data_list
:
wrt
(
step
.
represent_
data_list
())
if
step
.
hashes
:
wrt
(
step
.
represent_
hashes
())
if
step
.
failed
:
print_spaced
=
lambda
x
:
wrt
(
"
%
s
%
s
\n
"
%
(
" "
*
step
.
indentation
,
x
))
...
...
tests/functional/output_features/success_table/success_table_steps.py
View file @
af0d68f6
...
...
@@ -31,7 +31,7 @@ def compare_bucks(step, cash):
@step
(
'I have these items'
)
def
havetheseitems
(
step
):
cars
=
{}
for
data
in
step
.
data_list
:
for
data
in
step
.
hashes
:
key
=
data
[
'name'
]
value
=
int
(
data
[
'price'
])
cars
[
key
]
=
value
...
...
@@ -46,7 +46,7 @@ def sell_item(step, name):
@step
(
'my garage contains:'
)
def
alsothese
(
step
):
cars
=
{}
for
data
in
step
.
data_list
:
for
data
in
step
.
hashes
:
key
=
data
[
'name'
]
value
=
int
(
data
[
'price'
])
cars
[
key
]
=
value
...
...
tests/unit/test_core.py
View file @
af0d68f6
...
...
@@ -131,12 +131,12 @@ def test_step_represent_string_when_defined():
)
def
test_step_represent_table
():
"Step.represent_
data_list
"
"Step.represent_
hashes
"
step
=
core
.
Step
.
from_string
(
STEP_WITH_TABLE
)
assert_equals
(
step
.
represent_
data_list
(),
step
.
represent_
hashes
(),
' | name | description |
\n
'
' | Glass | a nice glass to drink grape juice |
\n
'
' | Pasta | a pasta to cook and eat with grape juice in the glass |
\n
'
...
...
@@ -153,7 +153,7 @@ Examples:
'''
def
test_scenario_outline_represent_examples
():
"Step.represent_
data_list
"
"Step.represent_
hashes
"
step
=
core
.
Scenario
.
from_string
(
SCENARIO_OUTLINE
)
...
...
tests/unit/test_feature_parser.py
View file @
af0d68f6
...
...
@@ -168,7 +168,7 @@ def test_feature_has_scenarios():
assert_equals
(
feature
.
scenarios
[
1
]
.
steps
[
0
]
.
keys
,
(
'Name'
,
'Rating'
,
'New'
,
'Available'
))
assert_equals
(
feature
.
scenarios
[
1
]
.
steps
[
0
]
.
data_list
,
feature
.
scenarios
[
1
]
.
steps
[
0
]
.
hashes
,
[
{
'Name'
:
'A night at the museum 2'
,
'Rating'
:
'3 stars'
,
'New'
:
'yes'
,
'Available'
:
'9'
},
{
'Name'
:
'Matrix Revolutions'
,
'Rating'
:
'4 stars'
,
'New'
:
'no'
,
'Available'
:
'6'
},
...
...
tests/unit/test_scenario_parsing.py
View file @
af0d68f6
...
...
@@ -137,7 +137,7 @@ def test_scenario_has_steps():
assert_equals
(
scenario
.
steps
[
0
]
.
keys
,
(
'Name'
,
'Duration'
))
assert_equals
(
scenario
.
steps
[
0
]
.
data_list
,
scenario
.
steps
[
0
]
.
hashes
,
[
{
'Name'
:
'Computer Science'
,
'Duration'
:
'5 years'
},
{
'Name'
:
'Nutrition'
,
'Duration'
:
'4 years'
},
...
...
tests/unit/test_step_parsing.py
View file @
af0d68f6
...
...
@@ -56,10 +56,10 @@ def test_can_parse_tables():
step
=
Step
.
from_string
(
STEP1
)
assert
isinstance
(
step
.
data_list
,
list
)
assert_equals
(
len
(
step
.
data_list
),
2
)
assert
isinstance
(
step
.
hashes
,
list
)
assert_equals
(
len
(
step
.
hashes
),
2
)
assert_equals
(
step
.
data_list
[
0
],
step
.
hashes
[
0
],
{
'Name'
:
'Skol'
,
'Type'
:
'Beer'
,
...
...
@@ -67,7 +67,7 @@ def test_can_parse_tables():
}
)
assert_equals
(
step
.
data_list
[
1
],
step
.
hashes
[
1
],
{
'Name'
:
'Nestea'
,
'Type'
:
'Ice-tea'
,
...
...
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