1
1
module test_np
2
2
use stdlib_array
3
+ use stdlib_filesystem, only : temp_dir
3
4
use stdlib_kinds, only : int8, int16, int32, int64, sp, dp
4
5
use stdlib_io_np, only : save_npy, load_npy, load_npz
5
6
use testdrive, only : new_unittest, unittest_type, error_type, check, test_failed
@@ -659,9 +660,10 @@ subroutine npz_load_nonexistent_file(error)
659
660
type (t_array_wrapper), allocatable :: arrays(:)
660
661
661
662
integer :: stat
662
- character (len=* ), parameter :: filename = " nonexistent.npz"
663
+ character (* ), parameter :: filename = " nonexistent.npz"
664
+ character (* ), parameter :: tmp = temp_dir// " nonexistent"
663
665
664
- call load_npz(filename, arrays, stat)
666
+ call load_npz(filename, arrays, stat, tmp_dir = tmp )
665
667
call check(error, stat, " Loading a non-existent npz file should fail." )
666
668
end
667
669
@@ -672,9 +674,11 @@ subroutine npz_load_invalid_dir(error)
672
674
type (t_array_wrapper), allocatable :: arrays(:)
673
675
674
676
integer :: stat
675
- character (len=* ), parameter :: filename = " ."
677
+ character (* ), parameter :: filename = " ."
678
+ character (* ), parameter :: tmp = temp_dir// " invalid_dir"
676
679
677
- call load_npz(filename, arrays, stat)
680
+
681
+ call load_npz(filename, arrays, stat, tmp_dir= tmp)
678
682
call check(error, stat, " A file name that points towards a directory should fail." )
679
683
end
680
684
@@ -686,11 +690,12 @@ subroutine npz_load_empty_file(error)
686
690
687
691
integer :: io, stat
688
692
character (* ), parameter :: filename = " empty_file"
693
+ character (* ), parameter :: tmp = temp_dir// " empty_file"
689
694
690
695
open (newunit= io, file= filename)
691
696
close (io)
692
697
693
- call load_npz(filename, arrays, stat)
698
+ call load_npz(filename, arrays, stat, tmp_dir = tmp )
694
699
call check(error, stat, " Try loading an empty file as an npz file should fail." )
695
700
696
701
call delete_file(filename)
@@ -704,13 +709,14 @@ subroutine npz_load_empty_zip(error)
704
709
integer :: io, stat
705
710
706
711
character (* ), parameter :: filename = " empty.zip"
712
+ character (* ), parameter :: tmp = temp_dir// " empty_zip"
707
713
character (* ), parameter :: binary_data = ' PK' // char (5 )// char (6 )// repeat (char (0 ), 18 )
708
714
709
715
open (newunit= io, file= filename, form= ' unformatted' , access= ' stream' )
710
716
write (io) binary_data
711
717
close (io)
712
718
713
- call load_npz(filename, arrays, stat)
719
+ call load_npz(filename, arrays, stat, tmp_dir = tmp )
714
720
call check(error, stat, " Trying to load an npz file that is an empty zip file should fail." )
715
721
716
722
call delete_file(filename)
@@ -722,10 +728,12 @@ subroutine npz_load_arr_empty_0(error)
722
728
type (t_array_wrapper), allocatable :: arrays(:)
723
729
integer :: stat
724
730
character (* ), parameter :: filename = " empty_0.npz"
731
+ character (* ), parameter :: tmp = temp_dir// " empty_0"
725
732
character (:), allocatable :: path
726
733
734
+
727
735
path = get_path(filename)
728
- call load_npz(path, arrays, stat)
736
+ call load_npz(path, arrays, stat, tmp_dir = tmp )
729
737
call check(error, stat, " Loading an npz that contains a single empty array shouldn't fail." )
730
738
if (stat /= 0 ) return
731
739
call check(error, size (arrays) == 1 , " '" // filename// " ' is supposed to contain a single array." )
@@ -746,10 +754,11 @@ subroutine npz_load_arr_rand_2_3(error)
746
754
type (t_array_wrapper), allocatable :: arrays(:)
747
755
integer :: stat
748
756
character (* ), parameter :: filename = " rand_2_3.npz"
757
+ character (* ), parameter :: tmp = temp_dir// " rand_2_3"
749
758
character (:), allocatable :: path
750
759
751
760
path = get_path(filename)
752
- call load_npz(path, arrays, stat)
761
+ call load_npz(path, arrays, stat, tmp_dir = tmp )
753
762
call check(error, stat, " Loading an npz file that contains a valid nd_array shouldn't fail." )
754
763
if (stat /= 0 ) return
755
764
call check(error, size (arrays) == 1 , " '" // filename// " ' is supposed to contain a single array." )
@@ -770,10 +779,12 @@ subroutine npz_load_arr_arange_10_20(error)
770
779
type (t_array_wrapper), allocatable :: arrays(:)
771
780
integer :: stat, i
772
781
character (* ), parameter :: filename = " arange_10_20.npz"
782
+ character (* ), parameter :: tmp = temp_dir// " arange_10_20"
783
+
773
784
character (:), allocatable :: path
774
785
775
786
path = get_path(filename)
776
- call load_npz(path, arrays, stat)
787
+ call load_npz(path, arrays, stat, tmp_dir = tmp )
777
788
call check(error, stat, " Loading an npz file that contains a valid nd_array shouldn't fail." )
778
789
if (stat /= 0 ) return
779
790
call check(error, size (arrays) == 1 , " '" // filename// " ' is supposed to contain a single array." )
@@ -801,10 +812,11 @@ subroutine npz_load_arr_cmplx(error)
801
812
type (t_array_wrapper), allocatable :: arrays(:)
802
813
integer :: stat
803
814
character (* ), parameter :: filename = " cmplx_arr.npz"
815
+ character (* ), parameter :: tmp = temp_dir// " cmplx_arr"
804
816
character (:), allocatable :: path
805
817
806
818
path = get_path(filename)
807
- call load_npz(path, arrays, stat)
819
+ call load_npz(path, arrays, stat, tmp_dir = tmp )
808
820
call check(error, stat, " Loading an npz file that contains a valid nd_array shouldn't fail." )
809
821
if (stat /= 0 ) return
810
822
call check(error, size (arrays) == 1 , " '" // filename// " ' is supposed to contain a single array." )
@@ -832,10 +844,11 @@ subroutine npz_load_two_arr_iint64_rdp(error)
832
844
type (t_array_wrapper), allocatable :: arrays(:)
833
845
integer :: stat
834
846
character (* ), parameter :: filename = " two_arr_iint64_rdp.npz"
847
+ character (* ), parameter :: tmp = temp_dir// " two_arr_iint64_rdp"
835
848
character (:), allocatable :: path
836
849
837
850
path = get_path(filename)
838
- call load_npz(path, arrays, stat)
851
+ call load_npz(path, arrays, stat, tmp_dir = tmp )
839
852
call check(error, stat, " Loading an npz file that contains valid nd_arrays shouldn't fail." )
840
853
if (stat /= 0 ) return
841
854
call check(error, size (arrays) == 2 , " '" // filename// " ' is supposed to contain two arrays." )
@@ -878,10 +891,11 @@ subroutine npz_load_two_arr_iint64_rdp_comp(error)
878
891
type (t_array_wrapper), allocatable :: arrays(:)
879
892
integer :: stat, i
880
893
character (* ), parameter :: filename = " two_arr_iint64_rdp_comp.npz"
894
+ character (* ), parameter :: tmp = temp_dir// " two_arr_iint64_rdp_comp"
881
895
character (:), allocatable :: path
882
896
883
897
path = get_path(filename)
884
- call load_npz(path, arrays, stat)
898
+ call load_npz(path, arrays, stat, tmp_dir = tmp )
885
899
call check(error, stat, " Loading a compressed npz file that contains valid nd_arrays shouldn't fail." )
886
900
if (stat /= 0 ) return
887
901
call check(error, size (arrays) == 2 , " '" // filename// " ' is supposed to contain two arrays." )
0 commit comments