| 1 | # SPDX-FileCopyrightText: 2023 Philippe Proulx <eeppeliteloop@gmail.com> |
| 2 | # SPDX-License-Identifier: MIT |
| 3 | |
| 4 | import bz2 |
| 5 | import gzip |
| 6 | import typing |
| 7 | |
| 8 | import normand |
| 9 | |
| 10 | |
| 11 | def _test_comp(type: str, dec_func: typing.Callable[[bytes], bytes]): |
| 12 | data = b"bonjour tout le monde \x00\x23\x42 \x17" + b"\x7b" * 500 |
| 13 | ntext = "!t {} {} !end".format(type, data.hex()) |
| 14 | res = normand.parse(ntext) |
| 15 | assert dec_func(res.data) == data |
| 16 | |
| 17 | |
| 18 | def test_gz(): |
| 19 | _test_comp("gz", gzip.decompress) |
| 20 | |
| 21 | |
| 22 | def test_bz2(): |
| 23 | _test_comp("bz2", bz2.decompress) |