File: compatibility_test.py

package info (click to toggle)
brotli 0.5.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 18,544 kB
  • ctags: 1,731
  • sloc: ansic: 39,873; cpp: 834; python: 431; makefile: 65; sh: 57
file content (30 lines) | stat: -rwxr-xr-x 1,012 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
#!/usr/bin/env python
from __future__ import print_function
import glob
import sys
import os
from subprocess import check_call

from test_utils import PYTHON, BRO, TEST_ENV, diff_q


os.chdir(os.path.abspath("../../tests"))
for filename in glob.glob("testdata/*.compressed*"):
    filename = os.path.abspath(filename)
    print('Testing decompression of file "%s"' % os.path.basename(filename))
    expected = filename.split(".compressed")[0]
    uncompressed = expected + ".uncompressed"
    check_call([PYTHON, BRO, "-f", "-d", "-i", filename, "-o", uncompressed],
               env=TEST_ENV)
    if diff_q(uncompressed, expected) != 0:
        sys.exit(1)
    # Test the streaming version
    with open(filename, "rb") as infile, open(uncompressed, "wb") as outfile:
        check_call([PYTHON, BRO, '-d'], stdin=infile, stdout=outfile,
                   env=TEST_ENV)
    if diff_q(uncompressed, expected) != 0:
        sys.exit(1)
    try:
        os.unlink(uncompressed)
    except OSError:
        pass