1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
import sys |
3
|
|
|
from unittest.mock import patch |
4
|
|
|
|
5
|
|
|
import pytest |
6
|
|
|
|
7
|
|
|
from dvnv.dvnv import parse_args |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
def test_parse_args_pass(): |
11
|
|
|
with patch.object(sys, "argv", ["dvnv", "python", "dvnv"]): |
12
|
|
|
args = parse_args() |
13
|
|
|
assert args.lang == "python" |
14
|
|
|
assert args.name == "dvnv" |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
def test_parse_args_no_args(capsys): |
18
|
|
|
with patch.object(sys, "argv", ["dvnv", None, None]): |
19
|
|
|
with pytest.raises(SystemExit): |
20
|
|
|
parse_args() |
21
|
|
|
captured = capsys.readouterr() |
22
|
|
|
assert ( |
23
|
|
|
captured.err |
24
|
|
|
== "[ERR] the following arguments are required: lang, name\n" |
25
|
|
|
) |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
def test_parse_args_no_lang(capsys): |
29
|
|
|
with patch.object(sys, "argv", ["dvnv", None, "test-project"]): |
30
|
|
|
with pytest.raises(SystemExit): |
31
|
|
|
parse_args() |
32
|
|
|
captured = capsys.readouterr() |
33
|
|
|
assert captured.err == "[ERR] the following arguments are required: lang\n" |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
def test_parse_args_no_name(capsys): |
37
|
|
|
with patch.object(sys, "argv", ["dvnv", "python", None]): |
38
|
|
|
with pytest.raises(SystemExit): |
39
|
|
|
parse_args() |
40
|
|
|
captured = capsys.readouterr() |
41
|
|
|
assert captured.err == "[ERR] the following arguments are required: name\n" |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
def test_parse_args_install_scripts(): |
45
|
|
|
with patch.object(sys, "argv", ["dvnv", None, None, "--install_scripts"]): |
46
|
|
|
assert parse_args() |
47
|
|
|
|