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.

103 lines
4.0 KiB

  1. import sys
  2. import unittest
  3. from argparse import ArgumentParser
  4. from collections import namedtuple
  5. from unittest.mock import patch
  6. from unittest.mock import MagicMock
  7. from python_bindings import constants
  8. from tests.harness import instrumentGooey
  9. from gooey.tests import *
  10. class TestGooeyApplication(unittest.TestCase):
  11. def testFullscreen(self):
  12. parser = self.basicParser()
  13. for shouldShow in [True, False]:
  14. with self.subTest('Should set full screen: {}'.format(shouldShow)):
  15. with instrumentGooey(parser, fullscreen=shouldShow) as (app, gapp):
  16. self.assertEqual(gapp.IsFullScreen(), shouldShow)
  17. @patch("gui.containers.application.modals.confirmForceStop")
  18. def testGooeyRequestsConfirmationWhenShowStopWarningModalTrue(self, mockModal):
  19. """
  20. When show_stop_warning=False, Gooey should immediately kill the
  21. running program without additional user confirmation.
  22. Otherwise, Gooey should show a confirmation modal and, dependending on the
  23. user's choice, either do nothing or kill the running program.
  24. """
  25. Case = namedtuple('Case', ['show_warning', 'shouldSeeConfirm', 'userChooses', 'shouldHaltProgram'])
  26. testcases = [
  27. Case(show_warning=True, shouldSeeConfirm=True, userChooses=True, shouldHaltProgram=True),
  28. Case(show_warning=True, shouldSeeConfirm=True, userChooses=False, shouldHaltProgram=False),
  29. Case(show_warning=False, shouldSeeConfirm=False, userChooses='N/A', shouldHaltProgram=True),
  30. ]
  31. for case in testcases:
  32. mockModal.reset_mock()
  33. parser = self.basicParser()
  34. with instrumentGooey(parser, show_stop_warning=case.show_warning) as (app, gapp):
  35. mockClientRunner = MagicMock()
  36. mockModal.return_value = case.userChooses
  37. gapp.clientRunner = mockClientRunner
  38. gapp.onStopExecution()
  39. if case.shouldSeeConfirm:
  40. mockModal.assert_called()
  41. else:
  42. mockModal.assert_not_called()
  43. if case.shouldHaltProgram:
  44. mockClientRunner.stop.assert_called()
  45. else:
  46. mockClientRunner.stop.assert_not_called()
  47. @patch("gui.containers.application.modals.confirmForceStop")
  48. def testOnCloseShutsDownActiveClients(self, mockModal):
  49. """
  50. Issue 592: Closing the UI should clean up any actively running programs
  51. """
  52. parser = self.basicParser()
  53. with instrumentGooey(parser) as (app, gapp):
  54. gapp.clientRunner = MagicMock()
  55. gapp.destroyGooey = MagicMock()
  56. # mocking that the user clicks "yes shut down" in the warning modal
  57. mockModal.return_value = True
  58. gapp.onClose()
  59. mockModal.assert_called()
  60. gapp.destroyGooey.assert_called()
  61. def testTerminalColorChanges(self):
  62. ## Issue #625 terminal panel color wasn't being set due to a typo
  63. parser = self.basicParser()
  64. expectedColors = [(255, 0, 0, 255), (255, 255, 255, 255), (100, 100, 100,100)]
  65. for expectedColor in expectedColors:
  66. with instrumentGooey(parser, terminal_panel_color=expectedColor) as (app, gapp):
  67. foundColor = gapp.console.GetBackgroundColour()
  68. self.assertEqual(tuple(foundColor), expectedColor)
  69. def testFontWeightsGetSet(self):
  70. ## Issue #625 font weight wasn't being correctly passed to the terminal
  71. for weight in [constants.FONTWEIGHT_LIGHT, constants.FONTWEIGHT_BOLD]:
  72. parser = self.basicParser()
  73. with instrumentGooey(parser, terminal_font_weight=weight) as (app, gapp):
  74. terminal = gapp.console.textbox
  75. self.assertEqual(terminal.GetFont().GetWeight(), weight)
  76. def basicParser(self):
  77. parser = ArgumentParser()
  78. parser.add_argument('--foo')
  79. return parser
  80. if __name__ == '__main__':
  81. unittest.main()