@@ -22,7 +22,22 @@ def test_read_dx():
2222 assert_equal (g .origin , np .array ([20.1 , 3. , - 10. ]))
2323
2424
25- def _test_write_dx (tmpdir , counts = 100 , ndim = 3 , nptype = "float32" , dxtype = "float" ):
25+ @pytest .mark .parametrize ("nptype,dxtype" , [
26+ ("float16" , "float" ),
27+ ("float32" , "float" ),
28+ ("float64" , "double" ),
29+ ("int64" , "int" ),
30+ ("int32" , "int" ),
31+ ("uint32" , "unsigned int" ),
32+ ("uint64" , "unsigned int" ),
33+ ("int16" , "short" ),
34+ ("uint16" , "unsigned short" ),
35+ ("int8" , "signed byte" ),
36+ ("uint8" , "byte" ),
37+ ])
38+ def test_write_dx (tmpdir , nptype , dxtype , counts = 100 , ndim = 3 ):
39+ # conversion from numpy array to DX file
40+
2641 h , edges = np .histogramdd (np .random .random ((counts , ndim )), bins = 10 )
2742 g = Grid (h , edges )
2843
@@ -51,42 +66,19 @@ def _test_write_dx(tmpdir, counts=100, ndim=3, nptype="float32", dxtype="float")
5166
5267 assert_equal (out_dxtype , dxtype )
5368
69+ @pytest .mark .parametrize ('nptype' , ("complex64" , "complex128" , "bool_" ))
70+ @pytest .mark .filterwarnings ("ignore:array dtype.name =" )
71+ def test_write_dx_ValueError (tmpdir , nptype , counts = 100 , ndim = 3 ):
72+ h , edges = np .histogramdd (np .random .random ((counts , ndim )), bins = 10 )
73+ g = Grid (h , edges )
5474
55- # conversion from numpy array to DX file
56-
57- def test_write_dx_float_float16 (tmpdir , nptype = "float16" , dxtype = "float" ):
58- return _test_write_dx (tmpdir , nptype = nptype , dxtype = dxtype )
59-
60- def test_write_dx_float_float32 (tmpdir , nptype = "float32" , dxtype = "float" ):
61- return _test_write_dx (tmpdir , nptype = nptype , dxtype = dxtype )
62-
63- def test_write_dx_double_float64 (tmpdir , nptype = "float64" , dxtype = "double" ):
64- return _test_write_dx (tmpdir , nptype = nptype , dxtype = dxtype )
65-
66- def test_write_dx_int_int64 (tmpdir , nptype = "int64" , dxtype = "int" ):
67- return _test_write_dx (tmpdir , nptype = nptype , dxtype = dxtype )
68-
69- def test_write_dx_int_int32 (tmpdir , nptype = "int32" , dxtype = "int" ):
70- return _test_write_dx (tmpdir , nptype = nptype , dxtype = dxtype )
71-
72- def test_write_dx_unsigned_int_uint32 (tmpdir , nptype = "uint32" , dxtype = "unsigned int" ):
73- return _test_write_dx (tmpdir , nptype = nptype , dxtype = dxtype )
74-
75- def test_write_dx_unsigned_int_uint64 (tmpdir , nptype = "uint64" , dxtype = "unsigned int" ):
76- return _test_write_dx (tmpdir , nptype = nptype , dxtype = dxtype )
77-
78- def test_write_dx_short_int16 (tmpdir , nptype = "int16" , dxtype = "short" ):
79- return _test_write_dx (tmpdir , nptype = nptype , dxtype = dxtype )
75+ # hack the grid to be a different dtype
76+ g .grid = g .grid .astype (nptype )
8077
81- def test_write_dx_unsigned_short_uint16 (tmpdir , nptype = "uint16" , dxtype = "unsigned short" ):
82- return _test_write_dx (tmpdir , nptype = nptype , dxtype = dxtype )
78+ with pytest .raises (ValueError ):
79+ with tmpdir .as_cwd ():
80+ outfile = "grid.dx"
81+ g .export (outfile )
8382
84- def test_write_dx_signed_byte (tmpdir , nptype = "int8" , dxtype = "signed byte" ):
85- return _test_write_dx (tmpdir , nptype = nptype , dxtype = dxtype )
8683
87- def test_write_dx_byte (tmpdir , nptype = "uint8" , dxtype = "byte" ):
88- return _test_write_dx (tmpdir , nptype = nptype , dxtype = dxtype )
8984
90- def test_write_dx_ValueError (tmpdir , nptype = "longdouble" , dxtype = "unknown" ):
91- with pytest .raises (ValueError ):
92- _test_write_dx (tmpdir , nptype = nptype , dxtype = dxtype )
0 commit comments