-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f38e57b
commit 79a2b86
Showing
5 changed files
with
219 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
This radish extension provides the functionality to write the feature file run to the console. | ||
""" | ||
|
||
from __future__ import unicode_literals | ||
from __future__ import print_function | ||
|
||
import sys | ||
import colorful as cf | ||
|
||
from radish.terrain import world | ||
from radish.hookregistry import before, after | ||
from radish.scenariooutline import ScenarioOutline | ||
from radish.scenarioloop import ScenarioLoop | ||
from radish.stepmodel import Step | ||
from radish.extensionregistry import extension | ||
|
||
|
||
@extension | ||
class DotOutputFormatter(object): | ||
""" | ||
Output formatter in the dot style. | ||
""" | ||
|
||
LOAD_IF = staticmethod(lambda config: config.formatter == "dots") | ||
LOAD_PRIORITY = 30 | ||
|
||
STATE_SYMBOLS = { | ||
Step.State.PASSED: ".", | ||
Step.State.PENDING: "P", | ||
Step.State.UNTESTED: "U", | ||
Step.State.SKIPPED: "S", | ||
Step.State.FAILED: "F", | ||
} | ||
|
||
def __init__(self): | ||
before.each_feature(self.dot_formatter_before_each_feature) | ||
after.each_feature(lambda *args, **kwargs: sys.stdout.write("\n")) | ||
after.each_scenario(self.dot_formatter_after_each_scenario) | ||
after.each_step(self.dot_formatter_after_each_step) | ||
after.all(self.dot_formatter_failure_summary) | ||
|
||
self._failed_steps = [] | ||
|
||
def dot_formatter_before_each_feature(self, feature): | ||
""" | ||
Writes feature header to the console | ||
:param Feature feature: the feature to write to the console | ||
""" | ||
output = cf.bold_black(feature.path) + ": " | ||
sys.stdout.write(str(output)) | ||
|
||
def dot_formatter_after_each_scenario(self, scenario): | ||
""" | ||
If the scenario is a ExampleScenario it will write the Examples header | ||
:param Scenario scenario: the scenario which was ran. | ||
""" | ||
if isinstance(scenario, (ScenarioOutline, ScenarioLoop)): | ||
return | ||
|
||
sys.stdout.write(self.STATE_SYMBOLS[scenario.state]) | ||
|
||
def dot_formatter_after_each_step(self, step): | ||
if step.state == Step.State.FAILED: | ||
self._failed_steps.append(step) | ||
|
||
def dot_formatter_failure_summary(self, features, marker): | ||
"""Output summary for failed Scenarios.""" | ||
if not self._failed_steps: | ||
return | ||
|
||
output = "\n" + cf.bold_red("Failures:") + "\n" | ||
|
||
for step in self._failed_steps: | ||
output += "{}: {}\n {}\n".format( | ||
step.path, step.parent.sentence, cf.red(step.sentence) | ||
) | ||
if world.config.with_traceback: | ||
output += " {}\n".format( | ||
"\n ".join( | ||
[ | ||
str(cf.red(l)) | ||
for l in step.failure.traceback.split("\n")[:-2] | ||
] | ||
) | ||
) | ||
output += " {}: {}\n\n".format( | ||
cf.bold_red(step.failure.name), cf.red(step.failure.reason) | ||
) | ||
|
||
sys.stdout.write(str(output) + "\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
@everything | ||
Feature: Everything in one Feature | ||
A feature file with everything in it. | ||
|
||
Background: A simple Background | ||
Given I have the number 5 | ||
And I have the number 3 | ||
|
||
@foo | ||
Scenario: Add numbers | ||
When I add them up | ||
Then I expect the sum to be 8 | ||
|
||
Scenario: Subtract numbers | ||
When I subtract them | ||
Then I expect the difference to be 2 | ||
|
||
@bad | ||
Scenario: Subtract numbers wrongly | ||
When I subtract them | ||
Then I expect the difference to be 3 | ||
|
||
Scenario Outline: A Scenario Outline | ||
Given I have the number <x> | ||
And I have the number <y> | ||
When I add them up | ||
Then I expect the sum to be <z> | ||
|
||
Examples: | ||
| x | y | z | | ||
| 1 | 2 | 3 | | ||
| 4 | 5 | 9 | | ||
|
||
Scenario Loop 2: This is a looped Scenario | ||
Given I have an instable function | ||
When I execute it | ||
Then I expect it to pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
[1m[30mfeatures/everything_with_failures.feature[22m[39m: ..FFF.. | ||
|
||
[1m[31mFailures:[22m[39m | ||
features/everything_with_failures.feature: Subtract numbers wrongly | ||
[31mThen I expect the difference to be 3[39m[26m | ||
[31mTraceback (most recent call last):[39m | ||
[31m File "/home/tuxtimo/work/radish/radish/stepmodel.py", line 117, in run[39m | ||
[31m self.definition_func(self, **kwargs) # pylint: disable=not-callable[39m | ||
[31m File "/home/tuxtimo/work/radish/tests/radish/steps.py", line 83, in expect_sum[39m | ||
[31m expected_diff.step.context.difference[39m | ||
[1m[31mAttributeError[22m[39m[26m: [31m'int' object has no attribute 'step'[39m[26m | ||
|
||
features/everything_with_failures.feature: A Scenario Outline - row 0 | ||
[31mThen I expect the sum to be 3[39m[26m | ||
[31mTraceback (most recent call last):[39m | ||
[31m File "/home/tuxtimo/work/radish/radish/stepmodel.py", line 117, in run[39m | ||
[31m self.definition_func(self, **kwargs) # pylint: disable=not-callable[39m | ||
[31m File "/home/tuxtimo/work/radish/tests/radish/steps.py", line 73, in expect_sum[39m | ||
[31m expected_sum, step.context.sum[39m | ||
[1m[31mAssertionError[22m[39m[26m: [31mThe expected sum 3 does not match actual sum 11[39m[26m | ||
|
||
features/everything_with_failures.feature: A Scenario Outline - row 1 | ||
[31mThen I expect the sum to be 9[39m[26m | ||
[31mTraceback (most recent call last):[39m | ||
[31m File "/home/tuxtimo/work/radish/radish/stepmodel.py", line 117, in run[39m | ||
[31m self.definition_func(self, **kwargs) # pylint: disable=not-callable[39m | ||
[31m File "/home/tuxtimo/work/radish/tests/radish/steps.py", line 73, in expect_sum[39m | ||
[31m expected_sum, step.context.sum[39m | ||
[1m[31mAssertionError[22m[39m[26m: [31mThe expected sum 9 does not match actual sum 17[39m[26m | ||
|
||
|
||
[1m[37m1 features ([22m[39m[1m[32m0 passed[22m[39m[1m[37m, [22m[39m[1m[31m1 failed[22m[39m[1m[37m)[22m[39m | ||
[1m[37m7 scenarios ([22m[39m[1m[32m4 passed[22m[39m[1m[37m, [22m[39m[1m[31m3 failed[22m[39m[1m[37m)[22m[39m | ||
[1m[37m20 steps ([22m[39m[1m[32m17 passed[22m[39m[1m[37m, [22m[39m[1m[31m3 failed[22m[39m[1m[37m)[22m[39m | ||
[36mRun test-marker finished within a moment[39m |