File size: 1,727 Bytes
1a8d642
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pytest

from handportal.cli import parse_args


def test_cli_overrides_runtime_options():
    args = parse_args(["--camera", "2", "--width", "640", "--height", "360", "--windowed"])
    assert (args.camera, args.width, args.height) == (2, 640, 360)
    assert args.windowed is True


def test_cli_rejects_invalid_dimensions():
    with pytest.raises(SystemExit):
        parse_args(["--width", "0"])


def test_cli_rejects_oversized_dimensions():
    # Only "positive" was checked, so --width 100000 reached
    # make_vignette_layer at startup and died allocating a gigantic
    # array instead of failing with a clear usage error.
    with pytest.raises(SystemExit):
        parse_args(["--width", "100000", "--height", "720"])
    with pytest.raises(SystemExit):
        parse_args(["--width", "1280", "--height", "5000"])


def test_cli_accepts_8k_dimensions():
    args = parse_args(["--width", "7680", "--height", "4320"])
    assert (args.width, args.height) == (7680, 4320)


def test_cli_rejects_negative_camera_index():
    with pytest.raises(SystemExit):
        parse_args(["--camera", "-1"])


def test_cli_rejects_out_of_range_pinch_threshold():
    with pytest.raises(SystemExit):
        parse_args(["--pinch-threshold", "0.5"])


def test_cli_rejects_missing_model_file():
    # A typo'd --model path used to silently download a fresh model to the
    # mistyped path instead of failing fast.
    with pytest.raises(SystemExit):
        parse_args(["--model", "no-such-model.task"])


def test_cli_accepts_existing_model_file(tmp_path):
    model = tmp_path / "hand_landmarker.task"
    model.write_bytes(b"fake-model")
    args = parse_args(["--model", str(model)])
    assert args.model == str(model)