Edit

kc3-lang/brotli/python/tests/compatibility_test.py

Branch :

  • Show log

    Commit

  • Author : Alex Nicksay
    Date : 2016-11-09 06:21:13
    Hash : 1e5ea6ae
    Message : Python: Add unit tests for brotli.compress and brotli.decompress (#467) Also - rename `test_utils` to `_test_utils` - refactor shared code into `_test_utils`

  • python/tests/compatibility_test.py
  • #!/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