summaryrefslogtreecommitdiff
path: root/tests/frontend/main.py
blob: 0df52e2c9213b228639283635365128c3fabe7c3 (plain)
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
import click
import pytest

from buildstream._frontend.app import _prefix_choice_value_proc


def test_prefix_choice_value_proc_full_match():
    value_proc = _prefix_choice_value_proc(['foo', 'bar', 'baz'])

    assert value_proc("foo") == "foo"
    assert value_proc("bar") == "bar"
    assert value_proc("baz") == "baz"


def test_prefix_choice_value_proc_prefix_match():
    value_proc = _prefix_choice_value_proc(['foo'])

    assert value_proc("f") == "foo"


def test_prefix_choice_value_proc_ambigous_match():
    value_proc = _prefix_choice_value_proc(['bar', 'baz'])

    assert value_proc("bar") == "bar"
    assert value_proc("baz") == "baz"
    with pytest.raises(click.UsageError):
        value_proc("ba")


def test_prefix_choice_value_proc_value_not_in_choices():
    value_proc = _prefix_choice_value_proc(['bar', 'baz'])

    with pytest.raises(click.UsageError):
        value_proc("foo")