-
Notifications
You must be signed in to change notification settings - Fork 638
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX #288: Use print function instead print statement in environment/steps files
- Loading branch information
Showing
6 changed files
with
175 additions
and
129 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
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 |
---|---|---|
@@ -1,121 +1,95 @@ | ||
@issue | ||
@only.with_python2=true | ||
Feature: Issue #288 -- print() needed in "environment.py" file or steps | ||
|
||
. QUICKFIX: Apply to your code base | ||
. pip install modernize | ||
. python-modernize --fix=libmodernize.fixes.fix_print my_directory/ # Shows only changes | ||
. python-modernize --fix=libmodernize.fixes.fix_print --write my_directory/ # Applies changes | ||
. | ||
. NOTE: Currently, the feature describes the implemented behaviour of behave. | ||
|
||
Background: Feature Setup | ||
Given a new working directory | ||
And a file named "features/steps/steps.py" with: | ||
""" | ||
from __future__ import unicode_literals | ||
from behave import step | ||
@step('{word:w} step passes') | ||
def step_passes(context, word): | ||
pass | ||
""" | ||
And a file named "features/e1.feature" with: | ||
""" | ||
Feature: | ||
Scenario: Alice | ||
Given a step passes | ||
Then another step passes | ||
Scenario: Bob | ||
Given some step passes | ||
""" | ||
Feature: Issue #288 -- Use print function instead print statement in environment/steps files | ||
|
||
. Loaded files have future flags of importing module "behave.runner". | ||
. This should be removed. | ||
. | ||
. AFFECTED FILES: | ||
. * features/environment.py | ||
. * features/steps/*.py | ||
. | ||
. AFFECTED FUTURE FLAGS: | ||
. * print_function | ||
. * absolute_import | ||
. * ... | ||
|
||
Scenario: Environment File Example | ||
Given a file named "features/environment.py" with: | ||
""" | ||
def before_all(context): | ||
print "HELLO @before_all" | ||
""" | ||
When I run "behave -f plain features" | ||
Then it should fail with: | ||
""" | ||
File "features/environment.py", line 2 | ||
print "HELLO @before_all" | ||
^ | ||
SyntaxError: invalid syntax | ||
""" | ||
|
||
Scenario: Module imported from environment file is unaffected | ||
Given a file named "features/environment.py" with: | ||
""" | ||
from __future__ import absolute_import, print_function | ||
from foo import hello | ||
def before_all(context): | ||
hello("@before_all") | ||
""" | ||
And a file named "foo.py" with: | ||
""" | ||
def hello(text): | ||
print "HELLO "+ text | ||
""" | ||
When I run "behave -f plain features" | ||
Then it should pass with: | ||
""" | ||
2 scenarios passed, 0 failed, 0 skipped | ||
3 steps passed, 0 failed, 0 skipped, 0 undefined | ||
""" | ||
@setup | ||
Scenario: Feature Setup | ||
Given a new working directory | ||
And a file named "features/steps/reuse_steps.py" with: | ||
""" | ||
from behave4cmd0 import passing_steps | ||
""" | ||
And a file named "features/passing.feature" with: | ||
""" | ||
Feature: | ||
Scenario: | ||
Given a step passes | ||
""" | ||
|
||
Scenario: Steps Example | ||
Given a file named "features/steps/print_steps.py" with: | ||
""" | ||
from __future__ import unicode_literals | ||
from behave import step | ||
@preferred | ||
Scenario: Use print function with future-statement in steps/environment (PY2, PY3) | ||
Given a file named "features/steps/my_steps.py" with: | ||
""" | ||
from __future__ import print_function | ||
print("Hello step") | ||
""" | ||
And a file named "features/environment.py" with: | ||
""" | ||
from __future__ import print_function | ||
print("Hello environment") | ||
""" | ||
When I run "behave -f plain features/passing.feature" | ||
Then it should pass with: | ||
""" | ||
1 scenario passed, 0 failed, 0 skipped | ||
1 step passed, 0 failed, 0 skipped, 0 undefined | ||
""" | ||
And the command output should not contain: | ||
""" | ||
Traceback (most recent call last): | ||
""" | ||
|
||
@step('I print "{text}"') | ||
def step_print(context, text): | ||
print "HELLO STEP "+ text | ||
""" | ||
When I run "behave -f plain features" | ||
Then it should fail with: | ||
""" | ||
File "features/steps/print_steps.py", line 6 | ||
print "HELLO STEP "+ text | ||
^ | ||
SyntaxError: invalid syntax | ||
""" | ||
@use.with_python2=true | ||
Scenario: Use python2 print keyword in steps/environment | ||
Given a file named "features/steps/my_steps.py" with: | ||
""" | ||
print "Hello step" | ||
""" | ||
And a file named "features/environment.py" with: | ||
""" | ||
print "Hello step" | ||
""" | ||
When I run "behave -f plain features/passing.feature" | ||
Then it should pass with: | ||
""" | ||
1 scenario passed, 0 failed, 0 skipped | ||
1 step passed, 0 failed, 0 skipped, 0 undefined | ||
""" | ||
And the command output should not contain "SyntaxError" | ||
And the command output should not contain: | ||
""" | ||
Traceback (most recent call last): | ||
""" | ||
|
||
Scenario: Step imports other module with print statement | ||
Given a file named "features/steps/print_steps2.py" with: | ||
""" | ||
from __future__ import unicode_literals | ||
from behave import step | ||
from bar import hello | ||
@use.with_python3=true | ||
Scenario: Use print function without future-statement in steps/environment (PY3) | ||
Given a file named "features/steps/my_steps.py" with: | ||
""" | ||
print("Hello step") | ||
""" | ||
And a file named "features/environment.py" with: | ||
""" | ||
print("Hello environment") | ||
""" | ||
When I run "behave -f plain features/passing.feature" | ||
Then it should pass with: | ||
""" | ||
1 scenario passed, 0 failed, 0 skipped | ||
1 step passed, 0 failed, 0 skipped, 0 undefined | ||
""" | ||
And the command output should not contain: | ||
""" | ||
Traceback (most recent call last): | ||
""" | ||
|
||
@step('I print "{text}"') | ||
def step_print(context, text): | ||
hello(text) | ||
""" | ||
And a file named "bar.py" with: | ||
""" | ||
def hello(text): | ||
print "HELLO "+ text | ||
""" | ||
And a file named "features/e2.feature" with: | ||
""" | ||
Feature: | ||
Scenario: Charly | ||
Given I print "Lorem ipsum" | ||
""" | ||
When I run "behave -f plain --no-capture features/e2.feature" | ||
Then it should pass with: | ||
""" | ||
1 scenario passed, 0 failed, 0 skipped | ||
1 step passed, 0 failed, 0 skipped, 0 undefined | ||
""" | ||
And the command output should contain: | ||
""" | ||
HELLO Lorem ipsum | ||
""" |
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,68 @@ | ||
@issue | ||
Feature: Issue #361 -- UTF-8 File with BOM | ||
|
||
. Using step files with "Byte-Order Mark" (BOM) prefix | ||
. causes weird problems. | ||
. | ||
. AFFECTED FILES: | ||
. * features/environment.py | ||
. * features/steps/*.py | ||
|
||
@setup | ||
Scenario: Feature Setup | ||
Given a new working directory | ||
And a file named "features/steps/reuse_steps.py" with: | ||
""" | ||
from behave4cmd0 import passing_steps | ||
""" | ||
And a file named "features/passing.feature" with: | ||
""" | ||
Feature: | ||
Scenario: | ||
Given a step passes | ||
Then a special step | ||
""" | ||
|
||
@encoding.<encoding> | ||
Scenario Outline: Use step file with <case> | ||
Given a file named "features/steps/my_steps.py" and encoding="<encoding>" with: | ||
""" | ||
# -*- coding: <encoding> -*- | ||
''' | ||
<text>. | ||
''' | ||
from behave import step | ||
@step(u'a special step') | ||
def step_impl(context): | ||
pass | ||
""" | ||
When I run "behave -f plain features/passing.feature" | ||
Then it should pass with: | ||
""" | ||
1 scenario passed, 0 failed, 0 skipped | ||
2 steps passed, 0 failed, 0 skipped, 0 undefined | ||
""" | ||
And the command output should contain: | ||
""" | ||
Feature: | ||
Scenario: | ||
Given a step passes ... passed | ||
Then a special step ... passed | ||
""" | ||
And the command output should not contain: | ||
""" | ||
SyntaxError: invalid character in identifier | ||
""" | ||
|
||
Examples: | ||
| encoding | text | case | Comment | | ||
| UTF-8-sig | Ärgernis ist überall | UTF-8 encoding and BOM | | | ||
| latin1 | Café | Latin1 encoding | | | ||
| iso-8859-1 | Ärgernis ist überall | iso-8859-1 encoding | Alias for latin1 | | ||
| cp1252 | Ärgernis ist überall | cp1252 encoding | Windows: Western Europe | | ||
| cp1251 | Привет! (=hello) | cp1251 encoding (Russia)| Windows: Russia | | ||
| cp866 | Привет! (=hello) | cp688 encoding (Russia) | IBM866: Russia | | ||
| euc_jp | こんにちは (=hello) | euc_jp encoding (Japan) | Japanese | | ||
| gbk | 您好 (=hello) | gbk encoding (China) | Unified Chinese | | ||
| gb2312 | 您好 (=hello) | gb2312 encoding (China) | Simplified Chinese | |
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