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
ccb95004
Commit
ccb95004
authored
Oct 20, 2012
by
Gabriel Falcao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implementing basic output of backgrounds
parent
b7ea4049
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
109 additions
and
13 deletions
+109
-13
lettuce/core.py
+55
-7
lettuce/plugins/shell_output.py
+7
-0
lettuce/registry.py
+4
-0
lettuce/strings.py
+2
-2
lettuce/terrain.py
+1
-0
tests/functional/bg_features/simple/simple.feature
+10
-0
tests/functional/bg_features/simple/steps.py
+26
-0
tests/functional/test_runner.py
+0
-0
tests/unit/test_core.py
+4
-4
No files found.
lettuce/core.py
View file @
ccb95004
...
...
@@ -15,13 +15,16 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
random
as
rand
import
re
import
codecs
from
fuzzywuzzy
import
fuzz
import
unicodedata
from
itertools
import
chain
from
copy
import
deepcopy
from
fuzzywuzzy
import
fuzz
from
itertools
import
chain
from
random
import
shuffle
from
lettuce
import
strings
from
lettuce
import
languages
from
lettuce.fs
import
FileSystem
...
...
@@ -181,6 +184,7 @@ class FeatureDescription(object):
self
.
line
=
None
described_at
=
[]
description_lines
=
strings
.
get_stripped_lines
(
feature
.
description
)
for
pline
,
part
in
enumerate
(
lines
):
part
=
part
.
strip
()
line
=
pline
+
1
...
...
@@ -205,6 +209,8 @@ class Step(object):
passed
=
None
failed
=
None
related_outline
=
None
scenario
=
None
background
=
None
def
__init__
(
self
,
sentence
,
remaining_lines
,
line
=
None
,
filename
=
None
):
self
.
sentence
=
sentence
...
...
@@ -301,12 +307,17 @@ class Step(object):
return
max_length
@property
def
parent
(
self
):
return
self
.
scenario
or
self
.
background
def
represent_string
(
self
,
string
):
head
=
' '
*
self
.
indentation
+
string
where
=
self
.
described_at
if
self
.
defined_at
:
where
=
self
.
defined_at
return
strings
.
rfill
(
head
,
self
.
scenario
.
feature
.
max_length
+
1
,
append
=
u'#
%
s:
%
d
\n
'
%
(
where
.
file
,
where
.
line
))
return
strings
.
rfill
(
head
,
self
.
parent
.
feature
.
max_length
+
1
,
append
=
u'#
%
s:
%
d
\n
'
%
(
where
.
file
,
where
.
line
))
def
represent_hashes
(
self
):
lines
=
strings
.
dicts_to_string
(
self
.
hashes
,
self
.
keys
)
.
splitlines
()
...
...
@@ -834,17 +845,54 @@ class Scenario(object):
class
Background
(
object
):
indentation
=
2
def
__init__
(
self
,
lines
,
feature
,
with_file
=
None
,
original_string
=
None
,
language
=
None
):
self
.
steps
=
Step
.
many_from_lines
(
lines
,
with_file
,
original_string
)
self
.
steps
=
map
(
self
.
add_self_to_step
,
Step
.
many_from_lines
(
lines
,
with_file
,
original_string
))
self
.
feature
=
feature
self
.
original_string
=
original_string
self
.
language
=
language
def
add_self_to_step
(
self
,
step
):
step
.
background
=
self
return
step
def
run
(
self
,
ignore_case
):
return
[
s
.
run
(
ignore_case
)
for
s
in
self
.
steps
]
call_hook
(
'before_each'
,
'background'
,
self
)
results
=
[]
for
step
in
self
.
steps
:
call_hook
(
'before_each'
,
'step'
,
step
)
try
:
results
.
append
(
step
.
run
(
ignore_case
))
except
Exception
,
e
:
print
e
pass
call_hook
(
'after_each'
,
'step'
,
step
)
call_hook
(
'after_each'
,
'background'
,
self
,
results
)
return
results
def
__repr__
(
self
):
return
'<Background for feature: {0}>'
.
format
(
self
.
feature
.
name
)
@property
def
max_length
(
self
):
max_length
=
0
for
step
in
self
.
steps
:
if
step
.
max_length
>
max_length
:
max_length
=
step
.
max_length
return
max_length
def
represented
(
self
):
return
((
' '
*
self
.
indentation
)
+
'Background:'
)
@classmethod
def
from_string
(
new_background
,
...
...
@@ -1065,7 +1113,7 @@ class Feature(object):
scenarios_ran
=
[]
if
random
:
rand
.
shuffle
(
self
.
scenarios
)
shuffle
(
self
.
scenarios
)
if
isinstance
(
scenarios
,
(
tuple
,
list
)):
if
all
(
map
(
lambda
x
:
isinstance
(
x
,
int
),
scenarios
)):
...
...
lettuce/plugins/shell_output.py
View file @
ccb95004
...
...
@@ -52,6 +52,13 @@ def print_scenario_running(scenario):
wrt
(
scenario
.
represented
())
@before.each_background
def
print_background_running
(
background
):
wrt
(
'
\n
'
)
wrt
(
background
.
represented
())
wrt
(
'
\n
'
)
@after.outline
def
print_outline
(
scenario
,
order
,
outline
,
reasons_to_fail
):
table
=
strings
.
dicts_to_string
(
scenario
.
outlines
,
scenario
.
keys
)
...
...
lettuce/registry.py
View file @
ccb95004
...
...
@@ -54,6 +54,10 @@ CALLBACK_REGISTRY = CallbackDict(
'after_each'
:
[],
'outline'
:
[],
},
'background'
:
{
'before_each'
:
[],
'after_each'
:
[],
},
'feature'
:
{
'before_each'
:
[],
'after_each'
:
[],
...
...
lettuce/strings.py
View file @
ccb95004
...
...
@@ -96,7 +96,7 @@ def getlen(string):
def
dicts_to_string
(
dicts
,
order
):
escape
=
"#{
%
s}"
%
str
(
time
.
time
())
escape
=
"#{
%
s}"
%
unicode
(
time
.
time
())
def
enline
(
line
):
return
unicode
(
line
)
.
replace
(
"|"
,
escape
)
...
...
@@ -133,7 +133,7 @@ def dicts_to_string(dicts, order):
def
parse_hashes
(
lines
):
escape
=
"#{
%
s}"
%
str
(
time
.
time
())
escape
=
"#{
%
s}"
%
unicode
(
time
.
time
())
def
enline
(
line
):
return
unicode
(
line
.
replace
(
"
\\
|"
,
escape
))
.
strip
()
...
...
lettuce/terrain.py
View file @
ccb95004
...
...
@@ -54,6 +54,7 @@ for name, where, when in (
(
'all'
,
'all'
,
'
%(0)
s'
),
(
'each_step'
,
'step'
,
'
%(0)
s_each'
),
(
'each_scenario'
,
'scenario'
,
'
%(0)
s_each'
),
(
'each_background'
,
'background'
,
'
%(0)
s_each'
),
(
'each_feature'
,
'feature'
,
'
%(0)
s_each'
),
(
'harvest'
,
'harvest'
,
'
%(0)
s'
),
(
'each_app'
,
'app'
,
'
%(0)
s_each'
),
...
...
tests/functional/bg_features/simple/simple.feature
0 → 100644
View file @
ccb95004
Feature
:
Simple and successful
As the Lettuce maintainer
In order to make sure the output is pretty
I want to automate its test
Background
:
Given
the variable
"X"
holds 2
Scenario
:
multiplication changing the value
Given
the variable
"X"
is equal to 2
tests/functional/bg_features/simple/steps.py
0 → 100644
View file @
ccb95004
# -*- coding: utf-8 -*-
from
lettuce
import
step
@step
(
u'Given the variable "([^"]*)" is equal to 2'
)
def
given_the_variable_group1_is_equal_to_2
(
step
,
group1
):
pass
@step
(
u'When the variable "([^"]*)" holds 10'
)
def
when_the_variable_group1_holds_10
(
step
,
group1
):
pass
@step
(
u'Then the variable "([^"]*)" times 5 is equal to 50'
)
def
then_the_variable_group1_times_5_is_equal_to_50
(
step
,
group1
):
pass
@step
(
u'And the variable "([^"]*)" is equal to 10'
)
def
and_the_variable_group1_is_equal_to_10
(
step
,
group1
):
pass
@step
(
u'Then the variable "([^"]*)" times 5 is equal to 10'
)
def
then_the_variable_group1_times_5_is_equal_to_10
(
step
,
group1
):
pass
@step
(
u'And the variable "([^"]*)" is equal to 2'
)
def
and_the_variable_group1_is_equal_to_2
(
step
,
group1
):
pass
tests/functional/test_runner.py
View file @
ccb95004
This diff is collapsed.
Click to expand it.
tests/unit/test_core.py
View file @
ccb95004
...
...
@@ -14,16 +14,16 @@
#
# 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
lettuce
import
core
from
sure
import
expect
from
nose.tools
import
assert_equals
from
nose.tools
import
assert_not_equals
STEP_WITH_TABLE
=
u'''
Given I have the following items in my shelf:
| name | description |
| Glass | a nice glass to drink grape juice |
| Pasta | a pasta to cook and eat with grape juice in the glass |
| name | description |
| Glass | a nice glass to drink grape juice |
| Pasta | a pasta to cook and eat with grape juice in the glass |
'''
...
...
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