Commit 8d0b0f09 by Gabriel Falcão

finished to write the test of colored failed output

parent fefb3160
...@@ -49,11 +49,31 @@ def print_step_ran(step): ...@@ -49,11 +49,31 @@ def print_step_ran(step):
write_out("\033[A" * (len(step.data_list) + 1)) write_out("\033[A" * (len(step.data_list) + 1))
string = step.represent_string(step.sentence) string = step.represent_string(step.sentence)
string = wrap_file_and_line(string, '\033[1;30m', '\033[0m') string = wrap_file_and_line(string, '\033[1;30m', '\033[0m')
write_out("\033[A\033[1;32m%s" % string)
if step.failed:
color = "\033[0;31m"
else:
color = "\033[1;32m"
write_out("\033[A%s%s" % (color, string))
if step.data_list: if step.data_list:
for line in step.represent_data_list().splitlines(): for line in step.represent_data_list().splitlines():
write_out("\033[1;32m%s\033[0m\n" % line) write_out("%s%s\033[0m\n" % (color, line))
if step.failed:
sys.stdout.write(color)
pspaced = lambda x: sys.stdout.write("%s%s" % (" " * step.indentation, x))
lines = step.why.traceback.splitlines()
for pindex, line in enumerate(lines):
pspaced(line)
if pindex + 1 < len(lines):
sys.stdout.write("\n")
sys.stdout.write("\033[0m\n")
@before.each_scenario @before.each_scenario
def print_scenario_running(scenario): def print_scenario_running(scenario):
......
...@@ -20,47 +20,50 @@ import sys ...@@ -20,47 +20,50 @@ import sys
from lettuce.terrain import after from lettuce.terrain import after
from lettuce.terrain import before from lettuce.terrain import before
def wrt(what):
sys.stdout.write(what)
@before.each_step @before.each_step
def print_step_running(step): def print_step_running(step):
sys.stdout.write(step.represent_string(step.sentence)) wrt(step.represent_string(step.sentence))
if step.data_list: if step.data_list:
sys.stdout.write(step.represent_data_list()) wrt(step.represent_data_list())
@after.each_step @after.each_step
def print_step_ran(step): def print_step_ran(step):
if step.data_list: if step.data_list:
sys.stdout.write("\033[A" * (len(step.data_list) + 1)) wrt("\033[A" * (len(step.data_list) + 1))
if step.defined_at: if step.defined_at:
sys.stdout.write("\033[A" + step.represent_string(step.sentence)) wrt("\033[A" + step.represent_string(step.sentence))
else: else:
sys.stdout.write(step.represent_string(step.sentence).rstrip() + " (undefined)\n") wrt(step.represent_string(step.sentence).rstrip() + " (undefined)\n")
if step.data_list: if step.data_list:
sys.stdout.write(step.represent_data_list()) wrt(step.represent_data_list())
if step.failed: if step.failed:
print_spaced = lambda x: sys.stdout.write("%s%s\n" % (" " * step.indentation, x)) print_spaced = lambda x: wrt("%s%s\n" % (" " * step.indentation, x))
for line in step.why.traceback.splitlines(): for line in step.why.traceback.splitlines():
print_spaced(line) print_spaced(line)
@before.each_scenario @before.each_scenario
def print_scenario_running(scenario): def print_scenario_running(scenario):
sys.stdout.write(scenario.represented()) wrt(scenario.represented())
@before.each_feature @before.each_feature
def print_feature_running(feature): def print_feature_running(feature):
sys.stdout.write("\n") wrt("\n")
sys.stdout.write(feature.represented()) wrt(feature.represented())
sys.stdout.write("\n") wrt("\n")
@after.all @after.all
def print_end(total): def print_end(total):
sys.stdout.write("\n") wrt("\n")
word = total.features_ran > 1 and "features" or "feature" word = total.features_ran > 1 and "features" or "feature"
sys.stdout.write("%d %s (%d passed)\n" % ( wrt("%d %s (%d passed)\n" % (
total.features_ran, total.features_ran,
word, word,
total.features_passed total.features_passed
...@@ -68,7 +71,7 @@ def print_end(total): ...@@ -68,7 +71,7 @@ def print_end(total):
) )
word = total.scenarios_ran > 1 and "scenarios" or "scenario" word = total.scenarios_ran > 1 and "scenarios" or "scenario"
sys.stdout.write("%d %s (%d passed)\n" % ( wrt("%d %s (%d passed)\n" % (
total.scenarios_ran, total.scenarios_ran,
word, word,
total.scenarios_passed total.scenarios_passed
...@@ -86,7 +89,7 @@ def print_end(total): ...@@ -86,7 +89,7 @@ def print_end(total):
steps_details.append("%d passed" % total.steps_passed) steps_details.append("%d passed" % total.steps_passed)
word = total.steps > 1 and "steps" or "step" word = total.steps > 1 and "steps" or "step"
sys.stdout.write("%d %s (%s)\n" % ( wrt("%d %s (%s)\n" % (
total.steps, total.steps,
word, word,
", ".join(steps_details) ", ".join(steps_details)
...@@ -94,21 +97,21 @@ def print_end(total): ...@@ -94,21 +97,21 @@ def print_end(total):
) )
if total.proposed_definitions: if total.proposed_definitions:
sys.stdout.write("\nYou can implement step definitions for undefined steps with these snippets:\n\n") wrt("\nYou can implement step definitions for undefined steps with these snippets:\n\n")
sys.stdout.write("from lettuce import step\n\n") wrt("from lettuce import step\n\n")
for step in total.proposed_definitions: for step in total.proposed_definitions:
method_name = "_".join(re.findall("\w+", step.sentence)).lower() method_name = "_".join(re.findall("\w+", step.sentence)).lower()
sys.stdout.write("@step(r'%s')\n" % re.escape(step.sentence).replace(r'\ ', ' ')) wrt("@step(r'%s')\n" % re.escape(step.sentence).replace(r'\ ', ' '))
sys.stdout.write("def %s(step):\n" % method_name) wrt("def %s(step):\n" % method_name)
sys.stdout.write(" pass\n") wrt(" pass\n")
def print_no_features_found(where): def print_no_features_found(where):
where = os.path.relpath(where) where = os.path.relpath(where)
if not where.startswith(os.sep): if not where.startswith(os.sep):
where = '.%s%s' % (os.sep, where) where = '.%s%s' % (os.sep, where)
sys.stdout.write('Oops!\n') wrt('Oops!\n')
sys.stdout.write( wrt(
'could not find features at ' 'could not find features at '
'%s\n' % where '%s\n' % where
) )
......
...@@ -417,3 +417,49 @@ def test_output_with_failed_colorless_with_table(): ...@@ -417,3 +417,49 @@ def test_output_with_failed_colorless_with_table():
'step_file': '/Users/gabriel.falcao/Projetos/lettuce/tests/functional/output_features/failed_table/failed_table_steps.py' 'step_file': '/Users/gabriel.falcao/Projetos/lettuce/tests/functional/output_features/failed_table/failed_table_steps.py'
} }
) )
@with_setup(prepare_stdout)
def test_output_with_failed_colorful_with_table():
"Testing the colorful output of failed with table"
runner = Runner(feature_name('failed_table'), verbosity=4)
runner.run()
assert_stdout_lines(
"\n"
"\033[1;37mFeature: Table Fail \033[1;30m# tests/functional/output_features/failed_table/failed_table.feature:1\033[0m\n"
"\n"
"\033[1;37m Scenario: See it fail \033[1;30m# tests/functional/output_features/failed_table/failed_table.feature:2\033[0m\n"
"\033[1;30m Given I have a dumb step that passes \033[1;30m# tests/functional/output_features/failed_table/failed_table_steps.py:20\033[0m\n"
"\033[A\033[1;32m Given I have a dumb step that passes \033[1;30m# tests/functional/output_features/failed_table/failed_table_steps.py:20\033[0m\n"
"\033[1;30m And this one fails \033[1;30m# tests/functional/output_features/failed_table/failed_table_steps.py:24\033[0m\n"
"\033[A\033[0;31m And this one fails \033[1;30m# tests/functional/output_features/failed_table/failed_table_steps.py:24\033[0m\n"
"\033[0;31m Traceback (most recent call last):\n"
' File "%(lettuce_core_file)s", line 54, in __call__\n'
" ret = self.function(self.step, *args, **kw)\n"
' File "%(step_file)s", line 25, in tof\n'
" assert False\n"
" AssertionError\033[0m\n"
"\033[1;30m Then this one will be skipped \033[1;30m# tests/functional/output_features/failed_table/failed_table_steps.py:28\033[0m\n"
"\033[A\033[0;36m Then this one will be skipped \033[1;30m# tests/functional/output_features/failed_table/failed_table_steps.py:28\033[0m\n"
"\033[1;30m And this one will be skipped \033[1;30m# tests/functional/output_features/failed_table/failed_table_steps.py:28\033[1;30m\n"
"\033[A\033[1;36m And this one will be skipped \033[1;30m# tests/functional/output_features/failed_table/failed_table_steps.py:28\033[0m\n"
"\033[0;33m And this one does not even has definition \033[1;30m# tests/functional/output_features/failed_table/failed_table.feature:12\033[0m\n"
"\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;37m5 steps (\033[0;31m1 failed\033[1;37m, \033[0;36mm2 skipped\033[1;37m, \033[0;33m1 undefined\033[1;37m, \033[1;32m1 passed\033[1;37m)\033[0m\n"
"\n"
"\033[0;33mYou can implement step definitions for undefined steps with these snippets:\n"
"\n"
"from lettuce import step\n"
"\n"
"@step(r'And this one does not even has definition')\n"
"def and_this_one_does_not_even_has_definition(step):\n"
" pass\n"
"\033[0m" % {
'lettuce_core_file':'/Users/gabriel.falcao/Projetos/lettuce/lettuce/core.py',
'step_file': '/Users/gabriel.falcao/Projetos/lettuce/tests/functional/output_features/failed_table/failed_table_steps.py'
}
)
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