@@ -123,35 +123,35 @@ class ExamplePydanticModel(BaseModel):
123
123
),
124
124
],
125
125
)
126
- def test (input_obj : Any , output : str ):
127
- assert format_as_xml (input_obj ) == output
126
+ def test_root_tag (input_obj : Any , output : str ):
127
+ assert format_as_xml (input_obj , root_tag = 'examples' , item_tag = 'example' ) == output
128
128
129
129
130
130
@pytest .mark .parametrize (
131
131
'input_obj,output' ,
132
132
[
133
- pytest .param ('a string' , snapshot ('<examples >a string</examples >' ), id = 'string' ),
134
- pytest .param ('a <ex>foo</ex>' , snapshot ('<examples >a <ex>foo</ex></examples >' ), id = 'string' ),
135
- pytest .param (42 , snapshot ('<examples >42</examples >' ), id = 'int' ),
133
+ pytest .param ('a string' , snapshot ('<item >a string</item >' ), id = 'string' ),
134
+ pytest .param ('a <ex>foo</ex>' , snapshot ('<item >a <ex>foo</ex></item >' ), id = 'string' ),
135
+ pytest .param (42 , snapshot ('<item >42</item >' ), id = 'int' ),
136
136
pytest .param (
137
137
[1 , 2 , 3 ],
138
138
snapshot ("""\
139
- <example >1</example >
140
- <example >2</example >
141
- <example >3</example >\
139
+ <item >1</item >
140
+ <item >2</item >
141
+ <item >3</item >\
142
142
""" ),
143
143
id = 'list[int]' ,
144
144
),
145
145
pytest .param (
146
146
[[1 , 2 ], [3 ]],
147
147
snapshot ("""\
148
- <example >
149
- <example >1</example >
150
- <example >2</example >
151
- </example >
152
- <example >
153
- <example >3</example >
154
- </example >\
148
+ <item >
149
+ <item >1</item >
150
+ <item >2</item >
151
+ </item >
152
+ <item >
153
+ <item >3</item >
154
+ </item >\
155
155
""" ),
156
156
id = 'list[list[int]]' ,
157
157
),
@@ -166,24 +166,22 @@ def test(input_obj: Any, output: str):
166
166
pytest .param (
167
167
[datetime (2025 , 1 , 1 , 12 , 13 ), date (2025 , 1 , 2 )],
168
168
snapshot ("""\
169
- <example >2025-01-01T12:13:00</example >
170
- <example >2025-01-02</example >\
169
+ <item >2025-01-01T12:13:00</item >
170
+ <item >2025-01-02</item >\
171
171
""" ),
172
172
id = 'list[date]' ,
173
173
),
174
174
],
175
175
)
176
176
def test_no_root (input_obj : Any , output : str ):
177
- assert format_as_xml (input_obj , include_root_tag = False ) == output
177
+ assert format_as_xml (input_obj ) == output
178
178
179
179
180
180
def test_no_indent ():
181
- assert format_as_xml ([1 , 2 , 3 ], indent = None ) == snapshot (
182
- '<examples><example>1</example><example>2</example><example>3</example></examples>'
183
- )
184
- assert format_as_xml ([1 , 2 , 3 ], indent = None , include_root_tag = False ) == snapshot (
185
- '<example>1</example><example>2</example><example>3</example>'
181
+ assert format_as_xml ([1 , 2 , 3 ], indent = None , root_tag = 'example' ) == snapshot (
182
+ '<example><item>1</item><item>2</item><item>3</item></example>'
186
183
)
184
+ assert format_as_xml ([1 , 2 , 3 ], indent = None ) == snapshot ('<item>1</item><item>2</item><item>3</item>' )
187
185
188
186
189
187
def test_invalid_value ():
@@ -197,8 +195,8 @@ def test_invalid_key():
197
195
198
196
199
197
def test_set ():
200
- assert '<example>1</example>' in format_as_xml ({1 , 2 , 3 })
198
+ assert '<example>1</example>' in format_as_xml ({1 , 2 , 3 }, item_tag = 'example' )
201
199
202
200
203
201
def test_custom_null ():
204
- assert format_as_xml (None , none_str = 'nil' ) == snapshot ('<examples >nil</examples >' )
202
+ assert format_as_xml (None , none_str = 'nil' ) == snapshot ('<item >nil</item >' )
0 commit comments