-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_cli.py
107 lines (76 loc) · 2.39 KB
/
test_cli.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import importlib.metadata
import json
import platform
import sys
import click
import pytest
from click.testing import CliRunner
import dask
import dask.cli
def test_version():
runner = CliRunner()
result = runner.invoke(dask.cli.cli, ["--version"])
assert result.exit_code == 0
assert result.output == f"cli, version {dask.__version__}\n"
def test_info_versions():
runner = CliRunner()
result = runner.invoke(dask.cli.versions)
assert result.exit_code == 0
# $ dask info versions
# will print to stdout a json like struct, so result.output can be
# loaded with json.
table = json.loads(result.output)
assert table["Python"] == ".".join(str(x) for x in sys.version_info[:3])
assert table["dask"] == dask.__version__
assert table["Platform"] == platform.uname().system
try:
from distributed import __version__ as distributed_version
except ImportError:
distributed_version = None
assert table["distributed"] == distributed_version
@click.group
def dummy_cli():
pass
def bad_command():
pass
@click.command(name="good")
def good_command():
pass
@click.command(name="good")
def good_command_2():
pass
def test_register_command_ep():
from dask.cli import _register_command_ep
bad_ep = importlib.metadata.EntryPoint(
name="bad",
value="dask.tests.test_cli:bad_command",
group="dask_cli",
)
good_ep = importlib.metadata.EntryPoint(
name="good",
value="dask.tests.test_cli:good_command",
group="dask_cli",
)
with pytest.warns(UserWarning, match="must be instances of"):
_register_command_ep(dummy_cli, bad_ep)
_register_command_ep(dummy_cli, good_ep)
assert "good" in dummy_cli.commands
assert dummy_cli.commands["good"] is good_command
@click.group
def dummy_cli_2():
pass
def test_repeated_name_registration_warn():
from dask.cli import _register_command_ep
one = importlib.metadata.EntryPoint(
name="one",
value="dask.tests.test_cli:good_command",
group="dask_cli",
)
two = importlib.metadata.EntryPoint(
name="two",
value="dask.tests.test_cli:good_command_2",
group="dask_cli",
)
_register_command_ep(dummy_cli_2, one)
with pytest.warns(UserWarning, match="While registering the command with name"):
_register_command_ep(dummy_cli_2, two)