Mercurial > hg
comparison contrib/python-zstandard/tests/test_data_structures.py @ 44147:5e84a96d865b
python-zstandard: blacken at 80 characters
I made this change upstream and it will make it into the next
release of python-zstandard. I figured I'd send it Mercurial's
way because it will allow us to drop this directory from the black
exclusion list.
# skip-blame blackening
Differential Revision: https://phab.mercurial-scm.org/D7937
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 22 Jan 2020 22:23:04 -0800 |
parents | de7838053207 |
children |
comparison
equal
deleted
inserted
replaced
44146:45ec64d93b3a | 44147:5e84a96d865b |
---|---|
63 self.assertEqual(p.compression_level, 2) | 63 self.assertEqual(p.compression_level, 2) |
64 | 64 |
65 p = zstd.ZstdCompressionParameters(threads=4) | 65 p = zstd.ZstdCompressionParameters(threads=4) |
66 self.assertEqual(p.threads, 4) | 66 self.assertEqual(p.threads, 4) |
67 | 67 |
68 p = zstd.ZstdCompressionParameters(threads=2, job_size=1048576, overlap_log=6) | 68 p = zstd.ZstdCompressionParameters( |
69 threads=2, job_size=1048576, overlap_log=6 | |
70 ) | |
69 self.assertEqual(p.threads, 2) | 71 self.assertEqual(p.threads, 2) |
70 self.assertEqual(p.job_size, 1048576) | 72 self.assertEqual(p.job_size, 1048576) |
71 self.assertEqual(p.overlap_log, 6) | 73 self.assertEqual(p.overlap_log, 6) |
72 self.assertEqual(p.overlap_size_log, 6) | 74 self.assertEqual(p.overlap_size_log, 6) |
73 | 75 |
126 | 128 |
127 def test_ldm_hash_rate_log(self): | 129 def test_ldm_hash_rate_log(self): |
128 with self.assertRaisesRegex( | 130 with self.assertRaisesRegex( |
129 ValueError, "cannot specify both ldm_hash_rate_log" | 131 ValueError, "cannot specify both ldm_hash_rate_log" |
130 ): | 132 ): |
131 zstd.ZstdCompressionParameters(ldm_hash_rate_log=8, ldm_hash_every_log=4) | 133 zstd.ZstdCompressionParameters( |
134 ldm_hash_rate_log=8, ldm_hash_every_log=4 | |
135 ) | |
132 | 136 |
133 p = zstd.ZstdCompressionParameters(ldm_hash_rate_log=8) | 137 p = zstd.ZstdCompressionParameters(ldm_hash_rate_log=8) |
134 self.assertEqual(p.ldm_hash_every_log, 8) | 138 self.assertEqual(p.ldm_hash_every_log, 8) |
135 | 139 |
136 p = zstd.ZstdCompressionParameters(ldm_hash_every_log=16) | 140 p = zstd.ZstdCompressionParameters(ldm_hash_every_log=16) |
137 self.assertEqual(p.ldm_hash_every_log, 16) | 141 self.assertEqual(p.ldm_hash_every_log, 16) |
138 | 142 |
139 def test_overlap_log(self): | 143 def test_overlap_log(self): |
140 with self.assertRaisesRegex(ValueError, "cannot specify both overlap_log"): | 144 with self.assertRaisesRegex( |
145 ValueError, "cannot specify both overlap_log" | |
146 ): | |
141 zstd.ZstdCompressionParameters(overlap_log=1, overlap_size_log=9) | 147 zstd.ZstdCompressionParameters(overlap_log=1, overlap_size_log=9) |
142 | 148 |
143 p = zstd.ZstdCompressionParameters(overlap_log=2) | 149 p = zstd.ZstdCompressionParameters(overlap_log=2) |
144 self.assertEqual(p.overlap_log, 2) | 150 self.assertEqual(p.overlap_log, 2) |
145 self.assertEqual(p.overlap_size_log, 2) | 151 self.assertEqual(p.overlap_size_log, 2) |
167 else: | 173 else: |
168 with self.assertRaises(zstd.ZstdError): | 174 with self.assertRaises(zstd.ZstdError): |
169 zstd.get_frame_parameters(u"foobarbaz") | 175 zstd.get_frame_parameters(u"foobarbaz") |
170 | 176 |
171 def test_invalid_input_sizes(self): | 177 def test_invalid_input_sizes(self): |
172 with self.assertRaisesRegex(zstd.ZstdError, "not enough data for frame"): | 178 with self.assertRaisesRegex( |
179 zstd.ZstdError, "not enough data for frame" | |
180 ): | |
173 zstd.get_frame_parameters(b"") | 181 zstd.get_frame_parameters(b"") |
174 | 182 |
175 with self.assertRaisesRegex(zstd.ZstdError, "not enough data for frame"): | 183 with self.assertRaisesRegex( |
184 zstd.ZstdError, "not enough data for frame" | |
185 ): | |
176 zstd.get_frame_parameters(zstd.FRAME_HEADER) | 186 zstd.get_frame_parameters(zstd.FRAME_HEADER) |
177 | 187 |
178 def test_invalid_frame(self): | 188 def test_invalid_frame(self): |
179 with self.assertRaisesRegex(zstd.ZstdError, "Unknown frame descriptor"): | 189 with self.assertRaisesRegex(zstd.ZstdError, "Unknown frame descriptor"): |
180 zstd.get_frame_parameters(b"foobarbaz") | 190 zstd.get_frame_parameters(b"foobarbaz") |
199 self.assertEqual(params.window_size, 1024) | 209 self.assertEqual(params.window_size, 1024) |
200 self.assertEqual(params.dict_id, 0) | 210 self.assertEqual(params.dict_id, 0) |
201 self.assertTrue(params.has_checksum) | 211 self.assertTrue(params.has_checksum) |
202 | 212 |
203 # Upper 2 bits indicate content size. | 213 # Upper 2 bits indicate content size. |
204 params = zstd.get_frame_parameters(zstd.FRAME_HEADER + b"\x40\x00\xff\x00") | 214 params = zstd.get_frame_parameters( |
215 zstd.FRAME_HEADER + b"\x40\x00\xff\x00" | |
216 ) | |
205 self.assertEqual(params.content_size, 511) | 217 self.assertEqual(params.content_size, 511) |
206 self.assertEqual(params.window_size, 1024) | 218 self.assertEqual(params.window_size, 1024) |
207 self.assertEqual(params.dict_id, 0) | 219 self.assertEqual(params.dict_id, 0) |
208 self.assertFalse(params.has_checksum) | 220 self.assertFalse(params.has_checksum) |
209 | 221 |
213 self.assertEqual(params.window_size, 262144) | 225 self.assertEqual(params.window_size, 262144) |
214 self.assertEqual(params.dict_id, 0) | 226 self.assertEqual(params.dict_id, 0) |
215 self.assertFalse(params.has_checksum) | 227 self.assertFalse(params.has_checksum) |
216 | 228 |
217 # Set multiple things. | 229 # Set multiple things. |
218 params = zstd.get_frame_parameters(zstd.FRAME_HEADER + b"\x45\x40\x0f\x10\x00") | 230 params = zstd.get_frame_parameters( |
231 zstd.FRAME_HEADER + b"\x45\x40\x0f\x10\x00" | |
232 ) | |
219 self.assertEqual(params.content_size, 272) | 233 self.assertEqual(params.content_size, 272) |
220 self.assertEqual(params.window_size, 262144) | 234 self.assertEqual(params.window_size, 262144) |
221 self.assertEqual(params.dict_id, 15) | 235 self.assertEqual(params.dict_id, 15) |
222 self.assertTrue(params.has_checksum) | 236 self.assertTrue(params.has_checksum) |
223 | 237 |