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
|
import os
import platform
import shutil
import pytest # type: ignore
from ppmd import main
testdata_path = os.path.join(os.path.dirname(__file__), 'data')
source = b'This file is located in a folder.This file is located in the root.\n'
@pytest.mark.skipif(platform.machine() in ("aarch64", "armv7", "ppc64le", "s390x"),
reason="argparse help may have a bug around print function in some arches.")
def test_cli_help(capsys):
expected = '''usage: ppmd [-h] [-x] [-c] [-7] target
ppmd
positional arguments:
target
options:
-h, --help show this help message and exit
-x Specify decompression
-c Output to stdout
-7, --seven Compress with PPMd ver.H instead of Ver.I
'''
with pytest.raises(SystemExit):
main(["-h"])
out, err = capsys.readouterr()
assert out.startswith(expected)
def test_cli_extract(tmp_path):
arcfile = os.path.join(testdata_path, "data.ppmd")
shutil.copy(arcfile, tmp_path.joinpath('data.ppmd'))
target = str(tmp_path.joinpath('data.ppmd'))
extracted = tmp_path.joinpath('data')
main(["-x", target])
#
result = extracted.open('rb').read()
assert result == source
def test_cli_extract_stdout(capsysbinary, tmp_path):
arcfile = os.path.join(testdata_path, "data.ppmd")
shutil.copy(arcfile, tmp_path.joinpath('data.ppmd'))
target = str(tmp_path.joinpath('data.ppmd'))
main(["-x", "-c", target])
captured = capsysbinary.readouterr()
assert captured.out == source
def test_cli_compress(tmp_path):
arcfile = os.path.join(testdata_path, "10000SalesRecords.csv")
shutil.copy(arcfile, tmp_path.joinpath('10000SalesRecords.csv'))
target = str(tmp_path.joinpath('10000SalesRecords.csv'))
main([target])
def test_cli_compress7(tmp_path):
arcfile = os.path.join(testdata_path, "10000SalesRecords.csv")
shutil.copy(arcfile, tmp_path.joinpath('10000SalesRecords.csv'))
target = str(tmp_path.joinpath('10000SalesRecords.csv'))
main(["-7", target])
|