Commit ccb95004 by Gabriel Falcao

implementing basic output of backgrounds

parent b7ea4049
...@@ -15,13 +15,16 @@ ...@@ -15,13 +15,16 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import random as rand
import re import re
import codecs import codecs
from fuzzywuzzy import fuzz
import unicodedata import unicodedata
from itertools import chain
from copy import deepcopy from copy import deepcopy
from fuzzywuzzy import fuzz
from itertools import chain
from random import shuffle
from lettuce import strings from lettuce import strings
from lettuce import languages from lettuce import languages
from lettuce.fs import FileSystem from lettuce.fs import FileSystem
...@@ -181,6 +184,7 @@ class FeatureDescription(object): ...@@ -181,6 +184,7 @@ class FeatureDescription(object):
self.line = None self.line = None
described_at = [] described_at = []
description_lines = strings.get_stripped_lines(feature.description) description_lines = strings.get_stripped_lines(feature.description)
for pline, part in enumerate(lines): for pline, part in enumerate(lines):
part = part.strip() part = part.strip()
line = pline + 1 line = pline + 1
...@@ -205,6 +209,8 @@ class Step(object): ...@@ -205,6 +209,8 @@ class Step(object):
passed = None passed = None
failed = None failed = None
related_outline = None related_outline = None
scenario = None
background = None
def __init__(self, sentence, remaining_lines, line=None, filename=None): def __init__(self, sentence, remaining_lines, line=None, filename=None):
self.sentence = sentence self.sentence = sentence
...@@ -301,12 +307,17 @@ class Step(object): ...@@ -301,12 +307,17 @@ class Step(object):
return max_length return max_length
@property
def parent(self):
return self.scenario or self.background
def represent_string(self, string): def represent_string(self, string):
head = ' ' * self.indentation + string head = ' ' * self.indentation + string
where = self.described_at where = self.described_at
if self.defined_at: if self.defined_at:
where = 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): def represent_hashes(self):
lines = strings.dicts_to_string(self.hashes, self.keys).splitlines() lines = strings.dicts_to_string(self.hashes, self.keys).splitlines()
...@@ -834,17 +845,54 @@ class Scenario(object): ...@@ -834,17 +845,54 @@ class Scenario(object):
class Background(object): class Background(object):
indentation = 2
def __init__(self, lines, feature, def __init__(self, lines, feature,
with_file=None, with_file=None,
original_string=None, original_string=None,
language=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.feature = feature
self.original_string = original_string self.original_string = original_string
self.language = language self.language = language
def add_self_to_step(self, step):
step.background = self
return step
def run(self, ignore_case): 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 @classmethod
def from_string(new_background, def from_string(new_background,
...@@ -1065,7 +1113,7 @@ class Feature(object): ...@@ -1065,7 +1113,7 @@ class Feature(object):
scenarios_ran = [] scenarios_ran = []
if random: if random:
rand.shuffle(self.scenarios) shuffle(self.scenarios)
if isinstance(scenarios, (tuple, list)): if isinstance(scenarios, (tuple, list)):
if all(map(lambda x: isinstance(x, int), scenarios)): if all(map(lambda x: isinstance(x, int), scenarios)):
......
...@@ -52,6 +52,13 @@ def print_scenario_running(scenario): ...@@ -52,6 +52,13 @@ def print_scenario_running(scenario):
wrt(scenario.represented()) wrt(scenario.represented())
@before.each_background
def print_background_running(background):
wrt('\n')
wrt(background.represented())
wrt('\n')
@after.outline @after.outline
def print_outline(scenario, order, outline, reasons_to_fail): def print_outline(scenario, order, outline, reasons_to_fail):
table = strings.dicts_to_string(scenario.outlines, scenario.keys) table = strings.dicts_to_string(scenario.outlines, scenario.keys)
......
...@@ -54,6 +54,10 @@ CALLBACK_REGISTRY = CallbackDict( ...@@ -54,6 +54,10 @@ CALLBACK_REGISTRY = CallbackDict(
'after_each': [], 'after_each': [],
'outline': [], 'outline': [],
}, },
'background': {
'before_each': [],
'after_each': [],
},
'feature': { 'feature': {
'before_each': [], 'before_each': [],
'after_each': [], 'after_each': [],
......
...@@ -96,7 +96,7 @@ def getlen(string): ...@@ -96,7 +96,7 @@ def getlen(string):
def dicts_to_string(dicts, order): def dicts_to_string(dicts, order):
escape = "#{%s}" % str(time.time()) escape = "#{%s}" % unicode(time.time())
def enline(line): def enline(line):
return unicode(line).replace("|", escape) return unicode(line).replace("|", escape)
...@@ -133,7 +133,7 @@ def dicts_to_string(dicts, order): ...@@ -133,7 +133,7 @@ def dicts_to_string(dicts, order):
def parse_hashes(lines): def parse_hashes(lines):
escape = "#{%s}" % str(time.time()) escape = "#{%s}" % unicode(time.time())
def enline(line): def enline(line):
return unicode(line.replace("\\|", escape)).strip() return unicode(line.replace("\\|", escape)).strip()
......
...@@ -54,6 +54,7 @@ for name, where, when in ( ...@@ -54,6 +54,7 @@ for name, where, when in (
('all', 'all', '%(0)s'), ('all', 'all', '%(0)s'),
('each_step', 'step', '%(0)s_each'), ('each_step', 'step', '%(0)s_each'),
('each_scenario', 'scenario', '%(0)s_each'), ('each_scenario', 'scenario', '%(0)s_each'),
('each_background', 'background', '%(0)s_each'),
('each_feature', 'feature', '%(0)s_each'), ('each_feature', 'feature', '%(0)s_each'),
('harvest', 'harvest', '%(0)s'), ('harvest', 'harvest', '%(0)s'),
('each_app', 'app', '%(0)s_each'), ('each_app', 'app', '%(0)s_each'),
......
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
# -*- 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
...@@ -70,17 +70,17 @@ def test_try_to_import_terrain(): ...@@ -70,17 +70,17 @@ def test_try_to_import_terrain():
raise AssertionError('The runner should raise ImportError !') raise AssertionError('The runner should raise ImportError !')
except SystemExit: except SystemExit:
assert_stderr_lines_with_traceback( assert_stderr_lines_with_traceback(
'Lettuce has tried to load the conventional environment module ' \ 'Lettuce has tried to load the conventional environment module '
'"terrain"\nbut it has errors, check its contents and ' \ '"terrain"\nbut it has errors, check its contents and '
'try to run lettuce again.\n\nOriginal traceback below:\n\n' \ 'try to run lettuce again.\n\nOriginal traceback below:\n\n'
"Traceback (most recent call last):\n" "Traceback (most recent call last):\n"
' File "%(lettuce_core_file)s", line 44, in <module>\n' ' File "%(lettuce_core_file)s", line 44, in <module>\n'
' terrain = fs.FileSystem._import("terrain")\n' \ ' terrain = fs.FileSystem._import("terrain")\n'
' File "%(lettuce_fs_file)s", line 63, in _import\n' \ ' File "%(lettuce_fs_file)s", line 63, in _import\n'
' module = imp.load_module(name, fp, pathname, description)\n' \ ' module = imp.load_module(name, fp, pathname, description)\n'
' File "%(terrain_file)s", line 18\n' \ ' File "%(terrain_file)s", line 18\n'
' it is here just to cause a syntax error\n' \ ' it is here just to cause a syntax error\n'
" ^\n" \ " ^\n"
'SyntaxError: invalid syntax\n' % { 'SyntaxError: invalid syntax\n' % {
'lettuce_core_file': abspath(join(lettuce_dir, '__init__.py')), 'lettuce_core_file': abspath(join(lettuce_dir, '__init__.py')),
'lettuce_fs_file': abspath(join(lettuce_dir, 'fs.py')), 'lettuce_fs_file': abspath(join(lettuce_dir, 'fs.py')),
...@@ -91,6 +91,7 @@ def test_try_to_import_terrain(): ...@@ -91,6 +91,7 @@ def test_try_to_import_terrain():
finally: finally:
os.chdir(original_path) os.chdir(original_path)
def test_feature_representation_without_colors(): def test_feature_representation_without_colors():
"Feature represented without colors" "Feature represented without colors"
feature_file = ojoin('..', 'simple_features', '1st_feature_dir', 'some.feature') feature_file = ojoin('..', 'simple_features', '1st_feature_dir', 'some.feature')
...@@ -104,6 +105,7 @@ def test_feature_representation_without_colors(): ...@@ -104,6 +105,7 @@ def test_feature_representation_without_colors():
" I want to be told the sum of two numbers # tests/functional/simple_features/1st_feature_dir/some.feature:8\n" " I want to be told the sum of two numbers # tests/functional/simple_features/1st_feature_dir/some.feature:8\n"
) )
def test_scenario_outline_representation_without_colors(): def test_scenario_outline_representation_without_colors():
"Scenario Outline represented without colors" "Scenario Outline represented without colors"
feature_file = ojoin('..', 'simple_features', '1st_feature_dir', 'some.feature') feature_file = ojoin('..', 'simple_features', '1st_feature_dir', 'some.feature')
...@@ -114,6 +116,7 @@ def test_scenario_outline_representation_without_colors(): ...@@ -114,6 +116,7 @@ def test_scenario_outline_representation_without_colors():
" Scenario Outline: Add two numbers # tests/functional/simple_features/1st_feature_dir/some.feature:10\n" " Scenario Outline: Add two numbers # tests/functional/simple_features/1st_feature_dir/some.feature:10\n"
) )
def test_scenario_representation_without_colors(): def test_scenario_representation_without_colors():
"Scenario represented without colors" "Scenario represented without colors"
feature_file = ojoin('runner_features', 'first.feature') feature_file = ojoin('runner_features', 'first.feature')
...@@ -124,6 +127,7 @@ def test_scenario_representation_without_colors(): ...@@ -124,6 +127,7 @@ def test_scenario_representation_without_colors():
" Scenario: Do nothing # tests/functional/output_features/runner_features/first.feature:6\n" " Scenario: Do nothing # tests/functional/output_features/runner_features/first.feature:6\n"
) )
def test_undefined_step_represent_string(): def test_undefined_step_represent_string():
"Undefined step represented without colors" "Undefined step represented without colors"
feature_file = ojoin('runner_features', 'first.feature') feature_file = ojoin('runner_features', 'first.feature')
...@@ -140,6 +144,7 @@ def test_undefined_step_represent_string(): ...@@ -140,6 +144,7 @@ def test_undefined_step_represent_string():
" foo bar # tests/functional/output_features/runner_features/first.feature:7\n" " foo bar # tests/functional/output_features/runner_features/first.feature:7\n"
) )
def test_defined_step_represent_string(): def test_defined_step_represent_string():
"Defined step represented without colors" "Defined step represented without colors"
feature_file = ojoin('runner_features', 'first.feature') feature_file = ojoin('runner_features', 'first.feature')
...@@ -158,8 +163,9 @@ def test_defined_step_represent_string(): ...@@ -158,8 +163,9 @@ def test_defined_step_represent_string():
" Given I do nothing # tests/functional/output_features/runner_features/dumb_steps.py:6\n" " Given I do nothing # tests/functional/output_features/runner_features/dumb_steps.py:6\n"
) )
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
def test_output_with_success_colorless(): def test_output_with_success_colorless2():
"Testing the colorless output of a successful feature" "Testing the colorless output of a successful feature"
runner = Runner(join(abspath(dirname(__file__)), 'output_features', 'runner_features'), verbosity=3) runner = Runner(join(abspath(dirname(__file__)), 'output_features', 'runner_features'), verbosity=3)
...@@ -180,6 +186,7 @@ def test_output_with_success_colorless(): ...@@ -180,6 +186,7 @@ def test_output_with_success_colorless():
"1 step (1 passed)\n" "1 step (1 passed)\n"
) )
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
def test_output_with_success_colorless(): def test_output_with_success_colorless():
"A feature with two scenarios should separate the two scenarios with a new line (in colorless mode)." "A feature with two scenarios should separate the two scenarios with a new line (in colorless mode)."
...@@ -205,6 +212,7 @@ def test_output_with_success_colorless(): ...@@ -205,6 +212,7 @@ def test_output_with_success_colorless():
"2 steps (2 passed)\n" "2 steps (2 passed)\n"
) )
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
def test_output_with_success_colorful(): def test_output_with_success_colorful():
"Testing the output of a successful feature" "Testing the output of a successful feature"
...@@ -213,21 +221,22 @@ def test_output_with_success_colorful(): ...@@ -213,21 +221,22 @@ def test_output_with_success_colorful():
runner.run() runner.run()
assert_stdout_lines( assert_stdout_lines(
"\n" \ "\n"
"\033[1;37mFeature: Dumb feature \033[1;30m# tests/functional/output_features/runner_features/first.feature:1\033[0m\n" \ "\033[1;37mFeature: Dumb feature \033[1;30m# tests/functional/output_features/runner_features/first.feature:1\033[0m\n"
"\033[1;37m In order to test success \033[1;30m# tests/functional/output_features/runner_features/first.feature:2\033[0m\n" \ "\033[1;37m In order to test success \033[1;30m# tests/functional/output_features/runner_features/first.feature:2\033[0m\n"
"\033[1;37m As a programmer \033[1;30m# tests/functional/output_features/runner_features/first.feature:3\033[0m\n" \ "\033[1;37m As a programmer \033[1;30m# tests/functional/output_features/runner_features/first.feature:3\033[0m\n"
"\033[1;37m I want to see that the output is green \033[1;30m# tests/functional/output_features/runner_features/first.feature:4\033[0m\n" \ "\033[1;37m I want to see that the output is green \033[1;30m# tests/functional/output_features/runner_features/first.feature:4\033[0m\n"
"\n" \ "\n"
"\033[1;37m Scenario: Do nothing \033[1;30m# tests/functional/output_features/runner_features/first.feature:6\033[0m\n" \ "\033[1;37m Scenario: Do nothing \033[1;30m# tests/functional/output_features/runner_features/first.feature:6\033[0m\n"
"\033[1;30m Given I do nothing \033[1;30m# tests/functional/output_features/runner_features/dumb_steps.py:6\033[0m\n" \ "\033[1;30m Given I do nothing \033[1;30m# tests/functional/output_features/runner_features/dumb_steps.py:6\033[0m\n"
"\033[A\033[1;32m Given I do nothing \033[1;30m# tests/functional/output_features/runner_features/dumb_steps.py:6\033[0m\n" \ "\033[A\033[1;32m Given I do nothing \033[1;30m# tests/functional/output_features/runner_features/dumb_steps.py:6\033[0m\n"
"\n" \ "\n"
"\033[1;37m1 feature (\033[1;32m1 passed\033[1;37m)\033[0m\n" \ "\033[1;37m1 feature (\033[1;32m1 passed\033[1;37m)\033[0m\n"
"\033[1;37m1 scenario (\033[1;32m1 passed\033[1;37m)\033[0m\n" \ "\033[1;37m1 scenario (\033[1;32m1 passed\033[1;37m)\033[0m\n"
"\033[1;37m1 step (\033[1;32m1 passed\033[1;37m)\033[0m\n" "\033[1;37m1 step (\033[1;32m1 passed\033[1;37m)\033[0m\n"
) )
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
def test_output_with_success_colorful_newline(): def test_output_with_success_colorful_newline():
"A feature with two scenarios should separate the two scenarios with a new line (in color mode)." "A feature with two scenarios should separate the two scenarios with a new line (in color mode)."
...@@ -236,25 +245,26 @@ def test_output_with_success_colorful_newline(): ...@@ -236,25 +245,26 @@ def test_output_with_success_colorful_newline():
runner.run() runner.run()
assert_stdout_lines( assert_stdout_lines(
"\n" \ "\n"
"\033[1;37mFeature: Dumb feature \033[1;30m# tests/functional/output_features/many_successful_scenarios/first.feature:1\033[0m\n" \ "\033[1;37mFeature: Dumb feature \033[1;30m# tests/functional/output_features/many_successful_scenarios/first.feature:1\033[0m\n"
"\033[1;37m In order to test success \033[1;30m# tests/functional/output_features/many_successful_scenarios/first.feature:2\033[0m\n" \ "\033[1;37m In order to test success \033[1;30m# tests/functional/output_features/many_successful_scenarios/first.feature:2\033[0m\n"
"\033[1;37m As a programmer \033[1;30m# tests/functional/output_features/many_successful_scenarios/first.feature:3\033[0m\n" \ "\033[1;37m As a programmer \033[1;30m# tests/functional/output_features/many_successful_scenarios/first.feature:3\033[0m\n"
"\033[1;37m I want to see that the output is green \033[1;30m# tests/functional/output_features/many_successful_scenarios/first.feature:4\033[0m\n" \ "\033[1;37m I want to see that the output is green \033[1;30m# tests/functional/output_features/many_successful_scenarios/first.feature:4\033[0m\n"
"\n" \ "\n"
"\033[1;37m Scenario: Do nothing \033[1;30m# tests/functional/output_features/many_successful_scenarios/first.feature:6\033[0m\n" \ "\033[1;37m Scenario: Do nothing \033[1;30m# tests/functional/output_features/many_successful_scenarios/first.feature:6\033[0m\n"
"\033[1;30m Given I do nothing \033[1;30m# tests/functional/output_features/many_successful_scenarios/dumb_steps.py:6\033[0m\n" \ "\033[1;30m Given I do nothing \033[1;30m# tests/functional/output_features/many_successful_scenarios/dumb_steps.py:6\033[0m\n"
"\033[A\033[1;32m Given I do nothing \033[1;30m# tests/functional/output_features/many_successful_scenarios/dumb_steps.py:6\033[0m\n" \ "\033[A\033[1;32m Given I do nothing \033[1;30m# tests/functional/output_features/many_successful_scenarios/dumb_steps.py:6\033[0m\n"
"\n" \ "\n"
"\033[1;37m Scenario: Do nothing (again) \033[1;30m# tests/functional/output_features/many_successful_scenarios/first.feature:9\033[0m\n" \ "\033[1;37m Scenario: Do nothing (again) \033[1;30m# tests/functional/output_features/many_successful_scenarios/first.feature:9\033[0m\n"
"\033[1;30m Given I do nothing (again) \033[1;30m# tests/functional/output_features/many_successful_scenarios/dumb_steps.py:6\033[0m\n" \ "\033[1;30m Given I do nothing (again) \033[1;30m# tests/functional/output_features/many_successful_scenarios/dumb_steps.py:6\033[0m\n"
"\033[A\033[1;32m Given I do nothing (again) \033[1;30m# tests/functional/output_features/many_successful_scenarios/dumb_steps.py:6\033[0m\n" \ "\033[A\033[1;32m Given I do nothing (again) \033[1;30m# tests/functional/output_features/many_successful_scenarios/dumb_steps.py:6\033[0m\n"
"\n" \ "\n"
"\033[1;37m1 feature (\033[1;32m1 passed\033[1;37m)\033[0m\n" \ "\033[1;37m1 feature (\033[1;32m1 passed\033[1;37m)\033[0m\n"
"\033[1;37m2 scenarios (\033[1;32m2 passed\033[1;37m)\033[0m\n" \ "\033[1;37m2 scenarios (\033[1;32m2 passed\033[1;37m)\033[0m\n"
"\033[1;37m2 steps (\033[1;32m2 passed\033[1;37m)\033[0m\n" "\033[1;37m2 steps (\033[1;32m2 passed\033[1;37m)\033[0m\n"
) )
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
def test_output_with_success_colorless_many_features(): def test_output_with_success_colorless_many_features():
"Testing the output of many successful features" "Testing the output of many successful features"
...@@ -284,6 +294,7 @@ def test_output_with_success_colorless_many_features(): ...@@ -284,6 +294,7 @@ def test_output_with_success_colorless_many_features():
"4 steps (4 passed)\n" "4 steps (4 passed)\n"
) )
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
def test_output_with_success_colorful_many_features(): def test_output_with_success_colorful_many_features():
"Testing the colorful output of many successful features" "Testing the colorful output of many successful features"
...@@ -313,11 +324,12 @@ def test_output_with_success_colorful_many_features(): ...@@ -313,11 +324,12 @@ def test_output_with_success_colorful_many_features():
"\033[1;30m Then I see that the test passes \033[1;30m# tests/functional/output_features/many_successful_features/dumb_steps.py:8\033[0m\n" "\033[1;30m Then I see that the test passes \033[1;30m# tests/functional/output_features/many_successful_features/dumb_steps.py:8\033[0m\n"
"\033[A\033[1;32m Then I see that the test passes \033[1;30m# tests/functional/output_features/many_successful_features/dumb_steps.py:8\033[0m\n" "\033[A\033[1;32m Then I see that the test passes \033[1;30m# tests/functional/output_features/many_successful_features/dumb_steps.py:8\033[0m\n"
"\n" "\n"
"\033[1;37m2 features (\033[1;32m2 passed\033[1;37m)\033[0m\n" \ "\033[1;37m2 features (\033[1;32m2 passed\033[1;37m)\033[0m\n"
"\033[1;37m2 scenarios (\033[1;32m2 passed\033[1;37m)\033[0m\n" \ "\033[1;37m2 scenarios (\033[1;32m2 passed\033[1;37m)\033[0m\n"
"\033[1;37m4 steps (\033[1;32m4 passed\033[1;37m)\033[0m\n" "\033[1;37m4 steps (\033[1;32m4 passed\033[1;37m)\033[0m\n"
) )
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
def test_output_when_could_not_find_features(): def test_output_when_could_not_find_features():
"Testing the colorful output of many successful features" "Testing the colorful output of many successful features"
...@@ -331,6 +343,7 @@ def test_output_when_could_not_find_features(): ...@@ -331,6 +343,7 @@ def test_output_when_could_not_find_features():
'\033[1;37mcould not find features at \033[1;33m./%s\033[0m\n' % path '\033[1;37mcould not find features at \033[1;33m./%s\033[0m\n' % path
) )
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
def test_output_when_could_not_find_features_colorless(): def test_output_when_could_not_find_features_colorless():
"Testing the colorful output of many successful features colorless" "Testing the colorful output of many successful features colorless"
...@@ -344,6 +357,7 @@ def test_output_when_could_not_find_features_colorless(): ...@@ -344,6 +357,7 @@ def test_output_when_could_not_find_features_colorless():
'could not find features at ./%s\n' % path 'could not find features at ./%s\n' % path
) )
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
def test_output_when_could_not_find_features_verbosity_level_2(): def test_output_when_could_not_find_features_verbosity_level_2():
"Testing the colorful output of many successful features colorless" "Testing the colorful output of many successful features colorless"
...@@ -357,6 +371,7 @@ def test_output_when_could_not_find_features_verbosity_level_2(): ...@@ -357,6 +371,7 @@ def test_output_when_could_not_find_features_verbosity_level_2():
'could not find features at ./%s\n' % path 'could not find features at ./%s\n' % path
) )
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
def test_output_with_success_colorless_with_table(): def test_output_with_success_colorless_with_table():
"Testing the colorless output of success with table" "Testing the colorless output of success with table"
...@@ -385,6 +400,7 @@ def test_output_with_success_colorless_with_table(): ...@@ -385,6 +400,7 @@ def test_output_with_success_colorless_with_table():
'5 steps (5 passed)\n' '5 steps (5 passed)\n'
) )
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
def test_output_with_success_colorful_with_table(): def test_output_with_success_colorful_with_table():
"Testing the colorful output of success with table" "Testing the colorful output of success with table"
...@@ -418,11 +434,12 @@ def test_output_with_success_colorful_with_table(): ...@@ -418,11 +434,12 @@ def test_output_with_success_colorful_with_table():
'\033[1;32m \033[1;37m |\033[1;32m name \033[1;37m |\033[1;32m price \033[1;37m |\033[1;32m\033[0m\n' '\033[1;32m \033[1;37m |\033[1;32m name \033[1;37m |\033[1;32m price \033[1;37m |\033[1;32m\033[0m\n'
'\033[1;32m \033[1;37m |\033[1;32m Porsche\033[1;37m |\033[1;32m 200000\033[1;37m |\033[1;32m\033[0m\n' '\033[1;32m \033[1;37m |\033[1;32m Porsche\033[1;37m |\033[1;32m 200000\033[1;37m |\033[1;32m\033[0m\n'
'\n' '\n'
"\033[1;37m1 feature (\033[1;32m1 passed\033[1;37m)\033[0m\n" \ "\033[1;37m1 feature (\033[1;32m1 passed\033[1;37m)\033[0m\n"
"\033[1;37m1 scenario (\033[1;32m1 passed\033[1;37m)\033[0m\n" \ "\033[1;37m1 scenario (\033[1;32m1 passed\033[1;37m)\033[0m\n"
"\033[1;37m5 steps (\033[1;32m5 passed\033[1;37m)\033[0m\n" "\033[1;37m5 steps (\033[1;32m5 passed\033[1;37m)\033[0m\n"
) )
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
def test_output_with_failed_colorless_with_table(): def test_output_with_failed_colorless_with_table():
"Testing the colorless output of failed with table" "Testing the colorless output of failed with table"
...@@ -461,10 +478,11 @@ def test_output_with_failed_colorless_with_table(): ...@@ -461,10 +478,11 @@ def test_output_with_failed_colorless_with_table():
" assert False, 'This step must be implemented'\n") % { " assert False, 'This step must be implemented'\n") % {
'lettuce_core_file': lettuce_path('core.py'), 'lettuce_core_file': lettuce_path('core.py'),
'step_file': abspath(lettuce_path('..', 'tests', 'functional', 'output_features', 'failed_table', 'failed_table_steps.py')), 'step_file': abspath(lettuce_path('..', 'tests', 'functional', 'output_features', 'failed_table', 'failed_table_steps.py')),
'call_line':call_line, 'call_line': call_line,
} }
) )
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
def test_output_with_failed_colorful_with_table(): def test_output_with_failed_colorful_with_table():
"Testing the colorful output of failed with table" "Testing the colorful output of failed with table"
...@@ -508,10 +526,11 @@ def test_output_with_failed_colorful_with_table(): ...@@ -508,10 +526,11 @@ def test_output_with_failed_colorful_with_table():
"\n" % { "\n" % {
'lettuce_core_file': lettuce_path('core.py'), 'lettuce_core_file': lettuce_path('core.py'),
'step_file': abspath(lettuce_path('..', 'tests', 'functional', 'output_features', 'failed_table', 'failed_table_steps.py')), 'step_file': abspath(lettuce_path('..', 'tests', 'functional', 'output_features', 'failed_table', 'failed_table_steps.py')),
'call_line':call_line, 'call_line': call_line,
} }
) )
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
def test_output_with_successful_outline_colorless(): def test_output_with_successful_outline_colorless():
"With colorless output, a successful outline scenario should print beautifully." "With colorless output, a successful outline scenario should print beautifully."
...@@ -547,6 +566,7 @@ def test_output_with_successful_outline_colorless(): ...@@ -547,6 +566,7 @@ def test_output_with_successful_outline_colorless():
'24 steps (24 passed)\n' '24 steps (24 passed)\n'
) )
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
def test_output_with_successful_outline_colorful(): def test_output_with_successful_outline_colorful():
"With colored output, a successful outline scenario should print beautifully." "With colored output, a successful outline scenario should print beautifully."
...@@ -577,11 +597,12 @@ def test_output_with_successful_outline_colorful(): ...@@ -577,11 +597,12 @@ def test_output_with_successful_outline_colorful():
'\033[1;32m \033[1;37m |\033[1;32m mary \033[1;37m |\033[1;32m wee-9876\033[1;37m |\033[1;32m mary@email.com\033[1;37m |\033[1;32m Mary \| My Website\033[1;37m |\033[1;32m\033[0m\n' '\033[1;32m \033[1;37m |\033[1;32m mary \033[1;37m |\033[1;32m wee-9876\033[1;37m |\033[1;32m mary@email.com\033[1;37m |\033[1;32m Mary \| My Website\033[1;37m |\033[1;32m\033[0m\n'
'\033[1;32m \033[1;37m |\033[1;32m foo \033[1;37m |\033[1;32m foo-bar \033[1;37m |\033[1;32m foo@bar.com \033[1;37m |\033[1;32m Foo \| My Website \033[1;37m |\033[1;32m\033[0m\n' '\033[1;32m \033[1;37m |\033[1;32m foo \033[1;37m |\033[1;32m foo-bar \033[1;37m |\033[1;32m foo@bar.com \033[1;37m |\033[1;32m Foo \| My Website \033[1;37m |\033[1;32m\033[0m\n'
'\n' '\n'
"\033[1;37m1 feature (\033[1;32m1 passed\033[1;37m)\033[0m\n" \ "\033[1;37m1 feature (\033[1;32m1 passed\033[1;37m)\033[0m\n"
"\033[1;37m3 scenarios (\033[1;32m3 passed\033[1;37m)\033[0m\n" \ "\033[1;37m3 scenarios (\033[1;32m3 passed\033[1;37m)\033[0m\n"
"\033[1;37m24 steps (\033[1;32m24 passed\033[1;37m)\033[0m\n" "\033[1;37m24 steps (\033[1;32m24 passed\033[1;37m)\033[0m\n"
) )
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
def test_output_with_failful_outline_colorless(): def test_output_with_failful_outline_colorless():
"With colorless output, an unsuccessful outline scenario should print beautifully." "With colorless output, an unsuccessful outline scenario should print beautifully."
...@@ -623,10 +644,11 @@ def test_output_with_failful_outline_colorless(): ...@@ -623,10 +644,11 @@ def test_output_with_failful_outline_colorless():
'24 steps (1 failed, 4 skipped, 19 passed)\n' % { '24 steps (1 failed, 4 skipped, 19 passed)\n' % {
'lettuce_core_file': lettuce_path('core.py'), 'lettuce_core_file': lettuce_path('core.py'),
'step_file': abspath(lettuce_path('..', 'tests', 'functional', 'output_features', 'fail_outline', 'fail_outline_steps.py')), 'step_file': abspath(lettuce_path('..', 'tests', 'functional', 'output_features', 'fail_outline', 'fail_outline_steps.py')),
'call_line':call_line, 'call_line': call_line,
} }
) )
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
def test_output_with_failful_outline_colorful(): def test_output_with_failful_outline_colorful():
"With colored output, an unsuccessful outline scenario should print beautifully." "With colored output, an unsuccessful outline scenario should print beautifully."
...@@ -663,41 +685,43 @@ def test_output_with_failful_outline_colorful(): ...@@ -663,41 +685,43 @@ def test_output_with_failful_outline_colorful():
" AssertionError\033[0m\n" " AssertionError\033[0m\n"
'\033[1;32m \033[1;37m |\033[1;32m foo \033[1;37m |\033[1;32m foo-bar \033[1;37m |\033[1;32m foo@bar.com \033[1;37m |\033[1;32m Welcome, Foo \033[1;37m |\033[1;32m\033[0m\n' '\033[1;32m \033[1;37m |\033[1;32m foo \033[1;37m |\033[1;32m foo-bar \033[1;37m |\033[1;32m foo@bar.com \033[1;37m |\033[1;32m Welcome, Foo \033[1;37m |\033[1;32m\033[0m\n'
'\n' '\n'
"\033[1;37m1 feature (\033[0;31m0 passed\033[1;37m)\033[0m\n" \ "\033[1;37m1 feature (\033[0;31m0 passed\033[1;37m)\033[0m\n"
"\033[1;37m3 scenarios (\033[1;32m2 passed\033[1;37m)\033[0m\n" \ "\033[1;37m3 scenarios (\033[1;32m2 passed\033[1;37m)\033[0m\n"
"\033[1;37m24 steps (\033[0;31m1 failed\033[1;37m, \033[0;36m4 skipped\033[1;37m, \033[1;32m19 passed\033[1;37m)\033[0m\n" % { "\033[1;37m24 steps (\033[0;31m1 failed\033[1;37m, \033[0;36m4 skipped\033[1;37m, \033[1;32m19 passed\033[1;37m)\033[0m\n" % {
'lettuce_core_file': lettuce_path('core.py'), 'lettuce_core_file': lettuce_path('core.py'),
'step_file': abspath(lettuce_path('..', 'tests', 'functional', 'output_features', 'fail_outline', 'fail_outline_steps.py')), 'step_file': abspath(lettuce_path('..', 'tests', 'functional', 'output_features', 'fail_outline', 'fail_outline_steps.py')),
'call_line':call_line, 'call_line': call_line,
} }
) )
@with_setup(prepare_stderr)
def test_many_features_a_file():
"syntax checking: Fail if a file has more than one feature"
filename = syntax_feature_name('many_features_a_file') # @with_setup(prepare_stderr)
runner = Runner(filename) # def test_many_features_a_file():
assert_raises(SystemExit, runner.run) # "syntax checking: Fail if a file has more than one feature"
assert_stderr_lines( # filename = syntax_feature_name('many_features_a_file')
'Syntax error at: %s\n' # runner = Runner(filename)
'A feature file must contain ONLY ONE feature!\n' % filename # assert_raises(SystemExit, runner.run)
)
@with_setup(prepare_stderr) # assert_stderr_lines(
def test_feature_without_name(): # 'Syntax error at: %s\n'
"syntax checking: Fail on features without name" # 'A feature file must contain ONLY ONE feature!\n' % filename
# )
filename = syntax_feature_name('feature_without_name')
runner = Runner(filename)
assert_raises(SystemExit, runner.run)
assert_stderr_lines( # @with_setup(prepare_stderr)
'Syntax error at: %s\n' # def test_feature_without_name():
'Features must have a name. e.g: "Feature: This is my name"\n' # "syntax checking: Fail on features without name"
% filename
) # filename = syntax_feature_name('feature_without_name')
# runner = Runner(filename)
# assert_raises(SystemExit, runner.run)
# assert_stderr_lines(
# 'Syntax error at: %s\n'
# 'Features must have a name. e.g: "Feature: This is my name"\n'
# % filename
# )
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
...@@ -728,6 +752,7 @@ def test_output_snippets_with_groups_within_double_quotes_colorless(): ...@@ -728,6 +752,7 @@ def test_output_snippets_with_groups_within_double_quotes_colorless():
u' assert False, \'This step must be implemented\'\n' u' assert False, \'This step must be implemented\'\n'
) )
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
def test_output_snippets_with_groups_within_double_quotes_colorful(): def test_output_snippets_with_groups_within_double_quotes_colorful():
"Testing that the proposed snippet is clever enough to identify groups within double quotes. colorful" "Testing that the proposed snippet is clever enough to identify groups within double quotes. colorful"
...@@ -742,8 +767,8 @@ def test_output_snippets_with_groups_within_double_quotes_colorful(): ...@@ -742,8 +767,8 @@ def test_output_snippets_with_groups_within_double_quotes_colorful():
u'\033[1;37m Scenario: Propose matched groups \033[1;30m# tests/functional/output_features/double-quoted-snippet/double-quoted-snippet.feature:2\033[0m\n' u'\033[1;37m Scenario: Propose matched groups \033[1;30m# tests/functional/output_features/double-quoted-snippet/double-quoted-snippet.feature:2\033[0m\n'
u'\033[0;33m Given I have "stuff here" and "more @#$%ˆ& bizar sutff h3r3" \033[1;30m# tests/functional/output_features/double-quoted-snippet/double-quoted-snippet.feature:3\033[0m\n' u'\033[0;33m Given I have "stuff here" and "more @#$%ˆ& bizar sutff h3r3" \033[1;30m# tests/functional/output_features/double-quoted-snippet/double-quoted-snippet.feature:3\033[0m\n'
u'\n' u'\n'
"\033[1;37m1 feature (\033[0;31m0 passed\033[1;37m)\033[0m\n" \ "\033[1;37m1 feature (\033[0;31m0 passed\033[1;37m)\033[0m\n"
"\033[1;37m1 scenario (\033[0;31m0 passed\033[1;37m)\033[0m\n" \ "\033[1;37m1 scenario (\033[0;31m0 passed\033[1;37m)\033[0m\n"
"\033[1;37m1 step (\033[0;33m1 undefined\033[1;37m, \033[1;32m0 passed\033[1;37m)\033[0m\n" "\033[1;37m1 step (\033[0;33m1 undefined\033[1;37m, \033[1;32m0 passed\033[1;37m)\033[0m\n"
u'\n' u'\n'
u'\033[0;33mYou can implement step definitions for undefined steps with these snippets:\n' u'\033[0;33mYou can implement step definitions for undefined steps with these snippets:\n'
...@@ -785,6 +810,7 @@ def test_output_snippets_with_groups_within_single_quotes_colorless(): ...@@ -785,6 +810,7 @@ def test_output_snippets_with_groups_within_single_quotes_colorless():
u' assert False, \'This step must be implemented\'\n' u' assert False, \'This step must be implemented\'\n'
) )
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
def test_output_snippets_with_groups_within_single_quotes_colorful(): def test_output_snippets_with_groups_within_single_quotes_colorful():
"Testing that the proposed snippet is clever enough to identify groups within single quotes. colorful" "Testing that the proposed snippet is clever enough to identify groups within single quotes. colorful"
...@@ -799,8 +825,8 @@ def test_output_snippets_with_groups_within_single_quotes_colorful(): ...@@ -799,8 +825,8 @@ def test_output_snippets_with_groups_within_single_quotes_colorful():
u'\033[1;37m Scenario: Propose matched groups \033[1;30m# tests/functional/output_features/single-quoted-snippet/single-quoted-snippet.feature:2\033[0m\n' u'\033[1;37m Scenario: Propose matched groups \033[1;30m# tests/functional/output_features/single-quoted-snippet/single-quoted-snippet.feature:2\033[0m\n'
u'\033[0;33m Given I have \'stuff here\' and \'more @#$%ˆ& bizar sutff h3r3\' \033[1;30m# tests/functional/output_features/single-quoted-snippet/single-quoted-snippet.feature:3\033[0m\n' u'\033[0;33m Given I have \'stuff here\' and \'more @#$%ˆ& bizar sutff h3r3\' \033[1;30m# tests/functional/output_features/single-quoted-snippet/single-quoted-snippet.feature:3\033[0m\n'
u'\n' u'\n'
"\033[1;37m1 feature (\033[0;31m0 passed\033[1;37m)\033[0m\n" \ "\033[1;37m1 feature (\033[0;31m0 passed\033[1;37m)\033[0m\n"
"\033[1;37m1 scenario (\033[0;31m0 passed\033[1;37m)\033[0m\n" \ "\033[1;37m1 scenario (\033[0;31m0 passed\033[1;37m)\033[0m\n"
"\033[1;37m1 step (\033[0;33m1 undefined\033[1;37m, \033[1;32m0 passed\033[1;37m)\033[0m\n" "\033[1;37m1 step (\033[0;33m1 undefined\033[1;37m, \033[1;32m0 passed\033[1;37m)\033[0m\n"
u'\n' u'\n'
u'\033[0;33mYou can implement step definitions for undefined steps with these snippets:\n' u'\033[0;33mYou can implement step definitions for undefined steps with these snippets:\n'
...@@ -813,6 +839,7 @@ def test_output_snippets_with_groups_within_single_quotes_colorful(): ...@@ -813,6 +839,7 @@ def test_output_snippets_with_groups_within_single_quotes_colorful():
u' assert False, \'This step must be implemented\'\033[0m\n' u' assert False, \'This step must be implemented\'\033[0m\n'
) )
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
def test_output_snippets_with_groups_within_redundant_quotes(): def test_output_snippets_with_groups_within_redundant_quotes():
"Testing that the proposed snippet is clever enough to avoid duplicating the same snippet" "Testing that the proposed snippet is clever enough to avoid duplicating the same snippet"
...@@ -842,6 +869,7 @@ def test_output_snippets_with_groups_within_redundant_quotes(): ...@@ -842,6 +869,7 @@ def test_output_snippets_with_groups_within_redundant_quotes():
u' assert False, \'This step must be implemented\'\n' u' assert False, \'This step must be implemented\'\n'
) )
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
def test_output_snippets_with_normalized_unicode_names(): def test_output_snippets_with_normalized_unicode_names():
"Testing that the proposed snippet is clever enough normalize method names even with latin accents" "Testing that the proposed snippet is clever enough normalize method names even with latin accents"
...@@ -881,6 +909,7 @@ def test_output_snippets_with_normalized_unicode_names(): ...@@ -881,6 +909,7 @@ def test_output_snippets_with_normalized_unicode_names():
u" assert False, 'This step must be implemented'\n" u" assert False, 'This step must be implemented'\n"
) )
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
def test_output_level_2_success(): def test_output_level_2_success():
'Output with verbosity 2 must show only the scenario names, followed by "... OK" in case of success' 'Output with verbosity 2 must show only the scenario names, followed by "... OK" in case of success'
...@@ -897,6 +926,7 @@ def test_output_level_2_success(): ...@@ -897,6 +926,7 @@ def test_output_level_2_success():
"2 steps (2 passed)\n" "2 steps (2 passed)\n"
) )
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
def test_output_level_2_fail(): def test_output_level_2_fail():
'Output with verbosity 2 must show only the scenario names, followed by "... FAILED" in case of fail' 'Output with verbosity 2 must show only the scenario names, followed by "... FAILED" in case of fail'
...@@ -919,10 +949,11 @@ def test_output_level_2_fail(): ...@@ -919,10 +949,11 @@ def test_output_level_2_fail():
"5 steps (1 failed, 2 skipped, 1 undefined, 1 passed)\n" % { "5 steps (1 failed, 2 skipped, 1 undefined, 1 passed)\n" % {
'lettuce_core_file': lettuce_path('core.py'), 'lettuce_core_file': lettuce_path('core.py'),
'step_file': abspath(lettuce_path('..', 'tests', 'functional', 'output_features', 'failed_table', 'failed_table_steps.py')), 'step_file': abspath(lettuce_path('..', 'tests', 'functional', 'output_features', 'failed_table', 'failed_table_steps.py')),
'call_line':call_line, 'call_line': call_line,
} }
) )
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
def test_output_level_2_error(): def test_output_level_2_error():
'Output with verbosity 2 must show only the scenario names, followed by "... ERROR" in case of fail' 'Output with verbosity 2 must show only the scenario names, followed by "... ERROR" in case of fail'
...@@ -946,10 +977,11 @@ def test_output_level_2_error(): ...@@ -946,10 +977,11 @@ def test_output_level_2_error():
"2 steps (1 failed, 1 passed)\n" % { "2 steps (1 failed, 1 passed)\n" % {
'lettuce_core_file': lettuce_path('core.py'), 'lettuce_core_file': lettuce_path('core.py'),
'step_file': abspath(lettuce_path('..', 'tests', 'functional', 'output_features', 'error_traceback', 'error_traceback_steps.py')), 'step_file': abspath(lettuce_path('..', 'tests', 'functional', 'output_features', 'error_traceback', 'error_traceback_steps.py')),
'call_line':call_line, 'call_line': call_line,
} }
) )
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
def test_output_level_1_success(): def test_output_level_1_success():
'Output with verbosity 2 must show only the scenario names, followed by "... OK" in case of success' 'Output with verbosity 2 must show only the scenario names, followed by "... OK" in case of success'
...@@ -965,6 +997,7 @@ def test_output_level_1_success(): ...@@ -965,6 +997,7 @@ def test_output_level_1_success():
"2 steps (2 passed)\n" "2 steps (2 passed)\n"
) )
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
def test_output_level_1_fail(): def test_output_level_1_fail():
'Output with verbosity 2 must show only the scenario names, followed by "... FAILED" in case of fail' 'Output with verbosity 2 must show only the scenario names, followed by "... FAILED" in case of fail'
...@@ -987,10 +1020,11 @@ def test_output_level_1_fail(): ...@@ -987,10 +1020,11 @@ def test_output_level_1_fail():
"5 steps (1 failed, 2 skipped, 1 undefined, 1 passed)\n" % { "5 steps (1 failed, 2 skipped, 1 undefined, 1 passed)\n" % {
'lettuce_core_file': lettuce_path('core.py'), 'lettuce_core_file': lettuce_path('core.py'),
'step_file': abspath(lettuce_path('..', 'tests', 'functional', 'output_features', 'failed_table', 'failed_table_steps.py')), 'step_file': abspath(lettuce_path('..', 'tests', 'functional', 'output_features', 'failed_table', 'failed_table_steps.py')),
'call_line':call_line, 'call_line': call_line,
} }
) )
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
def test_output_level_1_error(): def test_output_level_1_error():
'Output with verbosity 2 must show only the scenario names, followed by "... ERROR" in case of fail' 'Output with verbosity 2 must show only the scenario names, followed by "... ERROR" in case of fail'
...@@ -1013,10 +1047,11 @@ def test_output_level_1_error(): ...@@ -1013,10 +1047,11 @@ def test_output_level_1_error():
"2 steps (1 failed, 1 passed)\n" % { "2 steps (1 failed, 1 passed)\n" % {
'lettuce_core_file': lettuce_path('core.py'), 'lettuce_core_file': lettuce_path('core.py'),
'step_file': abspath(lettuce_path('..', 'tests', 'functional', 'output_features', 'error_traceback', 'error_traceback_steps.py')), 'step_file': abspath(lettuce_path('..', 'tests', 'functional', 'output_features', 'error_traceback', 'error_traceback_steps.py')),
'call_line':call_line, 'call_line': call_line,
} }
) )
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
def test_commented_scenario(): def test_commented_scenario():
'Test one commented scenario' 'Test one commented scenario'
...@@ -1033,7 +1068,6 @@ def test_commented_scenario(): ...@@ -1033,7 +1068,6 @@ def test_commented_scenario():
) )
#with_setup(prepare_stderr)
@with_setup(prepare_stdout) @with_setup(prepare_stdout)
def test_blank_step_hash_value(): def test_blank_step_hash_value():
"syntax checking: Blank in step hash column = empty string" "syntax checking: Blank in step hash column = empty string"
...@@ -1041,13 +1075,13 @@ def test_blank_step_hash_value(): ...@@ -1041,13 +1075,13 @@ def test_blank_step_hash_value():
from lettuce import step from lettuce import step
@step('ignore step') @step('ignore step')
def append_2_more(step): def ignore_step(step):
pass pass
@step('string length calc') @step('string length calc')
def append_2_more(step): def string_lenth_calc(step):
for hash in step.hashes: for hash in step.hashes:
if len(hash["string"])+len(hash["string2"]) != int(hash["length"]): if len(hash["string"]) + len(hash["string2"]) != int(hash["length"]):
raise AssertionError("fail") raise AssertionError("fail")
filename = syntax_feature_name('blank_values_in_hash') filename = syntax_feature_name('blank_values_in_hash')
...@@ -1137,7 +1171,7 @@ def test_background_with_header(): ...@@ -1137,7 +1171,7 @@ def test_background_with_header():
runner.run() runner.run()
assert_stdout_lines( assert_stdout_lines(
"......." "........."
"\n" "\n"
"1 feature (1 passed)\n" "1 feature (1 passed)\n"
"2 scenarios (2 passed)\n" "2 scenarios (2 passed)\n"
...@@ -1149,7 +1183,20 @@ def test_background_with_header(): ...@@ -1149,7 +1183,20 @@ def test_background_with_header():
def test_background_without_header(): def test_background_without_header():
"Running background without header" "Running background without header"
from lettuce import step, world from lettuce import step, world, before, after
actions = {}
@before.each_background
def register_background_before(background):
actions['before'] = unicode(background)
@after.each_background
def register_background_after(background, results):
actions['after'] = {
'background': unicode(background),
'results': results,
}
@step(ur'the variable "(\w+)" holds (\d+)') @step(ur'the variable "(\w+)" holds (\d+)')
def set_variable(step, name, value): def set_variable(step, name, value):
...@@ -1171,9 +1218,52 @@ def test_background_without_header(): ...@@ -1171,9 +1218,52 @@ def test_background_without_header():
runner.run() runner.run()
assert_stdout_lines( assert_stdout_lines(
"......." "........."
"\n" "\n"
"1 feature (1 passed)\n" "1 feature (1 passed)\n"
"2 scenarios (2 passed)\n" "2 scenarios (2 passed)\n"
"7 steps (7 passed)\n" "7 steps (7 passed)\n"
) )
expect(actions).to.equal({
'after': {
'results': [True],
'background': u'<Background for feature: Without Header>'
},
'before': u'<Background for feature: Without Header>'
})
@with_setup(prepare_stdout)
def test_output_background_with_success_colorless():
"A feature with background should print it accordingly"
from lettuce import step
@step(ur'the variable "(\w+)" holds (\d+)')
@step(ur'the variable "(\w+)" is equal to (\d+)')
def just_pass(step, *args):
pass
filename = bg_feature_name('simple')
runner = Runner(filename, verbosity=3)
runner.run()
assert_stdout_lines(
'\n'
'Feature: Simple and successful # tests/functional/bg_features/simple/simple.feature:1\n'
' As the Lettuce maintainer # tests/functional/bg_features/simple/simple.feature:2\n'
' In order to make sure the output is pretty # tests/functional/bg_features/simple/simple.feature:3\n'
' I want to automate its test # tests/functional/bg_features/simple/simple.feature:4\n'
'\n'
' Background:\n'
' Given the variable "X" holds 2 # tests/functional/test_runner.py:1244\n'
'\n'
' Scenario: multiplication changing the value # tests/functional/bg_features/simple/simple.feature:9\n'
' Given the variable "X" is equal to 2 # tests/functional/test_runner.py:1244\n'
'\n'
'1 feature (1 passed)\n'
'1 scenario (1 passed)\n'
'1 step (1 passed)\n'
)
...@@ -14,16 +14,16 @@ ...@@ -14,16 +14,16 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from lettuce import core from lettuce import core
from sure import expect
from nose.tools import assert_equals from nose.tools import assert_equals
from nose.tools import assert_not_equals from nose.tools import assert_not_equals
STEP_WITH_TABLE = u''' STEP_WITH_TABLE = u'''
Given I have the following items in my shelf: Given I have the following items in my shelf:
| name | description | | name | description |
| Glass | a nice glass to drink grape juice | | Glass | a nice glass to drink grape juice |
| Pasta | a pasta to cook and eat with grape juice in the glass | | Pasta | a pasta to cook and eat with grape juice in the glass |
''' '''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment