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
d80542cd
Commit
d80542cd
authored
Dec 14, 2010
by
Gabriel Falcão
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
supporting comments
parent
7218ea0a
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
110 additions
and
4 deletions
+110
-4
lettuce/core.py
+4
-2
lettuce/strings.py
+9
-2
tests/functional/output_features/commented_feature/commented_feature.feature
+7
-0
tests/functional/output_features/commented_feature/simple-steps.py
+9
-0
tests/functional/test_runner.py
+15
-0
tests/unit/test_feature_parser.py
+23
-0
tests/unit/test_scenario_parsing.py
+27
-0
tests/unit/test_strings.py
+16
-0
No files found.
lettuce/core.py
View file @
d80542cd
...
@@ -602,6 +602,8 @@ class Scenario(object):
...
@@ -602,6 +602,8 @@ class Scenario(object):
@classmethod
@classmethod
def
from_string
(
new_scenario
,
string
,
with_file
=
None
,
original_string
=
None
,
language
=
None
):
def
from_string
(
new_scenario
,
string
,
with_file
=
None
,
original_string
=
None
,
language
=
None
):
""" Creates a new scenario from string"""
""" Creates a new scenario from string"""
# ignoring comments
string
=
"
\n
"
.
join
(
strings
.
get_stripped_lines
(
string
,
ignore_lines_starting_with
=
'#'
))
if
not
language
:
if
not
language
:
language
=
Language
()
language
=
Language
()
...
@@ -700,11 +702,11 @@ class Feature(object):
...
@@ -700,11 +702,11 @@ class Feature(object):
@classmethod
@classmethod
def
from_string
(
new_feature
,
string
,
with_file
=
None
,
language
=
None
):
def
from_string
(
new_feature
,
string
,
with_file
=
None
,
language
=
None
):
"""Creates a new feature from string"""
"""Creates a new feature from string"""
lines
=
strings
.
get_stripped_lines
(
string
)
lines
=
strings
.
get_stripped_lines
(
string
,
ignore_lines_starting_with
=
'#'
)
if
not
language
:
if
not
language
:
language
=
Language
()
language
=
Language
()
found
=
len
(
re
.
findall
(
r'
%
s:[ ]*\w+'
%
language
.
feature
,
string
))
found
=
len
(
re
.
findall
(
r'
%
s:[ ]*\w+'
%
language
.
feature
,
"
\n
"
.
join
(
lines
)
))
if
found
>
1
:
if
found
>
1
:
raise
LettuceSyntaxError
(
raise
LettuceSyntaxError
(
...
...
lettuce/strings.py
View file @
d80542cd
...
@@ -25,10 +25,17 @@ def escape_if_necessary(what):
...
@@ -25,10 +25,17 @@ def escape_if_necessary(what):
return
what
return
what
def
get_stripped_lines
(
string
):
def
get_stripped_lines
(
string
,
ignore_lines_starting_with
=
''
):
string
=
unicode
(
string
)
string
=
unicode
(
string
)
lines
=
[
unicode
(
l
.
strip
())
for
l
in
string
.
splitlines
()]
lines
=
[
unicode
(
l
.
strip
())
for
l
in
string
.
splitlines
()]
return
filter
(
lambda
x
:
x
,
lines
)
if
ignore_lines_starting_with
:
filter_func
=
lambda
x
:
x
and
not
x
.
startswith
(
ignore_lines_starting_with
)
else
:
filter_func
=
lambda
x
:
x
lines
=
filter
(
filter_func
,
lines
)
return
lines
def
split_wisely
(
string
,
sep
,
strip
=
False
):
def
split_wisely
(
string
,
sep
,
strip
=
False
):
string
=
unicode
(
string
)
string
=
unicode
(
string
)
...
...
tests/functional/output_features/commented_feature/commented_feature.feature
0 → 100644
View file @
d80542cd
Feature
:
one commented scenario
Scenario
:
Do
nothing
Given
I do nothing
# Scenario: Do something
# Given I do something
# Then I see that the test passes
tests/functional/output_features/commented_feature/simple-steps.py
0 → 100644
View file @
d80542cd
# -*- coding: utf-8 -*-
from
lettuce
import
step
@step
(
u'Given I do nothing'
)
def
given_i_do_nothing
(
step
):
pass
@step
(
u'Then I see that the test passes'
)
def
then_i_see_that_the_test_passes
(
step
):
pass
tests/functional/test_runner.py
View file @
d80542cd
...
@@ -1028,3 +1028,18 @@ def test_output_level_1_error():
...
@@ -1028,3 +1028,18 @@ def test_output_level_1_error():
}
}
)
)
@with_setup
(
prepare_stdout
)
def
test_commented_scenario
():
'Test one commented scenario'
runner
=
Runner
(
feature_name
(
'commented_feature'
),
verbosity
=
1
)
runner
.
run
()
assert_stdout_lines
(
"."
"
\n
"
"1 feature (1 passed)
\n
"
"1 scenario (1 passed)
\n
"
"1 step (1 passed)
\n
"
)
tests/unit/test_feature_parser.py
View file @
d80542cd
...
@@ -130,6 +130,24 @@ Feature: Big scenario outline
...
@@ -130,6 +130,24 @@ Feature: Big scenario outline
| 3 |
| 3 |
"""
"""
FEATURE10
=
"""
Feature: Big sentence
As a clever guy
I want to describe this Feature
So that I can take care of my Scenario
Scenario: Regular numbers
Given a huge sentence, that have so many characters
And another one, very tiny
# Feature: Big sentence
# As a clever guy
# I want to describe this Feature
# So that I can take care of my Scenario
# Scenario: Regular numbers
# Given a huge sentence, that have so many characters
# And another one, very tiny
"""
def
test_feature_has_repr
():
def
test_feature_has_repr
():
"Feature implements __repr__ nicely"
"Feature implements __repr__ nicely"
...
@@ -283,3 +301,8 @@ def test_description_on_big_sentenced_steps():
...
@@ -283,3 +301,8 @@ def test_description_on_big_sentenced_steps():
"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
)
tests/unit/test_scenario_parsing.py
View file @
d80542cd
...
@@ -139,6 +139,27 @@ Scenario Outline: Add two numbers
...
@@ -139,6 +139,27 @@ Scenario Outline: Add two numbers
| 12 | 40 | add | 52 |
| 12 | 40 | add | 52 |
"""
"""
COMMENTED_SCENARIO
=
"""
Scenario: Adding some students to my university database
Given I have the following courses in my university:
| Name | Duration |
| Computer Science | 5 years |
| Nutrition | 4 years |
When I consolidate the database into 'courses.txt'
Then I see the 1st line of 'courses.txt' has 'Computer Science:5'
And I see the 2nd line of 'courses.txt' has 'Nutrition:4'
# Scenario: Adding some students to my university database
# Given I have the following courses in my university:
# | Name | Duration |
# | Computer Science | 5 years |
# | Nutrition | 4 years |
# When I consolidate the database into 'courses.txt'
# Then I see the 1st line of 'courses.txt' has 'Computer Science:5'
# And I see the 2nd line of 'courses.txt' has 'Nutrition:4'
"""
from
lettuce.core
import
Step
from
lettuce.core
import
Step
from
lettuce.core
import
Scenario
from
lettuce.core
import
Scenario
from
lettuce.core
import
Feature
from
lettuce.core
import
Feature
...
@@ -370,3 +391,9 @@ def test_scenario_aggregate_all_examples_blocks():
...
@@ -370,3 +391,9 @@ def test_scenario_aggregate_all_examples_blocks():
{
'input_1'
:
'12'
,
'input_2'
:
'40'
,
'button'
:
'add'
,
'output'
:
'52'
},
{
'input_1'
:
'12'
,
'input_2'
:
'40'
,
'button'
:
'add'
,
'output'
:
'52'
},
]
]
)
)
def
test_commented_scenarios
():
"A scenario string that contains lines starting with '#' will be commented"
scenario
=
Scenario
.
from_string
(
COMMENTED_SCENARIO
)
assert_equals
(
scenario
.
name
,
u'Adding some students to my university database'
)
assert_equals
(
len
(
scenario
.
steps
),
4
)
tests/unit/test_strings.py
View file @
d80542cd
...
@@ -49,6 +49,22 @@ def test_get_stripped_lines():
...
@@ -49,6 +49,22 @@ def test_get_stripped_lines():
]
]
)
)
def
test_get_stripped_lines_ignore_comments
():
"strings.get_stripped_lines ignore lines that start with some char"
my_string
=
'''
first line
# second line
'''
assert_equals
(
strings
.
get_stripped_lines
(
my_string
,
ignore_lines_starting_with
=
"#"
),
[
'first line'
,
]
)
def
test_split_wisely_splits_ignoring_case
():
def
test_split_wisely_splits_ignoring_case
():
"strings.split_wisely splits ignoring case"
"strings.split_wisely splits ignoring case"
my_string
=
'first line
\n
'
\
my_string
=
'first line
\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