summaryrefslogtreecommitdiffstats
path: root/tests/test_core.py
blob: ddad4dd5f2c9e96ec7d8d7d12e55c3ee1bc9d92e (plain) (blame)
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
import click
import pickle
import pytest

from pydanclick import core
from tests import conftest


def test_get_option_arguments_ok(valid_arguments):
    core.get_option_arguments(schema, parameter, "mega-option")
    pass


def test_generate_cli_options_start():

    @click.command()
    @core.generate_cli_options()
    def entrypoint(parameters: conftest.GenericArguments):
        pass

    with pytest.raises(SystemExit):
        entrypoint()


@pytest.mark.parametrize(
    "argument_info",
    [
        ["name", ["--name"], click.STRING],
        ["version", ["--version"], click.IntRange(min=0)],
        ["force", ["--force"], click.BOOL],
        ["fruit", ["--fruit"], click.Choice(["apple", "banana", "pineapple"])],
    ]
)
def test_generate_cli_options_arguments(
    valid_command_entrypoint,
    argument_info,
):
    option = next(
        filter(
            lambda el: el.name == argument_info[0],
            valid_command_entrypoint.params
        )
    )

    assert option.opts == argument_info[1]
    assert pickle.dumps(option.type) == pickle.dumps(argument_info[2])
remember that computers suck.