Skip to content

Commit ba2f62a

Browse files
committed
Add a few tests to get test directory started
1 parent 69b420c commit ba2f62a

File tree

5 files changed

+106
-4
lines changed

5 files changed

+106
-4
lines changed

SETUP.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,14 @@ Once all of the above are installed, simply run:
4747
```
4848
python3.4 main.py
4949
```
50+
51+
##Tests
52+
53+
Tests are located in the tests directory and were created with pytest.
54+
They can be run with:
55+
56+
```
57+
pytest
58+
```
59+
60+
in the root directory.

requirements.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
appdirs
2+
configobj
3+
https://github.com/pyinstaller/pyinstaller/archive/develop.zip
14
pillow
25
pyside
3-
configobj
6+
pytest
7+
requests
48
semantic_version
5-
appdirs
69
validators
7-
requests
8-
https://github.com/pyinstaller/pyinstaller/archive/develop.zip

tests/__init__.py

Whitespace-only changes.

tests/conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import pytest
2+
def pytest_addoption(parser):
3+
parser.addoption("--runapi", action="store_true",
4+
help="Run tests that hit a drainable api resource")

tests/test_command_line.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
from command_line import CommandBase
2+
import utils
3+
import config
4+
import pytest
5+
6+
api = pytest.mark.skipif(
7+
not pytest.config.getoption("--runapi"),
8+
reason="need --runapi option to run"
9+
)
10+
11+
@pytest.fixture(scope='module')
12+
def command_base():
13+
base = CommandBase()
14+
base._project_name = 'Test'
15+
return base
16+
17+
def test_get_versions(command_base):
18+
assert command_base.get_setting('nw_version').values == []
19+
command_base.get_versions()
20+
command_base.setup_nw_versions()
21+
assert '0.13.2' in command_base.get_setting('nw_version').values
22+
23+
def test_get_settings(command_base):
24+
settings = command_base.get_settings()
25+
26+
assert 'download_settings' in settings
27+
assert 'web2exe_settings' in settings
28+
assert 'window_settings' in settings
29+
assert 'app_settings' in settings
30+
assert 'compression' in settings
31+
32+
def test_sub_output_pattern(command_base):
33+
pattern_setting = command_base.get_setting('output_pattern')
34+
command_base.get_setting('name').value = 'Test'
35+
pattern_setting.value = '%(name) 123'
36+
37+
value = command_base.sub_pattern()
38+
39+
assert value == 'Test 123'
40+
41+
def test_multiple_sub_output_pattern(command_base):
42+
pattern_setting = command_base.get_setting('output_pattern')
43+
44+
command_base.get_setting('name').value = 'Test'
45+
command_base.get_setting('nw_version').value = '0.14.0'
46+
47+
pattern_setting.value = '%(name) 123 %(nw_version)'
48+
49+
value = command_base.sub_pattern()
50+
51+
assert value == 'Test 123 0.14.0'
52+
53+
def test_valid_get_setting_objects(command_base):
54+
valid_settings = ['name', 'nw_version', 'windows-x64', 'main']
55+
for setting_name in valid_settings:
56+
setting = command_base.get_setting(setting_name)
57+
assert setting != None
58+
59+
def test_invalid_get_setting_objects(command_base):
60+
invalid_settings = ['foo', 'bar', 'steve', 'der']
61+
for setting_name in invalid_settings:
62+
setting = command_base.get_setting(setting_name)
63+
assert setting == None
64+
65+
def test_get_default_nwjs_branch(command_base):
66+
import re
67+
branch = command_base.get_default_nwjs_branch()
68+
69+
match = re.match('nw\d+', branch)
70+
71+
assert match != None
72+
73+
def test_get_versions(command_base):
74+
import os
75+
path = utils.get_data_file_path(config.VER_FILE)
76+
77+
if os.path.exists(path):
78+
os.remove(path)
79+
80+
command_base.get_versions()
81+
82+
with open(path, 'r') as ver_file:
83+
data = ver_file.read()
84+
assert len(data) > 0
85+
86+

0 commit comments

Comments
 (0)