Browse Source

Bumping up test coverage

pull/150/head
chriskiehl 8 years ago
parent
commit
b0cf1dbb5b
2 changed files with 124 additions and 0 deletions
  1. 89
      gooey/tests/test_presentation.py
  2. 35
      gooey/tests/test_processor.py

89
gooey/tests/test_presentation.py

@ -0,0 +1,89 @@
import sys
import pytest
import wx
from mock import MagicMock
from gooey.gui.lang import i18n
from gooey.gui.model import MyModel
from gooey.gui.presenter import Presenter
from gooey.gui.util.freeze import get_resource_path
from gooey.python_bindings import config_generator
@pytest.fixture
def build_spec(complete_parser):
return config_generator.create_from_parser(complete_parser, sys.argv[0])
@pytest.fixture
def build_spec_subparser(subparser):
return config_generator.create_from_parser(subparser, sys.argv[0])
@pytest.fixture
def presentation_model(build_spec):
app = wx.App(False)
i18n.load(get_resource_path('languages'), build_spec['language'])
model = MyModel(build_spec)
view = MagicMock()
presentation = Presenter(view, model)
return presentation
@pytest.fixture
def subparser_presentation_model(build_spec_subparser):
app = wx.App(False)
i18n.load(get_resource_path('languages'), 'english')
model = MyModel(build_spec_subparser)
view = MagicMock()
presentation = Presenter(view, model)
return presentation
# ----------------------------
# Tests #
# ----------------------------
def test_presentation_init(presentation_model):
'''Sanity check that the primary fields are set on init '''
presentation = presentation_model
presentation.initialize_view()
assert presentation.view.heading_title == presentation.model.heading_title
assert presentation.view.heading_subtitle == presentation.model.heading_subtitle
assert presentation.view.required_section.populate.called
assert presentation.view.optional_section.populate.called
# should not call when not running in column format
assert not presentation.view.set_list_contents.called
def test_subparser_presentation_init_sets_sidebar(subparser_presentation_model):
presentation = subparser_presentation_model
presentation.initialize_view()
# should be called to initialize the sidebar
assert presentation.view.set_list_contents.called
def test_on_start_shows_err_dlg_if_missing_args(presentation_model):
presentation = presentation_model
presentation.initialize_view()
presentation.on_start()
assert presentation.view.show_missing_args_dialog.called
presentation.view.show_missing_args_dialog.reset_mock()
# the inverse:
# fill the missing args
for arg in presentation.model.required_args:
arg.value = 'foo'
# patch the methods we don't need
presentation.client_runner = MagicMock()
presentation.update_model = MagicMock()
presentation.model.build_command_line_string = MagicMock()
presentation.on_start()
# should no longer show the dialog
assert not presentation.view.show_missing_args_dialog.called

35
gooey/tests/test_processor.py

@ -0,0 +1,35 @@
import re
from gooey.gui.processor import ProcessController
def test_extract_progress():
# should pull out a number based on the supplied
# regex and expression
processor = ProcessController(r"^progress: (\d+)%$", None)
assert processor._extract_progress('progress: 50%') == 50
processor = ProcessController(r"total: (\d+)%$", None)
assert processor._extract_progress('my cool total: 100%') == 100
def test_extract_progress_returns_none_if_no_regex_supplied():
processor = ProcessController(None, None)
assert processor._extract_progress('Total progress: 100%') == None
def test_extract_progress_returns_none_if_no_match_found():
processor = ProcessController(r'(\d+)%$', None)
assert processor._extract_progress('No match in dis string') == None
def test_eval_progress():
# given a match in the string, should eval the result
regex = r'(\d+)/(\d+)$'
processor = ProcessController(regex, r'x[0] / x[1]')
match = re.search(regex, '50/50')
assert processor._eval_progress(match) == 1.0
def test_eval_progress_returns_none_on_failure():
# given a match in the string, should eval the result
regex = r'(\d+)/(\d+)$'
processor = ProcessController(regex, r'x[0] *^/* x[1]')
match = re.search(regex, '50/50')
assert processor._eval_progress(match) == None
Loading…
Cancel
Save