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.

126 lines
5.1 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. import sys
  2. import unittest
  3. from argparse import ArgumentParser
  4. from collections import namedtuple
  5. from pprint import pprint
  6. from unittest.mock import patch
  7. from unittest.mock import MagicMock
  8. from python_bindings import constants
  9. from tests.harness import instrumentGooey
  10. from gooey.tests import *
  11. class TestGooeyApplication(unittest.TestCase):
  12. def testFullscreen(self):
  13. parser = self.basicParser()
  14. for shouldShow in [True, False]:
  15. with self.subTest('Should set full screen: {}'.format(shouldShow)):
  16. with instrumentGooey(parser, fullscreen=shouldShow) as (app, frame, gapp):
  17. self.assertEqual(frame.IsFullScreen(), shouldShow)
  18. @patch("gui.containers.application.modals.confirmForceStop")
  19. def testGooeyRequestsConfirmationWhenShowStopWarningModalTrue(self, mockModal):
  20. """
  21. When show_stop_warning=False, Gooey should immediately kill the
  22. running program without additional user confirmation.
  23. Otherwise, Gooey should show a confirmation modal and, dependending on the
  24. user's choice, either do nothing or kill the running program.
  25. """
  26. Case = namedtuple('Case', ['show_warning', 'shouldSeeConfirm', 'userChooses', 'shouldHaltProgram'])
  27. testcases = [
  28. Case(show_warning=True, shouldSeeConfirm=True, userChooses=True, shouldHaltProgram=True),
  29. Case(show_warning=True, shouldSeeConfirm=True, userChooses=False, shouldHaltProgram=False),
  30. Case(show_warning=False, shouldSeeConfirm=False, userChooses='N/A', shouldHaltProgram=True),
  31. ]
  32. for case in testcases:
  33. mockModal.reset_mock()
  34. parser = self.basicParser()
  35. with instrumentGooey(parser, show_stop_warning=case.show_warning) as (app, frame, gapp):
  36. mockClientRunner = MagicMock()
  37. mockModal.return_value = case.userChooses
  38. gapp.clientRunner = mockClientRunner
  39. gapp.handleInterrupt()
  40. if case.shouldSeeConfirm:
  41. mockModal.assert_called()
  42. else:
  43. mockModal.assert_not_called()
  44. if case.shouldHaltProgram:
  45. mockClientRunner.stop.assert_called()
  46. else:
  47. mockClientRunner.stop.assert_not_called()
  48. # @patch("gui.containers.application.modals.confirmForceStop")
  49. # def testOnCloseShutsDownActiveClients(self, mockModal):
  50. # """
  51. # Issue 592: Closing the UI should clean up any actively running programs
  52. # """
  53. # parser = self.basicParser()
  54. # with instrumentGooey(parser) as (app, frame):
  55. # frame.clientRunner = MagicMock()
  56. # frame.destroyGooey = MagicMock()
  57. # # mocking that the user clicks "yes shut down" in the warning modal
  58. # mockModal.return_value = True
  59. # frame._instance.handleClose()
  60. #
  61. # mockModal.assert_called()
  62. # frame.destroyGooey.assert_called()
  63. def testTerminalColorChanges(self):
  64. ## Issue #625 terminal panel color wasn't being set due to a typo
  65. parser = self.basicParser()
  66. expectedColors = [(255, 0, 0, 255), (255, 255, 255, 255), (100, 100, 100,100)]
  67. for expectedColor in expectedColors:
  68. with instrumentGooey(parser, terminal_panel_color=expectedColor) as (app, frame, gapp):
  69. foundColor = gapp.consoleRef.instance.GetBackgroundColour()
  70. self.assertEqual(tuple(foundColor), expectedColor)
  71. def testFontWeightsGetSet(self):
  72. ## Issue #625 font weight wasn't being correctly passed to the terminal
  73. for weight in [constants.FONTWEIGHT_LIGHT, constants.FONTWEIGHT_BOLD]:
  74. parser = self.basicParser()
  75. with instrumentGooey(parser, terminal_font_weight=weight) as (app, frame, gapp):
  76. terminal = gapp.consoleRef.instance.textbox
  77. self.assertEqual(terminal.GetFont().GetWeight(), weight)
  78. def testProgressBarHiddenWhenDisabled(self):
  79. options = [
  80. {'disable_progress_bar_animation': True},
  81. {'disable_progress_bar_animation': False},
  82. {}
  83. ]
  84. for kwargs in options:
  85. parser = self.basicParser()
  86. with instrumentGooey(parser, **kwargs) as (app, frame, gapp):
  87. mockClientRunner = MagicMock()
  88. frame.clientRunner = mockClientRunner
  89. # transition's Gooey to the running state using the now mocked processor.
  90. # so that we can make assertions about the visibility of footer buttons
  91. gapp.onStart()
  92. # the progress bar flag is awkwardly inverted (is_disabled, rather than
  93. # is_enabled). Thus inverting the expectation here. When disabled is true,
  94. # shown should be False,
  95. expect_shown = not kwargs.get('disable_progress_bar_animation', False)
  96. self.assertEqual(gapp.state['progress']['show'], expect_shown)
  97. def basicParser(self):
  98. parser = ArgumentParser()
  99. parser.add_argument('--foo')
  100. return parser
  101. if __name__ == '__main__':
  102. unittest.main()