|
1 | 1 | """Scenario Outline tests."""
|
| 2 | +from __future__ import unicode_literals |
2 | 3 | import re
|
3 | 4 | import textwrap
|
4 | 5 |
|
|
11 | 12 |
|
12 | 13 | @scenario("outline.feature", "Outlined given, when, thens", example_converters=dict(start=int, eat=float, left=str))
|
13 | 14 | def test_outlined(request):
|
14 |
| - assert get_parametrize_markers_args(request.node) == ([u"start", u"eat", u"left"], [[12, 5.0, "7"], [5, 4.0, "1"]]) |
| 15 | + assert get_parametrize_markers_args(request.node) == (["start", "eat", "left"], [[12, 5.0, "7"], [5, 4.0, "1"]]) |
15 | 16 |
|
16 | 17 |
|
17 | 18 | @given("there are <start> cucumbers")
|
@@ -56,7 +57,7 @@ def test_wrong_vertical_examples_scenario(testdir):
|
56 | 57 | feature = features.join("test.feature")
|
57 | 58 | feature.write_text(
|
58 | 59 | textwrap.dedent(
|
59 |
| - u""" |
| 60 | + """ |
60 | 61 | Scenario Outline: Outlined with wrong vertical example table
|
61 | 62 | Given there are <start> cucumbers
|
62 | 63 | When I eat <eat> cucumbers
|
@@ -89,7 +90,7 @@ def test_wrong_vertical_examples_feature(testdir):
|
89 | 90 | feature = features.join("test.feature")
|
90 | 91 | feature.write_text(
|
91 | 92 | textwrap.dedent(
|
92 |
| - u""" |
| 93 | + """ |
93 | 94 | Feature: Outlines
|
94 | 95 |
|
95 | 96 | Examples: Vertical
|
@@ -133,7 +134,7 @@ def test_outlined_with_other_fixtures(other_fixture):
|
133 | 134 | )
|
134 | 135 | def test_vertical_example(request):
|
135 | 136 | """Test outlined scenario with vertical examples table."""
|
136 |
| - assert get_parametrize_markers_args(request.node) == ([u"start", u"eat", u"left"], [[12, 5.0, "7"], [2, 1.0, "1"]]) |
| 137 | + assert get_parametrize_markers_args(request.node) == (["start", "eat", "left"], [[12, 5.0, "7"], [2, 1.0, "1"]]) |
137 | 138 |
|
138 | 139 |
|
139 | 140 | @given("there are <start> <fruits>")
|
@@ -164,5 +165,62 @@ def test_outlined_feature(request):
|
164 | 165 | ["start", "eat", "left"],
|
165 | 166 | [[12, 5.0, "7"], [5, 4.0, "1"]],
|
166 | 167 | ["fruits"],
|
167 |
| - [[u"oranges"], [u"apples"]], |
| 168 | + [["oranges"], ["apples"]], |
168 | 169 | )
|
| 170 | + |
| 171 | + |
| 172 | +def test_outline_with_escaped_pipes(testdir): |
| 173 | + """Test parametrized feature example table with escaped pipe characters in input.""" |
| 174 | + features = testdir.mkdir("features") |
| 175 | + feature = features.join("test.feature") |
| 176 | + feature.write_text( |
| 177 | + textwrap.dedent( |
| 178 | + r""" |
| 179 | + Feature: Outline With Special characters |
| 180 | + |
| 181 | + Scenario Outline: Outline with escaped pipe character |
| 182 | + Given We have strings <string1> and <string2> |
| 183 | + Then <string2> should be the base64 encoding of <string1> |
| 184 | +
|
| 185 | + Examples: |
| 186 | + | string1 | string2 | |
| 187 | + | bork | Ym9yaw== | |
| 188 | + | \|bork | fGJvcms= | |
| 189 | + | bork \| | Ym9yayB8 | |
| 190 | + | bork\|\|bork | Ym9ya3x8Ym9yaw== | |
| 191 | + | \| | fA== | |
| 192 | + | bork \\ | Ym9yayAgICAgIFxc | |
| 193 | + | bork \\\| | Ym9yayAgICBcXHw= | |
| 194 | + """ |
| 195 | + ), |
| 196 | + "utf-8", |
| 197 | + ensure=True, |
| 198 | + ) |
| 199 | + |
| 200 | + testdir.makepyfile( |
| 201 | + textwrap.dedent( |
| 202 | + """ |
| 203 | + import base64 |
| 204 | +
|
| 205 | + from pytest_bdd import scenario, given, when, then |
| 206 | + from pytest_bdd.utils import get_parametrize_markers_args |
| 207 | +
|
| 208 | +
|
| 209 | + @scenario("features/test.feature", "Outline with escaped pipe character") |
| 210 | + def test_outline_with_escaped_pipe_character(request): |
| 211 | + pass |
| 212 | +
|
| 213 | +
|
| 214 | + @given("We have strings <string1> and <string2>") |
| 215 | + def we_have_strings_string1_and_string2(string1, string2): |
| 216 | + pass |
| 217 | +
|
| 218 | +
|
| 219 | + @then("<string2> should be the base64 encoding of <string1>") |
| 220 | + def string2_should_be_base64_encoding_of_string1(string2, string1): |
| 221 | + assert string1.encode() == base64.b64decode(string2.encode()) |
| 222 | + """ |
| 223 | + ) |
| 224 | + ) |
| 225 | + result = testdir.runpytest() |
| 226 | + result.stdout.fnmatch_lines(["* 7 passed *"]) |
0 commit comments