| 1 |
|
| 2 |
""" |
| 3 |
test_compatibility |
| 4 |
~~~~~~~~~~~~~~~~~~ |
| 5 |
|
| 6 |
Tests for names that exist purely for compatibility purposes. |
| 7 |
""" |
| 8 |
import re |
| 9 |
from os.path import abspath, join, dirname |
| 10 |
import brotlicffi |
| 11 |
|
| 12 |
|
| 13 |
def test_compatible_names(): |
| 14 |
""" |
| 15 |
Encoder modes are also defined as individual top-level names with the same |
| 16 |
names as in brotlimodule.cc from the library. |
| 17 |
""" |
| 18 |
assert brotlicffi.MODE_GENERIC is brotlicffi.BrotliEncoderMode.GENERIC |
| 19 |
assert brotlicffi.MODE_TEXT is brotlicffi.BrotliEncoderMode.TEXT |
| 20 |
assert brotlicffi.MODE_FONT is brotlicffi.BrotliEncoderMode.FONT |
| 21 |
|
| 22 |
|
| 23 |
def test_brotli_version(): |
| 24 |
""" |
| 25 |
Test that the __version__ starts with the |
| 26 |
Brotli version that's compiled with. |
| 27 |
""" |
| 28 |
version_h = join( |
| 29 |
dirname(dirname(abspath(__file__))), "libbrotli/c/common/version.h" |
| 30 |
) |
| 31 |
with open(version_h) as f: |
| 32 |
brotli_versions = dict( |
| 33 |
re.findall( |
| 34 |
r"#define BROTLI_VERSION_(MAJOR|MINOR|PATCH) ([0-9]+)", |
| 35 |
f.read() |
| 36 |
) |
| 37 |
) |
| 38 |
assert brotlicffi.__version__.startswith( |
| 39 |
"%s.%s.%s." % ( |
| 40 |
brotli_versions["MAJOR"], |
| 41 |
brotli_versions["MINOR"], |
| 42 |
brotli_versions["PATCH"] |
| 43 |
) |
| 44 |
) |