@@ -471,11 +471,12 @@ def test_header_footer(self):
471
471
assert_equal (c .read (),
472
472
asbytes ('1 2\n 3 4\n ' + commentstr + test_header_footer + '\n ' ))
473
473
474
- def test_file_roundtrip (self ):
474
+ @pytest .mark .parametrize ("filename_type" , [Path , str ])
475
+ def test_file_roundtrip (self , filename_type ):
475
476
with temppath () as name :
476
477
a = np .array ([(1 , 2 ), (3 , 4 )])
477
- np .savetxt (name , a )
478
- b = np .loadtxt (name )
478
+ np .savetxt (filename_type ( name ) , a )
479
+ b = np .loadtxt (filename_type ( name ) )
479
480
assert_array_equal (a , b )
480
481
481
482
def test_complex_arrays (self ):
@@ -2567,10 +2568,10 @@ def test_save_load_memmap(self):
2567
2568
break_cycles ()
2568
2569
2569
2570
@pytest .mark .xfail (IS_WASM , reason = "memmap doesn't work correctly" )
2570
- def test_save_load_memmap_readwrite ( self ):
2571
- # Test that pathlib.Path instances can be written mem-mapped.
2571
+ @ pytest . mark . parametrize ( "filename_type" , [ Path , str ])
2572
+ def test_save_load_memmap_readwrite ( self , filename_type ):
2572
2573
with temppath (suffix = '.npy' ) as path :
2573
- path = Path (path )
2574
+ path = filename_type (path )
2574
2575
a = np .array ([[1 , 2 ], [3 , 4 ]], int )
2575
2576
np .save (path , a )
2576
2577
b = np .load (path , mmap_mode = 'r+' )
@@ -2583,35 +2584,37 @@ def test_save_load_memmap_readwrite(self):
2583
2584
data = np .load (path )
2584
2585
assert_array_equal (data , a )
2585
2586
2586
- def test_savez_load ( self ):
2587
- # Test that pathlib.Path instances can be used with savez.
2587
+ @ pytest . mark . parametrize ( "filename_type" , [ Path , str ])
2588
+ def test_savez_load ( self , filename_type ):
2588
2589
with temppath (suffix = '.npz' ) as path :
2589
- path = Path (path )
2590
+ path = filename_type (path )
2590
2591
np .savez (path , lab = 'place holder' )
2591
2592
with np .load (path ) as data :
2592
2593
assert_array_equal (data ['lab' ], 'place holder' )
2593
2594
2594
- def test_savez_compressed_load ( self ):
2595
- # Test that pathlib.Path instances can be used with savez.
2595
+ @ pytest . mark . parametrize ( "filename_type" , [ Path , str ])
2596
+ def test_savez_compressed_load ( self , filename_type ):
2596
2597
with temppath (suffix = '.npz' ) as path :
2597
- path = Path (path )
2598
+ path = filename_type (path )
2598
2599
np .savez_compressed (path , lab = 'place holder' )
2599
2600
data = np .load (path )
2600
2601
assert_array_equal (data ['lab' ], 'place holder' )
2601
2602
data .close ()
2602
2603
2603
- def test_genfromtxt (self ):
2604
+ @pytest .mark .parametrize ("filename_type" , [Path , str ])
2605
+ def test_genfromtxt (self , filename_type ):
2604
2606
with temppath (suffix = '.txt' ) as path :
2605
- path = Path (path )
2607
+ path = filename_type (path )
2606
2608
a = np .array ([(1 , 2 ), (3 , 4 )])
2607
2609
np .savetxt (path , a )
2608
2610
data = np .genfromtxt (path )
2609
2611
assert_array_equal (a , data )
2610
2612
2611
- def test_recfromtxt (self ):
2613
+ @pytest .mark .parametrize ("filename_type" , [Path , str ])
2614
+ def test_recfromtxt (self , filename_type ):
2612
2615
with temppath (suffix = '.txt' ) as path :
2613
- path = Path (path )
2614
- with path . open ('w' ) as f :
2616
+ path = filename_type (path )
2617
+ with open (path , 'w' ) as f :
2615
2618
f .write ('A,B\n 0,1\n 2,3' )
2616
2619
2617
2620
kwargs = dict (delimiter = "," , missing_values = "N/A" , names = True )
@@ -2621,10 +2624,11 @@ def test_recfromtxt(self):
2621
2624
assert_ (isinstance (test , np .recarray ))
2622
2625
assert_equal (test , control )
2623
2626
2624
- def test_recfromcsv (self ):
2627
+ @pytest .mark .parametrize ("filename_type" , [Path , str ])
2628
+ def test_recfromcsv (self , filename_type ):
2625
2629
with temppath (suffix = '.txt' ) as path :
2626
- path = Path (path )
2627
- with path . open ('w' ) as f :
2630
+ path = filename_type (path )
2631
+ with open (path , 'w' ) as f :
2628
2632
f .write ('A,B\n 0,1\n 2,3' )
2629
2633
2630
2634
kwargs = dict (missing_values = "N/A" , names = True , case_sensitive = True )
0 commit comments