File: test_compatibility.py

package info (click to toggle)
python-brotlicffi 1.1.0.0%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 164 kB
  • sloc: python: 642; makefile: 8
file content (44 lines) | stat: -rw-r--r-- 1,264 bytes parent folder | download
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
# -*- coding: utf-8 -*-
"""
test_compatibility
~~~~~~~~~~~~~~~~~~

Tests for names that exist purely for compatibility purposes.
"""
import re
from os.path import abspath, join, dirname
import brotlicffi


def test_compatible_names():
    """
    Encoder modes are also defined as individual top-level names with the same
    names as in brotlimodule.cc from the library.
    """
    assert brotlicffi.MODE_GENERIC is brotlicffi.BrotliEncoderMode.GENERIC
    assert brotlicffi.MODE_TEXT is brotlicffi.BrotliEncoderMode.TEXT
    assert brotlicffi.MODE_FONT is brotlicffi.BrotliEncoderMode.FONT


def test_brotli_version():
    """
    Test that the __version__ starts with the
    Brotli version that's compiled with.
    """
    version_h = join(
        dirname(dirname(abspath(__file__))), "libbrotli/c/common/version.h"
    )
    with open(version_h) as f:
        brotli_versions = dict(
            re.findall(
                r"#define BROTLI_VERSION_(MAJOR|MINOR|PATCH) ([0-9]+)",
                f.read()
            )
        )
        assert brotlicffi.__version__.startswith(
            "%s.%s.%s." % (
                brotli_versions["MAJOR"],
                brotli_versions["MINOR"],
                brotli_versions["PATCH"]
            )
        )