1
1
import itertools
2
+ from contextlib import suppress
2
3
3
4
import numpy as np
4
5
import pytest
5
6
6
- try :
7
- from numcodecs .checksum32 import CRC32 , CRC32C , Adler32
8
- except ImportError : # pragma: no cover
9
- pytest .skip ("numcodecs.checksum32 not available" , allow_module_level = True )
10
-
7
+ from numcodecs .checksum32 import CRC32 , Adler32
11
8
from numcodecs .tests .common import (
12
9
check_backwards_compatibility ,
13
10
check_config ,
17
14
check_repr ,
18
15
)
19
16
17
+ has_crc32c = False
18
+ with suppress (ImportError ):
19
+ from numcodecs .checksum32 import CRC32C
20
+
21
+ has_crc32c = True
22
+
20
23
# mix of dtypes: integer, float, bool, string
21
24
# mix of shapes: 1D, 2D, 3D
22
25
# mix of orders: C, F
39
42
codecs = [
40
43
CRC32 (),
41
44
CRC32 (location = "end" ),
42
- CRC32C (location = "start" ),
43
- CRC32C (),
44
45
Adler32 (),
45
46
Adler32 (location = "end" ),
46
47
]
48
+ if has_crc32c :
49
+ codecs .extend (
50
+ [
51
+ CRC32C (location = "start" ),
52
+ CRC32C (),
53
+ ]
54
+ )
47
55
48
56
49
57
@pytest .mark .parametrize (("codec" , "arr" ), itertools .product (codecs , arrays ))
@@ -88,25 +96,28 @@ def test_err_encode_list(codec):
88
96
def test_err_location ():
89
97
with pytest .raises (ValueError ):
90
98
CRC32 (location = "foo" )
91
- with pytest .raises (ValueError ):
92
- CRC32C (location = "foo" )
93
99
with pytest .raises (ValueError ):
94
100
Adler32 (location = "foo" )
101
+ if has_crc32c :
102
+ with pytest .raises (ValueError ):
103
+ CRC32C (location = "foo" )
95
104
96
105
97
106
def test_repr ():
98
107
check_repr ("CRC32(location='start')" )
99
- check_repr ("CRC32C(location='start')" )
100
- check_repr ("Adler32(location='start')" )
101
108
check_repr ("CRC32(location='end')" )
102
- check_repr ("CRC32C (location='end ')" )
109
+ check_repr ("Adler32 (location='start ')" )
103
110
check_repr ("Adler32(location='end')" )
111
+ if has_crc32c :
112
+ check_repr ("CRC32C(location='start')" )
113
+ check_repr ("CRC32C(location='end')" )
104
114
105
115
106
116
def test_backwards_compatibility ():
107
117
check_backwards_compatibility (CRC32 .codec_id , arrays , [CRC32 ()])
108
118
check_backwards_compatibility (Adler32 .codec_id , arrays , [Adler32 ()])
109
- check_backwards_compatibility (CRC32C .codec_id , arrays , [CRC32C ()])
119
+ if has_crc32c :
120
+ check_backwards_compatibility (CRC32C .codec_id , arrays , [CRC32C ()])
110
121
111
122
112
123
@pytest .mark .parametrize ("codec" , codecs )
@@ -127,6 +138,7 @@ def test_err_out_too_small(codec):
127
138
codec .decode (codec .encode (arr ), out )
128
139
129
140
141
+ @pytest .mark .skipif (not has_crc32c , reason = "Needs `crc32c` installed" )
130
142
def test_crc32c_checksum ():
131
143
arr = np .arange (0 , 64 , dtype = "uint8" )
132
144
buf = CRC32C (location = "end" ).encode (arr )
0 commit comments