summaryrefslogtreecommitdiff
path: root/tests/frontend/main.py
blob: c330c39d9437fd8138952f063f3f02f66cbda847 (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
from buildstream._frontend.app import _prefix_choice_value_proc

import pytest
import click


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

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


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

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


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

    assert ("bar" == value_proc("bar"))
    assert ("baz" == value_proc("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")