File: test.py

package info (click to toggle)
pylzss 0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 212 kB
  • sloc: ansic: 568; python: 65; sh: 7; makefile: 2
file content (68 lines) | stat: -rw-r--r-- 1,979 bytes parent folder | download | duplicates (2)
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
# Unit test for the Python LZSS wrapper

# Copyright (C) 2013 Plastic Logic Limited
#
#     Guillaume Tucker <guillaume.tucker@plasticlogic.com>
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
# License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function

import os
import sys
import lzss

def test_buffer(data):
    data_lzss = lzss.compress(data)
    data_orig = lzss.decompress(data_lzss)
    return data == data_orig

def main(argv):
    data = b"""\
Lorem ipsum dolor sit amet, consectetur
adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris nisi
ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint
occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id
est laborum."""

    result = True

    tests = { 'buffer': test_buffer }

    for name, f in tests.items():
        print("Test: {}... ".format(name), end='')
        if f(data) is False:
            result = False
            print("FAILED")
        else:
            print("PASSED")

    if result is True:
        print("All tests passed OK.")
    else:
        print("Some tests failed.")

    return result


if __name__ == '__main__':
    ret = main(sys.argv)
    sys.exit(0 if ret is True else 1)