MCPcopy Create free account
hub / github.com/pytest-dev/pytest-bdd / test_generate_with_quotes

Function test_generate_with_quotes

tests/scripts/test_generate.py:81–155  ·  view source on GitHub ↗

Test that code generation escapes quote characters properly.

(pytester)

Source from the content-addressed store, hash-verified

79
80
81def test_generate_with_quotes(pytester):
82 """Test that code generation escapes quote characters properly."""
83 pytester.makefile(
84 ".feature",
85 generate_with_quotes=textwrap.dedent(
86 '''\
87 Feature: Handling quotes in code generation
88
89 Scenario: A step definition with quotes should be escaped as needed
90 Given I have a fixture with 'single' quotes
91 And I have a fixture with "double" quotes
92 And I have a fixture with single-quote \'\'\'triple\'\'\' quotes
93 And I have a fixture with double-quote """triple""" quotes
94
95 When I generate the code
96
97 Then The generated string should be written
98 '''
99 ),
100 )
101
102 result = pytester.run("pytest-bdd", "generate", "generate_with_quotes.feature")
103 assert str(result.stdout) == textwrap.dedent(
104 '''\
105 """Handling quotes in code generation feature tests."""
106
107 from pytest_bdd import (
108 given,
109 scenario,
110 then,
111 when,
112 )
113
114
115 @scenario('generate_with_quotes.feature', 'A step definition with quotes should be escaped as needed')
116 def test_a_step_definition_with_quotes_should_be_escaped_as_needed():
117 """A step definition with quotes should be escaped as needed."""
118
119
120 @given('I have a fixture with "double" quotes')
121 def _():
122 """I have a fixture with "double" quotes."""
123 raise NotImplementedError
124
125
126 @given('I have a fixture with \\'single\\' quotes')
127 def _():
128 """I have a fixture with 'single' quotes."""
129 raise NotImplementedError
130
131
132 @given('I have a fixture with double-quote """triple""" quotes')
133 def _():
134 """I have a fixture with double-quote \\"\\"\\"triple\\"\\"\\" quotes."""
135 raise NotImplementedError
136
137
138 @given('I have a fixture with single-quote \\'\\'\\'triple\\'\\'\\' quotes')

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…