| 1 |
Feature: Internationalization (i18n) and Problems with Unicode Strings |
| 2 |
|
| 3 |
. POTENTIAL PROBLEM AREAS: |
| 4 |
. * Feature, scenario, step names with problematic chars |
| 5 |
. * Tags with problematic chars |
| 6 |
. * step raises exception with problematic text (output capture) |
| 7 |
. * step generates output with problematic and some step fails (stdout capture) |
| 8 |
. * filenames with problematic chars: feature files, steps files |
| 9 |
. |
| 10 |
. CHECKED FORMATTERS and REPORTERS: |
| 11 |
. * plain |
| 12 |
. * pretty |
| 13 |
. * junit (used via "behave.ini" defaults) |
| 14 |
|
| 15 |
|
| 16 |
@setup |
| 17 |
Scenario: Feature Setup |
| 18 |
Given a new working directory |
| 19 |
And a file named "behave.ini" with: |
| 20 |
""" |
| 21 |
[behave] |
| 22 |
show_timings = false |
| 23 |
show_skipped = false |
| 24 |
show_source = true |
| 25 |
junit = true |
| 26 |
""" |
| 27 |
And a file named "features/steps/passing_steps.py" with: |
| 28 |
""" |
| 29 |
# -*- coding: UTF-8 -*- |
| 30 |
from behave import step |
| 31 |
|
| 32 |
@step(u'{word:w} step passes') |
| 33 |
def step_passes(context, word): |
| 34 |
pass |
| 35 |
|
| 36 |
@step(u'{word:w} step passes with "{text}"') |
| 37 |
def step_passes_with_text(context, word, text): |
| 38 |
pass |
| 39 |
|
| 40 |
@step(u'{word:w} step fails') |
| 41 |
def step_fails(context, word): |
| 42 |
assert False, "XFAIL" |
| 43 |
|
| 44 |
@step(u'{word:w} step fails with "{text}"') |
| 45 |
def step_fails_with_text(context, word, text): |
| 46 |
assert False, u"XFAIL: "+ text |
| 47 |
""" |
| 48 |
And a file named "features/steps/step_write_output.py" with: |
| 49 |
""" |
| 50 |
# -*- coding: UTF-8 -*- |
| 51 |
from __future__ import print_function |
| 52 |
from behave import step |
| 53 |
import six |
| 54 |
|
| 55 |
@step(u'I write text "{text}" to stdout') |
| 56 |
def step_write_text(context, text): |
| 57 |
if six.PY2 and isinstance(text, six.text_type): |
| 58 |
text = text.encode("utf-8", "replace") |
| 59 |
print(text) |
| 60 |
|
| 61 |
@step(u'I write bytes "{data}" to stdout') |
| 62 |
def step_write_bytes(context, data): |
| 63 |
if isinstance(data, six.text_type): |
| 64 |
data = data.encode("unicode-escape", "replace") |
| 65 |
print(data) |
| 66 |
""" |
| 67 |
|
| 68 |
|
| 69 |
Scenario Outline: Problematic scenario name: <scenario.name> (case: passed, <format>) |
| 70 |
Given a file named "features/scenario_name_problematic_and_pass.feature" with: |
| 71 |
""" |
| 72 |
Feature: |
| 73 |
Scenario: <scenario.name> |
| 74 |
Given a step passes |
| 75 |
""" |
| 76 |
When I run "behave -f <format> features/scenario_name_problematic_and_pass.feature" |
| 77 |
Then it should pass with: |
| 78 |
""" |
| 79 |
1 feature passed, 0 failed, 0 skipped |
| 80 |
1 scenario passed, 0 failed, 0 skipped |
| 81 |
""" |
| 82 |
And the command output should contain: |
| 83 |
""" |
| 84 |
Scenario: <scenario.name> |
| 85 |
""" |
| 86 |
|
| 87 |
Examples: |
| 88 |
| format | scenario.name | |
| 89 |
| plain | Café | |
| 90 |
| pretty | Ärgernis ist überall | |
| 91 |
|
| 92 |
|
| 93 |
Scenario Outline: Problematic scenario name: <scenario.name> (case: failed, <format>) |
| 94 |
Given a file named "features/scenario_name_problematic_and_fail.feature" with: |
| 95 |
""" |
| 96 |
Feature: |
| 97 |
Scenario: <scenario.name> |
| 98 |
Given a step fails |
| 99 |
""" |
| 100 |
When I run "behave -f <format> features/scenario_name_problematic_and_fail.feature" |
| 101 |
Then it should fail with: |
| 102 |
""" |
| 103 |
0 features passed, 1 failed, 0 skipped |
| 104 |
0 scenarios passed, 1 failed, 0 skipped |
| 105 |
""" |
| 106 |
And the command output should contain: |
| 107 |
""" |
| 108 |
Scenario: <scenario.name> |
| 109 |
""" |
| 110 |
|
| 111 |
Examples: |
| 112 |
| format | scenario.name | |
| 113 |
| plain | Café | |
| 114 |
| pretty | Ärgernis ist überall | |
| 115 |
|
| 116 |
|
| 117 |
Scenario Outline: Problematic step: <step.text> (case: passed, <format>) |
| 118 |
Given a file named "features/step_problematic_and_pass.feature" with: |
| 119 |
""" |
| 120 |
Feature: |
| 121 |
Scenario: |
| 122 |
Given a step passes with "<step.text>" |
| 123 |
""" |
| 124 |
When I run "behave -f <format> features/step_problematic_and_pass.feature" |
| 125 |
Then it should pass with: |
| 126 |
""" |
| 127 |
1 feature passed, 0 failed, 0 skipped |
| 128 |
1 scenario passed, 0 failed, 0 skipped |
| 129 |
1 step passed, 0 failed, 0 skipped, 0 undefined |
| 130 |
""" |
| 131 |
|
| 132 |
Examples: |
| 133 |
| format | step.text | |
| 134 |
| plain | Café | |
| 135 |
| pretty | Ärgernis ist überall | |
| 136 |
|
| 137 |
|
| 138 |
Scenario Outline: Problematic step: <step.text> (case: fail, <format>) |
| 139 |
Given a file named "features/step_problematic_and_fail.feature" with: |
| 140 |
""" |
| 141 |
Feature: |
| 142 |
Scenario: |
| 143 |
Given a step fails with "<step.text>" |
| 144 |
""" |
| 145 |
When I run "behave -f <format> features/step_problematic_and_fail.feature" |
| 146 |
Then it should fail with: |
| 147 |
""" |
| 148 |
0 features passed, 1 failed, 0 skipped |
| 149 |
0 scenarios passed, 1 failed, 0 skipped |
| 150 |
0 steps passed, 1 failed, 0 skipped, 0 undefined |
| 151 |
""" |
| 152 |
|
| 153 |
Examples: |
| 154 |
| format | step.text | |
| 155 |
| plain | Café | |
| 156 |
| pretty | Ärgernis ist überall | |
| 157 |
|
| 158 |
|
| 159 |
@problematic.feature_filename |
| 160 |
@not.with_os=win32 |
| 161 |
Scenario Outline: Problematic feature filename: <name> (case: pass, <format>) |
| 162 |
Given a file named "features/<name>_and_pass.feature" with: |
| 163 |
""" |
| 164 |
Feature: |
| 165 |
Scenario: |
| 166 |
Given a step passes |
| 167 |
""" |
| 168 |
When I run "behave -f <format> features/<name>_and_pass.feature" |
| 169 |
Then it should pass with: |
| 170 |
""" |
| 171 |
1 feature passed, 0 failed, 0 skipped |
| 172 |
1 scenario passed, 0 failed, 0 skipped |
| 173 |
""" |
| 174 |
|
| 175 |
Examples: |
| 176 |
| format | name | |
| 177 |
| plain | Café | |
| 178 |
| pretty | Ärgernis_ist_überall | |
| 179 |
|
| 180 |
|
| 181 |
@problematic.feature_filename |
| 182 |
@not.with_os=win32 |
| 183 |
Scenario Outline: Problematic feature filename: <name> (case: fail, <format>) |
| 184 |
Given a file named "features/<name>_and_fail.feature" with: |
| 185 |
""" |
| 186 |
Feature: |
| 187 |
Scenario: |
| 188 |
Given a step fails |
| 189 |
""" |
| 190 |
When I run "behave -f <format> features/<name>_and_fail.feature" |
| 191 |
Then it should fail with: |
| 192 |
""" |
| 193 |
0 features passed, 1 failed, 0 skipped |
| 194 |
0 scenarios passed, 1 failed, 0 skipped |
| 195 |
""" |
| 196 |
|
| 197 |
Examples: |
| 198 |
| format | name | |
| 199 |
| plain | Café | |
| 200 |
| pretty | Ärgernis_ist_überall | |
| 201 |
|
| 202 |
|
| 203 |
@problematic.step_filename |
| 204 |
Scenario Outline: Problematic step filename: <name> (case: pass, <format>) |
| 205 |
|
| 206 |
TEST-CONSTRAINT: Only one step file is used (= 1 name only). |
| 207 |
Otherwise, duplicated steps occur (without cleanup in step directory). |
| 208 |
|
| 209 |
Given a file named "features/problematic_stepfile_and_pass.feature" with: |
| 210 |
""" |
| 211 |
Feature: |
| 212 |
Scenario: |
| 213 |
Given I use a weird step and pass |
| 214 |
""" |
| 215 |
And a file named "features/steps/step_pass_<name>.py" with: |
| 216 |
""" |
| 217 |
from behave import step |
| 218 |
|
| 219 |
@step(u'I use a weird step and pass') |
| 220 |
def step_weird_pass(context): |
| 221 |
pass |
| 222 |
""" |
| 223 |
When I run "behave -f <format> features/problematic_stepfile_and_pass.feature" |
| 224 |
Then it should pass with: |
| 225 |
""" |
| 226 |
1 feature passed, 0 failed, 0 skipped |
| 227 |
1 scenario passed, 0 failed, 0 skipped |
| 228 |
""" |
| 229 |
But note that "you should normally use only ASCII/latin-1 python filenames" |
| 230 |
|
| 231 |
Examples: |
| 232 |
| format | name | |
| 233 |
| plain | Ärgernis_ist_überall | |
| 234 |
| pretty | Ärgernis_ist_überall | |
| 235 |
|
| 236 |
|
| 237 |
@problematic.step_filename |
| 238 |
Scenario Outline: Problematic step filename: <name> (case: fail, <format>) |
| 239 |
|
| 240 |
TEST-CONSTRAINT: Only one step file is used (= 1 name only). |
| 241 |
Otherwise, duplicated steps occur (without cleanup in step directory). |
| 242 |
|
| 243 |
Given a file named "features/problematic_stepfile_and_fail.feature" with: |
| 244 |
""" |
| 245 |
Feature: |
| 246 |
Scenario: |
| 247 |
Given I use a weird step and fail |
| 248 |
""" |
| 249 |
And a file named "features/steps/step_fail_<name>.py" with: |
| 250 |
""" |
| 251 |
from behave import step |
| 252 |
|
| 253 |
@step(u'I use a weird step and fail') |
| 254 |
def step_weird_fails(context): |
| 255 |
assert False, "XFAIL-WEIRD" |
| 256 |
""" |
| 257 |
When I run "behave -f <format> features/problematic_stepfile_and_fail.feature" |
| 258 |
Then it should fail with: |
| 259 |
""" |
| 260 |
0 features passed, 1 failed, 0 skipped |
| 261 |
0 scenarios passed, 1 failed, 0 skipped |
| 262 |
""" |
| 263 |
But note that "you should normally use only ASCII/latin-1 python filenames" |
| 264 |
|
| 265 |
Examples: |
| 266 |
| format | name | |
| 267 |
| plain | Ärgernis_ist_überall | |
| 268 |
| pretty | Ärgernis_ist_überall | |
| 269 |
|
| 270 |
|
| 271 |
@problematic.output |
| 272 |
Scenario Outline: Problematic output: <text> (case: pass, <format>) |
| 273 |
Given a file named "features/problematic_output_and_pass.feature" with: |
| 274 |
""" |
| 275 |
Feature: |
| 276 |
Scenario: |
| 277 |
Given I write text "<text>" to stdout |
| 278 |
Then I write bytes "<text>" to stdout |
| 279 |
And a step passes |
| 280 |
""" |
| 281 |
When I run "behave -f <format> --no-capture features/problematic_output_and_pass.feature" |
| 282 |
Then it should pass with: |
| 283 |
""" |
| 284 |
1 feature passed, 0 failed, 0 skipped |
| 285 |
1 scenario passed, 0 failed, 0 skipped |
| 286 |
""" |
| 287 |
|
| 288 |
Examples: |
| 289 |
| format | text | |
| 290 |
| plain | Café | |
| 291 |
| pretty | Ärgernis ist überall | |
| 292 |
|
| 293 |
|
| 294 |
@problematic.output |
| 295 |
Scenario Outline: Problematic output: <text> (case: fail, <format>) |
| 296 |
Given a file named "features/problematic_output_and_fail.feature" with: |
| 297 |
""" |
| 298 |
Feature: |
| 299 |
Scenario: |
| 300 |
Given I write text "<text>" to stdout |
| 301 |
Then I write bytes "<text>" to stdout |
| 302 |
And a step fails |
| 303 |
""" |
| 304 |
When I run "behave -f <format> features/problematic_output_and_fail.feature" |
| 305 |
Then it should fail with: |
| 306 |
""" |
| 307 |
0 features passed, 1 failed, 0 skipped |
| 308 |
0 scenarios passed, 1 failed, 0 skipped |
| 309 |
""" |
| 310 |
And the command output should contain: |
| 311 |
""" |
| 312 |
<text> |
| 313 |
""" |
| 314 |
|
| 315 |
Examples: |
| 316 |
| format | text | |
| 317 |
| plain | Café | |
| 318 |
| pretty | Ärgernis ist überall | |
| 319 |
|
| 320 |
|
| 321 |
@problematic.tags |
| 322 |
Scenario Outline: Problematic tag: <tag> (case: pass, <format>) |
| 323 |
Given a file named "features/problematic_tag_and_pass.feature" with: |
| 324 |
""" |
| 325 |
Feature: |
| 326 |
@<tag> |
| 327 |
Scenario: |
| 328 |
Given a step passes |
| 329 |
""" |
| 330 |
When I run "behave -f <format> features/problematic_tag_and_pass.feature" |
| 331 |
Then it should pass with: |
| 332 |
""" |
| 333 |
1 scenario passed, 0 failed, 0 skipped |
| 334 |
""" |
| 335 |
|
| 336 |
Examples: |
| 337 |
| format | tag | |
| 338 |
| plain | tag.Café | |
| 339 |
| pretty | tag.Ärgernis_ist_überall | |
| 340 |
|
| 341 |
|
| 342 |
@problematic.tags |
| 343 |
Scenario Outline: Problematic tag: <tag> (case: fail, <format>) |
| 344 |
Given a file named "features/problematic_tag_and_fail.feature" with: |
| 345 |
""" |
| 346 |
Feature: |
| 347 |
@<tag> |
| 348 |
Scenario: |
| 349 |
Given a step fails |
| 350 |
""" |
| 351 |
When I run "behave -f <format> features/problematic_tag_and_fail.feature" |
| 352 |
Then it should fail with: |
| 353 |
""" |
| 354 |
0 scenarios passed, 1 failed, 0 skipped |
| 355 |
""" |
| 356 |
|
| 357 |
Examples: |
| 358 |
| format | tag | |
| 359 |
| plain | tag.Café | |
| 360 |
| pretty | tag.Ärgernis_ist_überall | |
| 361 |
|
| 362 |
|
| 363 |
@issue_0230 |
| 364 |
Scenario Outline: Step assert fails with problematic chars (case: <format>) |
| 365 |
|
| 366 |
NOTE: Python2 fails silently without showing the failed step. |
| 367 |
HINT: Use unicode string when you use, special non-ASCII characters. |
| 368 |
HINT: Use encoding-hint in python file header. |
| 369 |
|
| 370 |
Given a file named "features/steps/problematic_steps.py" with: |
| 371 |
""" |
| 372 |
# -*- coding: UTF-8 -*- |
| 373 |
from behave import step |
| 374 |
|
| 375 |
@step(u'{word:w} step fails with assert and non-ASCII text') |
| 376 |
def step_fails_with_assert_and_problematic_text(context, word): |
| 377 |
assert False, u"XFAIL:¾;" |
| 378 |
""" |
| 379 |
And a file named "features/assert_with_ptext.feature" with: |
| 380 |
""" |
| 381 |
Feature: |
| 382 |
Scenario: |
| 383 |
Given a step passes |
| 384 |
When a step fails with assert and non-ASCII text |
| 385 |
""" |
| 386 |
When I run "behave -f <format> features/assert_with_ptext.feature" |
| 387 |
Then it should fail with: |
| 388 |
""" |
| 389 |
0 scenarios passed, 1 failed, 0 skipped |
| 390 |
1 step passed, 1 failed, 0 skipped, 0 undefined |
| 391 |
""" |
| 392 |
And the command output should contain: |
| 393 |
""" |
| 394 |
Assertion Failed: XFAIL:¾; |
| 395 |
""" |
| 396 |
|
| 397 |
Examples: |
| 398 |
| format | |
| 399 |
| plain | |
| 400 |
| pretty | |
| 401 |
|
| 402 |
@issue_0226 |
| 403 |
Scenario Outline: Step raises exception with problematic chars (case: <format>) |
| 404 |
|
| 405 |
In Python2: When an exception is raised with unicode argument, |
| 406 |
(and special non-ASCII chars) the conversion of the exception into |
| 407 |
a unicode string causes implicit conversion into a normal string |
| 408 |
by using the default encoding (normally: ASCII). |
| 409 |
Therefore, the implicit encoding into a normal string often fails. |
| 410 |
|
| 411 |
SEE ALSO: http://bugs.python.org/issue2517 |
| 412 |
NOTE: Better if encoding hint is provided in python file header. |
| 413 |
|
| 414 |
Given a file named "features/steps/problematic_steps.py" with: |
| 415 |
""" |
| 416 |
# -*- coding: UTF-8 -*- |
| 417 |
from behave import step |
| 418 |
|
| 419 |
@step(u'{word:w} step fails with exception and non-ASCII text') |
| 420 |
def step_fails_with_exception_and_problematic_text(context, word): |
| 421 |
# -- REQUIRE: UNICODE STRING, when special, non-ASCII chars are used. |
| 422 |
raise RuntimeError(u"FAIL:¾;") |
| 423 |
""" |
| 424 |
And a file named "features/exception_with_ptext.feature" with: |
| 425 |
""" |
| 426 |
Feature: |
| 427 |
Scenario: |
| 428 |
Given a step passes |
| 429 |
When a step fails with exception and non-ASCII text |
| 430 |
""" |
| 431 |
When I run "behave -f <format> features/exception_with_ptext.feature" |
| 432 |
Then it should fail with: |
| 433 |
""" |
| 434 |
0 scenarios passed, 1 failed, 0 skipped |
| 435 |
1 step passed, 1 failed, 0 skipped, 0 undefined |
| 436 |
""" |
| 437 |
And the command output should contain: |
| 438 |
""" |
| 439 |
RuntimeError: FAIL:¾; |
| 440 |
""" |
| 441 |
|
| 442 |
Examples: |
| 443 |
| format | |
| 444 |
| plain | |
| 445 |
| pretty | |