Commit ca9a1a4b by Gabriel Falcão

starting to implement verbosity level 2

parent 9ca6bddd
...@@ -77,6 +77,8 @@ class Runner(object): ...@@ -77,6 +77,8 @@ class Runner(object):
if verbosity is 0: if verbosity is 0:
from lettuce.plugins import non_verbose as output from lettuce.plugins import non_verbose as output
elif verbosity is 2:
from lettuce.plugins import scenario_names as output
elif verbosity is 3: elif verbosity is 3:
from lettuce.plugins import shell_output as output from lettuce.plugins import shell_output as output
else: else:
......
...@@ -274,16 +274,16 @@ class Step(object): ...@@ -274,16 +274,16 @@ class Step(object):
self.defined_at = step_definition self.defined_at = step_definition
return matched, step_definition return matched, step_definition
def given(self, string): def given(self, string):
return self.behave_as(string) return self.behave_as(string)
def when(self, string): def when(self, string):
return self.behave_as(string) return self.behave_as(string)
def then(self, string): def then(self, string):
return self.behave_as(string) return self.behave_as(string)
def behave_as(self, string): def behave_as(self, string):
""" Parses and runs steps given in string form. """ Parses and runs steps given in string form.
...@@ -297,13 +297,13 @@ class Step(object): ...@@ -297,13 +297,13 @@ class Step(object):
@step('something defined elsewhere') @step('something defined elsewhere')
def elsewhere(step): def elsewhere(step):
# actual step behavior, maybe. # actual step behavior, maybe.
This will raise error (thus halting execution of the step) if a subordinate step fails. This will raise error (thus halting execution of the step) if a subordinate step fails.
""" """
lines = string.split('\n') lines = string.split('\n')
steps = self.many_from_lines(lines) steps = self.many_from_lines(lines)
(_, _, steps_failed, _, _) = self.run_all(steps) (_, _, steps_failed, _, _) = self.run_all(steps)
if not steps_failed: if not steps_failed:
self.passed = True self.passed = True
...@@ -329,25 +329,25 @@ class Step(object): ...@@ -329,25 +329,25 @@ class Step(object):
self.passed = True self.passed = True
return True return True
@staticmethod @staticmethod
def run_all(steps, outline = None, run_callbacks = False, ignore_case = True): def run_all(steps, outline = None, run_callbacks = False, ignore_case = True):
"""Runs each step in the given list of steps. """Runs each step in the given list of steps.
Returns a tuple of five lists: Returns a tuple of five lists:
- The full set of steps executed - The full set of steps executed
- The steps that passed - The steps that passed
- The steps that failed - The steps that failed
- The steps that were undefined - The steps that were undefined
- The reason for each failing step (indices matching per above) - The reason for each failing step (indices matching per above)
""" """
all_steps = [] all_steps = []
steps_passed = [] steps_passed = []
steps_failed = [] steps_failed = []
steps_undefined = [] steps_undefined = []
reasons_to_fail = [] reasons_to_fail = []
for step in steps: for step in steps:
if outline: if outline:
step = step.solve_and_clone(outline) step = step.solve_and_clone(outline)
...@@ -373,28 +373,28 @@ class Step(object): ...@@ -373,28 +373,28 @@ class Step(object):
all_steps.append(step) all_steps.append(step)
if run_callbacks: if run_callbacks:
call_hook('after_each', 'step', step) call_hook('after_each', 'step', step)
return (all_steps, steps_passed, steps_failed, steps_undefined, reasons_to_fail) return (all_steps, steps_passed, steps_failed, steps_undefined, reasons_to_fail)
@classmethod @classmethod
def many_from_lines(klass, lines, filename = None, original_string = None): def many_from_lines(klass, lines, filename = None, original_string = None):
"""Parses a set of steps from lines of input. """Parses a set of steps from lines of input.
This will correctly parse and produce a list of steps from lines without This will correctly parse and produce a list of steps from lines without
any Scenario: heading at the top. Examples in table form are correctly any Scenario: heading at the top. Examples in table form are correctly
parsed, but must be well-formed under a regular step sentence. parsed, but must be well-formed under a regular step sentence.
""" """
invalid_first_line_error = '\nFirst line of step "%(line)s" is in table form.' invalid_first_line_error = '\nFirst line of step "%(line)s" is in table form.'
if lines and strings.wise_startswith(lines[0], u'|'): if lines and strings.wise_startswith(lines[0], u'|'):
raise LettuceSyntaxError( raise LettuceSyntaxError(
None, None,
invalid_first_line_error % lines[0]) invalid_first_line_error % lines[0])
# Select only lines that aren't end-to-end whitespace # Select only lines that aren't end-to-end whitespace
only_whitspace = re.compile('^\s*$') only_whitspace = re.compile('^\s*$')
lines = filter(lambda x: not only_whitspace.match(x), lines) lines = filter(lambda x: not only_whitspace.match(x), lines)
step_strings = [] step_strings = []
for line in lines: for line in lines:
if strings.wise_startswith(line, u"|"): if strings.wise_startswith(line, u"|"):
...@@ -506,6 +506,14 @@ class Scenario(object): ...@@ -506,6 +506,14 @@ class Scenario(object):
yield (outline, steps) yield (outline, steps)
@property
def ran(self):
return all([step.ran for step in self.steps])
@property
def passed(self):
return self.ran and all([step.passed for step in self.steps])
def run(self, ignore_case): def run(self, ignore_case):
"""Runs a scenario, running each of its steps. Also call """Runs a scenario, running each of its steps. Also call
before_each and after_each callbacks for steps and scenario""" before_each and after_each callbacks for steps and scenario"""
......
...@@ -878,3 +878,19 @@ def test_output_snippets_with_normalized_unicode_names(): ...@@ -878,3 +878,19 @@ def test_output_snippets_with_normalized_unicode_names():
u"def entao_eu_fico_felizao(step):\n" u"def entao_eu_fico_felizao(step):\n"
u" assert False, 'This step must be implemented'\n" u" assert False, 'This step must be implemented'\n"
) )
@with_setup(prepare_stdout)
def test_output_level_2():
'Output with verbosity 2 must show only the scenario names, followed by "... OK" or "... FAIL" or "... ERROR"'
runner = Runner(join(abspath(dirname(__file__)), 'output_features', 'many_successful_scenarios'), verbosity=2)
runner.run()
assert_stdout_lines(
"Do nothing ... OK\n"
"Do nothing (again) ... OK\n"
"\n"
"1 feature (1 passed)\n"
"2 scenarios (2 passed)\n"
"2 steps (2 passed)\n"
)
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