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.

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