##// END OF EJS Templates
rust-config: add config getters that don't fall back to defaults...
rust-config: add config getters that don't fall back to defaults This is useful in cases where we access config items that are more... lenient with their types than a fresh new system would allow. For now there is only a single use of this, but we might get more later.

File last commit:

r44605:5e84a96d default
r51657:8ff187fb default
Show More
test_train_dictionary.py
102 lines | 2.8 KiB | text/x-python | PythonLexer
Gregory Szorc
zstandard: vendor python-zstandard 0.9.0...
r37513 import struct
Gregory Szorc
zstd: vendor python-zstandard 0.5.0...
r30435 import sys
Gregory Szorc
zstandard: vendor python-zstandard 0.9.0...
r37513 import unittest
Gregory Szorc
zstd: vendor python-zstandard 0.5.0...
r30435
Gregory Szorc
zstandard: vendor python-zstandard 0.9.0...
r37513 import zstandard as zstd
Gregory Szorc
zstd: vendor python-zstandard 0.5.0...
r30435
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 from .common import (
Gregory Szorc
zstandard: vendor python-zstandard 0.9.0...
r37513 generate_samples,
Gregory Szorc
zstd: vendor python-zstandard 0.7.0...
r30895 make_cffi,
Gregory Szorc
zstandard: vendor python-zstandard 0.12...
r43207 random_input_data,
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 TestCase,
Gregory Szorc
zstd: vendor python-zstandard 0.7.0...
r30895 )
Gregory Szorc
zstd: vendor python-zstandard 0.5.0...
r30435
if sys.version_info[0] >= 3:
int_type = int
else:
int_type = long
Gregory Szorc
zstd: vendor python-zstandard 0.7.0...
r30895 @make_cffi
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 class TestTrainDictionary(TestCase):
Gregory Szorc
zstd: vendor python-zstandard 0.5.0...
r30435 def test_no_args(self):
with self.assertRaises(TypeError):
zstd.train_dictionary()
def test_bad_args(self):
with self.assertRaises(TypeError):
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 zstd.train_dictionary(8192, u"foo")
Gregory Szorc
zstd: vendor python-zstandard 0.5.0...
r30435
with self.assertRaises(ValueError):
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 zstd.train_dictionary(8192, [u"foo"])
Gregory Szorc
zstd: vendor python-zstandard 0.5.0...
r30435
Gregory Szorc
zstandard: vendor python-zstandard 0.9.0...
r37513 def test_no_params(self):
Gregory Szorc
zstandard: vendor python-zstandard 0.12...
r43207 d = zstd.train_dictionary(8192, random_input_data())
Gregory Szorc
zstandard: vendor python-zstandard 0.9.0...
r37513 self.assertIsInstance(d.dict_id(), int_type)
Gregory Szorc
zstd: vendor python-zstandard 0.5.0...
r30435
Gregory Szorc
zstandard: vendor python-zstandard 0.9.0...
r37513 # The dictionary ID may be different across platforms.
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 expected = b"\x37\xa4\x30\xec" + struct.pack("<I", d.dict_id())
Gregory Szorc
zstd: vendor python-zstandard 0.5.0...
r30435
data = d.as_bytes()
Gregory Szorc
zstandard: vendor python-zstandard 0.9.0...
r37513 self.assertEqual(data[0:8], expected)
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796
def test_basic(self):
Gregory Szorc
zstandard: vendor python-zstandard 0.9.0...
r37513 d = zstd.train_dictionary(8192, generate_samples(), k=64, d=16)
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796 self.assertIsInstance(d.dict_id(), int_type)
data = d.as_bytes()
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 self.assertEqual(data[0:4], b"\x37\xa4\x30\xec")
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796
self.assertEqual(d.k, 64)
self.assertEqual(d.d, 16)
def test_set_dict_id(self):
Gregory Szorc
python-zstandard: blacken at 80 characters...
r44605 d = zstd.train_dictionary(
8192, generate_samples(), k=64, d=16, dict_id=42
)
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796 self.assertEqual(d.dict_id(), 42)
def test_optimize(self):
Gregory Szorc
python-zstandard: blacken at 80 characters...
r44605 d = zstd.train_dictionary(
8192, generate_samples(), threads=-1, steps=1, d=16
)
Gregory Szorc
zstandard: vendor python-zstandard 0.9.0...
r37513
Gregory Szorc
zstandard: vendor python-zstandard 0.10.1...
r40157 # This varies by platform.
self.assertIn(d.k, (50, 2000))
Gregory Szorc
zstandard: vendor python-zstandard 0.9.0...
r37513 self.assertEqual(d.d, 16)
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446
Gregory Szorc
zstandard: vendor python-zstandard 0.9.0...
r37513 @make_cffi
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 class TestCompressionDict(TestCase):
Gregory Szorc
zstandard: vendor python-zstandard 0.9.0...
r37513 def test_bad_mode(self):
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 with self.assertRaisesRegex(ValueError, "invalid dictionary load mode"):
zstd.ZstdCompressionDict(b"foo", dict_type=42)
Gregory Szorc
zstandard: vendor python-zstandard 0.9.0...
r37513
def test_bad_precompute_compress(self):
d = zstd.train_dictionary(8192, generate_samples(), k=64, d=16)
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796
Gregory Szorc
python-zstandard: blacken at 80 characters...
r44605 with self.assertRaisesRegex(
ValueError, "must specify one of level or "
):
Gregory Szorc
zstandard: vendor python-zstandard 0.9.0...
r37513 d.precompute_compress()
Gregory Szorc
python-zstandard: blacken at 80 characters...
r44605 with self.assertRaisesRegex(
ValueError, "must only specify one of level or "
):
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 d.precompute_compress(
level=3, compression_params=zstd.CompressionParameters()
)
Gregory Szorc
zstd: vendor python-zstandard 0.8.0...
r31796
Gregory Szorc
zstandard: vendor python-zstandard 0.9.0...
r37513 def test_precompute_compress_rawcontent(self):
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 d = zstd.ZstdCompressionDict(
b"dictcontent" * 64, dict_type=zstd.DICT_TYPE_RAWCONTENT
)
Gregory Szorc
zstandard: vendor python-zstandard 0.9.0...
r37513 d.precompute_compress(level=1)
Gregory Szorc
zstandard: vendor python-zstandard 0.13.0...
r44446 d = zstd.ZstdCompressionDict(
b"dictcontent" * 64, dict_type=zstd.DICT_TYPE_FULLDICT
)
Gregory Szorc
python-zstandard: blacken at 80 characters...
r44605 with self.assertRaisesRegex(
zstd.ZstdError, "unable to precompute dictionary"
):
Gregory Szorc
zstandard: vendor python-zstandard 0.9.0...
r37513 d.precompute_compress(level=1)