File: test_cli.py

package info (click to toggle)
python-ppmd 0.3.3-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,628 kB
  • sloc: ansic: 3,015; python: 798; cpp: 23; makefile: 20; sh: 17
file content (63 lines) | stat: -rw-r--r-- 1,842 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
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
import os
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'


def test_cli_help(capsys):
    expected = '''usage: ppmd [-h] [-x] [-c] [-7] target

ppmd

positional arguments:
  target

optional arguments:
  -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])