|
| 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