-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathtest_command_line.py
118 lines (78 loc) · 2.97 KB
/
test_command_line.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
108
109
110
111
112
113
114
115
116
117
118
import os
import config
import utils
import pytest
from command_line import CommandBase
# api = pytest.mark.skipif(
# not pytest.Config.getoption("--runapi"),
# reason="need --runapi option to run"
# )
@pytest.fixture(scope="module")
def command_base():
config.TESTING = True
dpath = utils.get_data_path("")
if os.path.exists(dpath):
utils.rmtree(dpath)
base = CommandBase()
base._project_name = "Test"
return base
def test_get_versions(command_base):
assert command_base.get_setting("nw_version").values == []
command_base.get_versions()
command_base.setup_nw_versions()
assert "0.13.2" in command_base.get_setting("nw_version").values
def test_get_settings(command_base):
settings = command_base.get_settings()
assert "download_settings" in settings
assert "web2exe_settings" in settings
assert "window_settings" in settings
assert "app_settings" in settings
assert "compression" in settings
def test_sub_output_pattern(command_base):
pattern_setting = command_base.get_setting("output_pattern")
command_base.get_setting("name").value = "Test"
pattern_setting.value = "%(name) 123"
value = command_base.sub_pattern()
assert value == "Test 123"
def test_multiple_sub_output_pattern(command_base):
pattern_setting = command_base.get_setting("output_pattern")
command_base.get_setting("name").value = "Test"
command_base.get_setting("nw_version").value = "0.72.0"
pattern_setting.value = "%(name) 123 %(nw_version)"
value = command_base.sub_pattern()
assert value == "Test 123 0.72.0"
def test_valid_get_setting_objects(command_base):
valid_settings = ["name", "nw_version", "windows-x64", "main"]
for setting_name in valid_settings:
setting = command_base.get_setting(setting_name)
assert setting != None
def test_invalid_get_setting_objects(command_base):
invalid_settings = ["foo", "bar", "steve", "der"]
for setting_name in invalid_settings:
setting = command_base.get_setting(setting_name)
assert setting == None
def test_get_default_nwjs_branch(command_base):
import re
branch = command_base.get_default_nwjs_branch()
match = re.match("nw\d+", branch)
assert match != None
def test_get_versions(command_base):
path = utils.get_data_file_path(config.VER_FILE)
if os.path.exists(path):
os.remove(path)
command_base.get_versions()
with open(path, "r") as ver_file:
data = ver_file.read()
assert len(data) > 0
def test_download_nwjs(command_base):
command_base.get_setting("nw_version").value = "0.19.0"
command_base.get_setting("windows-x64").value = True
command_base.init()
command_base.get_files_to_download()
command_base.download_file_with_error_handling()
base, _ = os.path.split(__file__)
assert os.path.exists(
utils.path_join(
base, "test_data", "files", "downloads", "nwjs-v0.19.0-win-x64.zip"
)
)