You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.7 KiB

  1. import sys
  2. import pytest
  3. import wx
  4. from mock import MagicMock
  5. from gooey.gui.lang import i18n
  6. from gooey.gui.model import MyModel
  7. from gooey.gui.presenter import Presenter
  8. from gooey.gui.util.freeze import get_resource_path
  9. from gooey.python_bindings import config_generator
  10. @pytest.fixture
  11. def build_spec(complete_parser):
  12. return config_generator.create_from_parser(complete_parser, sys.argv[0])
  13. @pytest.fixture
  14. def build_spec_subparser(subparser):
  15. return config_generator.create_from_parser(subparser, sys.argv[0])
  16. @pytest.fixture
  17. def presentation_model(build_spec):
  18. app = wx.App(False)
  19. i18n.load(get_resource_path('languages'), build_spec['language'])
  20. model = MyModel(build_spec)
  21. view = MagicMock()
  22. presentation = Presenter(view, model)
  23. return presentation
  24. @pytest.fixture
  25. def subparser_presentation_model(build_spec_subparser):
  26. app = wx.App(False)
  27. i18n.load(get_resource_path('languages'), 'english')
  28. model = MyModel(build_spec_subparser)
  29. view = MagicMock()
  30. presentation = Presenter(view, model)
  31. return presentation
  32. # ----------------------------
  33. # Tests #
  34. # ----------------------------
  35. def test_presentation_init(presentation_model):
  36. '''Sanity check that the primary fields are set on init '''
  37. presentation = presentation_model
  38. presentation.initialize_view()
  39. assert presentation.view.heading_title == presentation.model.heading_title
  40. assert presentation.view.heading_subtitle == presentation.model.heading_subtitle
  41. assert presentation.view.required_section.populate.called
  42. assert presentation.view.optional_section.populate.called
  43. # should not call when not running in column format
  44. assert not presentation.view.set_list_contents.called
  45. def test_subparser_presentation_init_sets_sidebar(subparser_presentation_model):
  46. presentation = subparser_presentation_model
  47. presentation.initialize_view()
  48. # should be called to initialize the sidebar
  49. assert presentation.view.set_list_contents.called
  50. def test_on_start_shows_err_dlg_if_missing_args(presentation_model):
  51. presentation = presentation_model
  52. presentation.initialize_view()
  53. presentation.on_start()
  54. assert presentation.view.show_missing_args_dialog.called
  55. presentation.view.show_missing_args_dialog.reset_mock()
  56. # the inverse:
  57. # fill the missing args
  58. for arg in presentation.model.required_args:
  59. arg.value = 'foo'
  60. # patch the methods we don't need
  61. presentation.client_runner = MagicMock()
  62. presentation.update_model = MagicMock()
  63. presentation.model.build_command_line_string = MagicMock()
  64. presentation.on_start()
  65. # should no longer show the dialog
  66. assert not presentation.view.show_missing_args_dialog.called