@@ -261,45 +261,31 @@ def test_clean_writer():
261
261
"""
262
262
263
263
264
- def test_pathplus_write_clean ():
264
+ @pytest .mark .parametrize (
265
+ "input_string, output_string" ,
266
+ [(["Top line" , " " , "Line with whitespace " , "Line with tabs " , "No newline at end of file"
267
+ ], ["Top line" , '' , "Line with whitespace" , "Line with tabs" , "No newline at end of file" , "" ]),
268
+ ([
269
+ "Top line" ,
270
+ " " ,
271
+ "Line with whitespace " ,
272
+ "Line with tabs " ,
273
+ "Too many newlines\n \n \n \n \n \n \n "
274
+ ], [
275
+ "Top line" ,
276
+ "" ,
277
+ "Line with whitespace" ,
278
+ "Line with tabs" ,
279
+ "Too many newlines" ,
280
+ "" ,
281
+ ]), ([], ["\n " ])]
282
+ )
283
+ def test_pathplus_write_clean (input_string , output_string ):
265
284
with TemporaryDirectory () as tmpdir :
266
285
tempfile = PathPlus (tmpdir ) / "tmpfile.txt"
267
286
268
- test_string = "\n " .join ([
269
- "Top line" ,
270
- " " ,
271
- "Line with whitespace " ,
272
- "Line with tabs " ,
273
- "No newline at end of file" ,
274
- ])
275
-
276
- with tempfile .open ("w" ) as fp :
277
- tempfile .write_clean (test_string )
278
-
279
- assert tempfile .read_text () == """Top line
280
-
281
- Line with whitespace
282
- Line with tabs
283
- No newline at end of file
284
- """
285
- # Again with lots of newlines
286
- test_string = "\n " .join ([
287
- "Top line" ,
288
- " " ,
289
- "Line with whitespace " ,
290
- "Line with tabs " ,
291
- "Too many newlines\n \n \n \n \n \n \n " ,
292
- ])
293
-
294
- with tempfile .open ("w" ) as fp :
295
- tempfile .write_clean (test_string )
296
-
297
- assert tempfile .read_text () == """Top line
298
-
299
- Line with whitespace
300
- Line with tabs
301
- Too many newlines
302
- """
287
+ tempfile .write_clean ("\n " .join (input_string ))
288
+ assert tempfile .read_text () == "\n " .join (output_string )
303
289
304
290
305
291
@pytest .mark .xfail (reason = "Unsupported on PyPy3 <7.2" , condition = (platform .python_implementation () == "PyPy" ))
0 commit comments