-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest_vscode.py
82 lines (61 loc) · 2.17 KB
/
test_vscode.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
from __future__ import annotations
import os
import textwrap
import pytest
from _pytask.vscode import send_logging_info, validate_and_return_port
from pytask import ExitCode
from pytask import cli
def test_validate_and_return_port_valid_port():
assert validate_and_return_port("6000") == 6000
def test_validate_and_return_port_invalid_port():
with pytest.raises(ValueError):
validate_and_return_port("not_an_integer")
@pytest.mark.end_to_end()
def test_vscode_collect_failed(runner, tmp_path):
source = """
raise Exception
"""
os.environ["PYTASK_VSCODE"] = "6000"
tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source))
result = runner.invoke(cli, ["collect", tmp_path.as_posix()])
assert result.exit_code == ExitCode.COLLECTION_FAILED
@pytest.mark.end_to_end()
def test_vscode_collect(runner, tmp_path):
source = """
def task_example():
return
"""
os.environ["PYTASK_VSCODE"] = "6000"
tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source))
result = runner.invoke(cli, ["collect", tmp_path.as_posix()])
assert result.exit_code == ExitCode.OK
@pytest.mark.end_to_end()
def test_vscode_build(runner, tmp_path):
source = """
def task_example():
return
def task_raises():
raise Exception
"""
os.environ["PYTASK_VSCODE"] = "6000"
tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source))
result = runner.invoke(cli, [tmp_path.as_posix()])
assert result.exit_code == ExitCode.FAILED
@pytest.mark.end_to_end()
def test_vscode_env_variable(runner, tmp_path):
source = """
def task_example():
return
"""
os.environ["PYTASK_VSCODE"] = "TEST"
tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source))
result = runner.invoke(cli, ["collect", tmp_path.as_posix()])
assert result.exit_code == ExitCode.OK
result = runner.invoke(cli, [tmp_path.as_posix()])
assert result.exit_code == ExitCode.OK
@pytest.mark.unit()
def test_send_logging_info():
url = "http://localhost:6000/pytask/run"
data = {"test": "test"}
timeout = 0.00001
send_logging_info(url, data, timeout)