-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtests.py
96 lines (83 loc) · 3.06 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import pytest
from hypothesis import given, settings, assume
from hypothesis.strategies import text
import smaz
def test_ok():
"""Simple test case."""
raw = "The quick brown fox jumps over the lazy dog."
compressed = smaz.compress(raw)
decompressed = smaz.decompress(compressed)
assert decompressed == raw
@given(text())
@settings(max_examples=10000)
def test_compress_decompress_unicode(string):
"""Verify all sorts of strings, generated by hypothesis.
This includes empty strings, very long strings, various kinds of unicode
characters etc.
"""
# Exclude strings with NULL characters in them. I am not sure this is smart. Lets
# see how people use this and if I ever get a bug report about not supporting null
# characters.
assume("\x00" not in string)
compressed = smaz.compress(string)
decompressed = smaz.decompress(compressed)
assert string == decompressed
def test_compress_non_str():
"""Verify only str being accepted by compress."""
raw = "The quick brown fox jumps over the lazy dog."
with pytest.raises(TypeError):
smaz.compress([raw])
with pytest.raises(TypeError):
smaz.compress((raw,))
with pytest.raises(TypeError):
smaz.compress({"raw": raw})
with pytest.raises(TypeError):
smaz.compress(1)
with pytest.raises(TypeError):
smaz.compress(1.5)
with pytest.raises(TypeError):
smaz.compress(raw.encode("utf-8"))
def test_compress_non_bytes():
"""Verify only bytes being accepted by decompress."""
raw = "The quick brown fox jumps over the lazy dog."
with pytest.raises(TypeError):
smaz.decompress(raw)
with pytest.raises(TypeError):
smaz.decompress([raw])
with pytest.raises(TypeError):
smaz.decompress((raw,))
with pytest.raises(TypeError):
smaz.decompress({"raw": raw})
with pytest.raises(TypeError):
smaz.decompress(1)
with pytest.raises(TypeError):
smaz.decompress(1.5)
@pytest.mark.parametrize(
"raw",
[
"This is a small string",
"foobar",
"the end",
"not-a-g00d-Exampl333",
"Smaz is a simple compression library",
"Nothing is more difficult, and therefore more precious, than to be able to decide",
"this is an example of what works very well with smaz",
"1000 numbers 2000 will 10 20 30 compress very little",
"and now a few italian sentences:",
"Nel mezzo del cammin di nostra vita, mi ritrovai in una selva oscura",
"Mi illumino di immenso",
"L'autore di questa libreria vive in Sicilia",
"try it against urls",
"http://google.com",
"http://programming.reddit.com",
"http://github.com/antirez/smaz/tree/master",
"/media/hdb1/music/Alben/The Bla",
],
)
def test_original_smaz(raw):
"""Verify functionality based on the original smaz_test.c
https://github.com/antirez/smaz/blob/master/smaz_test.c
"""
compressed = smaz.compress(raw)
decompressed = smaz.decompress(compressed)
assert decompressed == raw