Mercurial > public > mercurial-scm > hg-stable
diff contrib/python-zstandard/tests/test_train_dictionary.py @ 43999:de7838053207
zstandard: vendor python-zstandard 0.13.0
Version 0.13.0 of the package was just released. It contains
an upgraded zstd C library which can result in some performance
wins, official support for Python 3.8, and a blackened code base.
There were no meaningful code or functionality changes in this
release of python-zstandard: just reformatting and an upgraded
zstd library version. So the diff seems much larger than what it
is.
Files were added without modifications.
The clang-format-ignorelist file was updated to reflect a new
header file in the zstd distribution.
# no-check-commit because 3rd party code has different style guidelines
Differential Revision: https://phab.mercurial-scm.org/D7770
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 28 Dec 2019 09:55:45 -0800 |
parents | 69de49c4e39c |
children | 5e84a96d865b |
line wrap: on
line diff
--- a/contrib/python-zstandard/tests/test_train_dictionary.py Fri Dec 27 18:54:57 2019 -0500 +++ b/contrib/python-zstandard/tests/test_train_dictionary.py Sat Dec 28 09:55:45 2019 -0800 @@ -4,10 +4,11 @@ import zstandard as zstd -from . common import ( +from .common import ( generate_samples, make_cffi, random_input_data, + TestCase, ) if sys.version_info[0] >= 3: @@ -17,24 +18,24 @@ @make_cffi -class TestTrainDictionary(unittest.TestCase): +class TestTrainDictionary(TestCase): def test_no_args(self): with self.assertRaises(TypeError): zstd.train_dictionary() def test_bad_args(self): with self.assertRaises(TypeError): - zstd.train_dictionary(8192, u'foo') + zstd.train_dictionary(8192, u"foo") with self.assertRaises(ValueError): - zstd.train_dictionary(8192, [u'foo']) + zstd.train_dictionary(8192, [u"foo"]) def test_no_params(self): d = zstd.train_dictionary(8192, random_input_data()) self.assertIsInstance(d.dict_id(), int_type) # The dictionary ID may be different across platforms. - expected = b'\x37\xa4\x30\xec' + struct.pack('<I', d.dict_id()) + expected = b"\x37\xa4\x30\xec" + struct.pack("<I", d.dict_id()) data = d.as_bytes() self.assertEqual(data[0:8], expected) @@ -44,46 +45,48 @@ self.assertIsInstance(d.dict_id(), int_type) data = d.as_bytes() - self.assertEqual(data[0:4], b'\x37\xa4\x30\xec') + self.assertEqual(data[0:4], b"\x37\xa4\x30\xec") self.assertEqual(d.k, 64) self.assertEqual(d.d, 16) def test_set_dict_id(self): - d = zstd.train_dictionary(8192, generate_samples(), k=64, d=16, - dict_id=42) + d = zstd.train_dictionary(8192, generate_samples(), k=64, d=16, dict_id=42) self.assertEqual(d.dict_id(), 42) def test_optimize(self): - d = zstd.train_dictionary(8192, generate_samples(), threads=-1, steps=1, - d=16) + d = zstd.train_dictionary(8192, generate_samples(), threads=-1, steps=1, d=16) # This varies by platform. self.assertIn(d.k, (50, 2000)) self.assertEqual(d.d, 16) + @make_cffi -class TestCompressionDict(unittest.TestCase): +class TestCompressionDict(TestCase): def test_bad_mode(self): - with self.assertRaisesRegexp(ValueError, 'invalid dictionary load mode'): - zstd.ZstdCompressionDict(b'foo', dict_type=42) + with self.assertRaisesRegex(ValueError, "invalid dictionary load mode"): + zstd.ZstdCompressionDict(b"foo", dict_type=42) def test_bad_precompute_compress(self): d = zstd.train_dictionary(8192, generate_samples(), k=64, d=16) - with self.assertRaisesRegexp(ValueError, 'must specify one of level or '): + with self.assertRaisesRegex(ValueError, "must specify one of level or "): d.precompute_compress() - with self.assertRaisesRegexp(ValueError, 'must only specify one of level or '): - d.precompute_compress(level=3, - compression_params=zstd.CompressionParameters()) + with self.assertRaisesRegex(ValueError, "must only specify one of level or "): + d.precompute_compress( + level=3, compression_params=zstd.CompressionParameters() + ) def test_precompute_compress_rawcontent(self): - d = zstd.ZstdCompressionDict(b'dictcontent' * 64, - dict_type=zstd.DICT_TYPE_RAWCONTENT) + d = zstd.ZstdCompressionDict( + b"dictcontent" * 64, dict_type=zstd.DICT_TYPE_RAWCONTENT + ) d.precompute_compress(level=1) - d = zstd.ZstdCompressionDict(b'dictcontent' * 64, - dict_type=zstd.DICT_TYPE_FULLDICT) - with self.assertRaisesRegexp(zstd.ZstdError, 'unable to precompute dictionary'): + d = zstd.ZstdCompressionDict( + b"dictcontent" * 64, dict_type=zstd.DICT_TYPE_FULLDICT + ) + with self.assertRaisesRegex(zstd.ZstdError, "unable to precompute dictionary"): d.precompute_compress(level=1)