@@ -171,9 +171,8 @@ def parser(request):
171
171
# FILE OUTPUT
172
172
173
173
174
- def test_file_output_str_read (datapath , parser , from_file_expected ):
175
- filename = datapath ("io" , "data" , "xml" , "books.xml" )
176
- df_file = read_xml (filename , parser = parser )
174
+ def test_file_output_str_read (xml_books , parser , from_file_expected ):
175
+ df_file = read_xml (xml_books , parser = parser )
177
176
178
177
with tm .ensure_clean ("test.xml" ) as path :
179
178
df_file .to_xml (path , parser = parser )
@@ -185,9 +184,8 @@ def test_file_output_str_read(datapath, parser, from_file_expected):
185
184
assert output == from_file_expected
186
185
187
186
188
- def test_file_output_bytes_read (datapath , parser , from_file_expected ):
189
- filename = datapath ("io" , "data" , "xml" , "books.xml" )
190
- df_file = read_xml (filename , parser = parser )
187
+ def test_file_output_bytes_read (xml_books , parser , from_file_expected ):
188
+ df_file = read_xml (xml_books , parser = parser )
191
189
192
190
with tm .ensure_clean ("test.xml" ) as path :
193
191
df_file .to_xml (path , parser = parser )
@@ -199,9 +197,8 @@ def test_file_output_bytes_read(datapath, parser, from_file_expected):
199
197
assert output == from_file_expected
200
198
201
199
202
- def test_str_output (datapath , parser , from_file_expected ):
203
- filename = datapath ("io" , "data" , "xml" , "books.xml" )
204
- df_file = read_xml (filename , parser = parser )
200
+ def test_str_output (xml_books , parser , from_file_expected ):
201
+ df_file = read_xml (xml_books , parser = parser )
205
202
206
203
output = df_file .to_xml (parser = parser )
207
204
output = equalize_decl (output )
@@ -222,7 +219,7 @@ def test_wrong_file_path(parser, geom_df):
222
219
# INDEX
223
220
224
221
225
- def test_index_false (datapath , parser ):
222
+ def test_index_false (xml_books , parser ):
226
223
expected = """\
227
224
<?xml version='1.0' encoding='utf-8'?>
228
225
<data>
@@ -249,8 +246,7 @@ def test_index_false(datapath, parser):
249
246
</row>
250
247
</data>"""
251
248
252
- filename = datapath ("io" , "data" , "xml" , "books.xml" )
253
- df_file = read_xml (filename , parser = parser )
249
+ df_file = read_xml (xml_books , parser = parser )
254
250
255
251
with tm .ensure_clean ("test.xml" ) as path :
256
252
df_file .to_xml (path , index = False , parser = parser )
@@ -262,7 +258,7 @@ def test_index_false(datapath, parser):
262
258
assert output == expected
263
259
264
260
265
- def test_index_false_rename_row_root (datapath , parser ):
261
+ def test_index_false_rename_row_root (xml_books , parser ):
266
262
expected = """\
267
263
<?xml version='1.0' encoding='utf-8'?>
268
264
<books>
@@ -289,8 +285,7 @@ def test_index_false_rename_row_root(datapath, parser):
289
285
</book>
290
286
</books>"""
291
287
292
- filename = datapath ("io" , "data" , "xml" , "books.xml" )
293
- df_file = read_xml (filename , parser = parser )
288
+ df_file = read_xml (xml_books , parser = parser )
294
289
295
290
with tm .ensure_clean ("test.xml" ) as path :
296
291
df_file .to_xml (
@@ -831,9 +826,8 @@ def test_namespace_prefix_and_default(parser, geom_df):
831
826
</data>"""
832
827
833
828
834
- def test_encoding_option_str (datapath , parser ):
835
- filename = datapath ("io" , "data" , "xml" , "baby_names.xml" )
836
- df_file = read_xml (filename , parser = parser , encoding = "ISO-8859-1" ).head (5 )
829
+ def test_encoding_option_str (xml_baby_names , parser ):
830
+ df_file = read_xml (xml_baby_names , parser = parser , encoding = "ISO-8859-1" ).head (5 )
837
831
838
832
output = df_file .to_xml (encoding = "ISO-8859-1" , parser = parser )
839
833
@@ -848,19 +842,17 @@ def test_encoding_option_str(datapath, parser):
848
842
849
843
850
844
@td .skip_if_no ("lxml" )
851
- def test_correct_encoding_file (datapath ):
852
- filename = datapath ("io" , "data" , "xml" , "baby_names.xml" )
853
- df_file = read_xml (filename , encoding = "ISO-8859-1" , parser = "lxml" )
845
+ def test_correct_encoding_file (xml_baby_names ):
846
+ df_file = read_xml (xml_baby_names , encoding = "ISO-8859-1" , parser = "lxml" )
854
847
855
848
with tm .ensure_clean ("test.xml" ) as path :
856
849
df_file .to_xml (path , index = False , encoding = "ISO-8859-1" , parser = "lxml" )
857
850
858
851
859
852
@td .skip_if_no ("lxml" )
860
853
@pytest .mark .parametrize ("encoding" , ["UTF-8" , "UTF-16" , "ISO-8859-1" ])
861
- def test_wrong_encoding_option_lxml (datapath , parser , encoding ):
862
- filename = datapath ("io" , "data" , "xml" , "baby_names.xml" )
863
- df_file = read_xml (filename , encoding = "ISO-8859-1" , parser = "lxml" )
854
+ def test_wrong_encoding_option_lxml (xml_baby_names , parser , encoding ):
855
+ df_file = read_xml (xml_baby_names , encoding = "ISO-8859-1" , parser = "lxml" )
864
856
865
857
with tm .ensure_clean ("test.xml" ) as path :
866
858
df_file .to_xml (path , index = False , encoding = encoding , parser = parser )
@@ -988,22 +980,22 @@ def test_unknown_parser(geom_df):
988
980
989
981
990
982
@td .skip_if_no ("lxml" )
991
- def test_stylesheet_file_like (datapath , mode , geom_df ):
992
- xsl = datapath ( "io" , "data" , "xml" , "row_field_output.xsl" )
993
-
994
- with open ( xsl , mode , encoding = "utf-8" if mode == "r" else None ) as f :
983
+ def test_stylesheet_file_like (xsl_row_field_output , mode , geom_df ):
984
+ with open (
985
+ xsl_row_field_output , mode , encoding = "utf-8" if mode == "r" else None
986
+ ) as f :
995
987
assert geom_df .to_xml (stylesheet = f ) == xsl_expected
996
988
997
989
998
990
@td .skip_if_no ("lxml" )
999
- def test_stylesheet_io (datapath , mode , geom_df ):
1000
- xsl_path = datapath ("io" , "data" , "xml" , "row_field_output.xsl" )
1001
-
991
+ def test_stylesheet_io (xsl_row_field_output , mode , geom_df ):
1002
992
# note: By default the bodies of untyped functions are not checked,
1003
993
# consider using --check-untyped-defs
1004
994
xsl_obj : BytesIO | StringIO # type: ignore[annotation-unchecked]
1005
995
1006
- with open (xsl_path , mode , encoding = "utf-8" if mode == "r" else None ) as f :
996
+ with open (
997
+ xsl_row_field_output , mode , encoding = "utf-8" if mode == "r" else None
998
+ ) as f :
1007
999
if mode == "rb" :
1008
1000
xsl_obj = BytesIO (f .read ())
1009
1001
else :
@@ -1015,10 +1007,10 @@ def test_stylesheet_io(datapath, mode, geom_df):
1015
1007
1016
1008
1017
1009
@td .skip_if_no ("lxml" )
1018
- def test_stylesheet_buffered_reader (datapath , mode , geom_df ):
1019
- xsl = datapath ( "io" , "data" , "xml" , "row_field_output.xsl" )
1020
-
1021
- with open ( xsl , mode , encoding = "utf-8" if mode == "r" else None ) as f :
1010
+ def test_stylesheet_buffered_reader (xsl_row_field_output , mode , geom_df ):
1011
+ with open (
1012
+ xsl_row_field_output , mode , encoding = "utf-8" if mode == "r" else None
1013
+ ) as f :
1022
1014
xsl_obj = f .read ()
1023
1015
1024
1016
output = geom_df .to_xml (stylesheet = xsl_obj )
0 commit comments