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.

110 lines
4.5 KiB

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 gooey.python_bindings import constants
  9. from gooey.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("gooey.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. def testTerminalColorChanges(self):
  49. ## Issue #625 terminal panel color wasn't being set due to a typo
  50. parser = self.basicParser()
  51. expectedColors = [(255, 0, 0, 255), (255, 255, 255, 255), (100, 100, 100,100)]
  52. for expectedColor in expectedColors:
  53. with instrumentGooey(parser, terminal_panel_color=expectedColor) as (app, frame, gapp):
  54. foundColor = gapp.consoleRef.instance.GetBackgroundColour()
  55. self.assertEqual(tuple(foundColor), expectedColor)
  56. def testFontWeightsGetSet(self):
  57. ## Issue #625 font weight wasn't being correctly passed to the terminal
  58. for weight in [constants.FONTWEIGHT_LIGHT, constants.FONTWEIGHT_BOLD]:
  59. parser = self.basicParser()
  60. with instrumentGooey(parser, terminal_font_weight=weight) as (app, frame, gapp):
  61. terminal = gapp.consoleRef.instance.textbox
  62. self.assertEqual(terminal.GetFont().GetWeight(), weight)
  63. def testProgressBarHiddenWhenDisabled(self):
  64. options = [
  65. {'disable_progress_bar_animation': True},
  66. {'disable_progress_bar_animation': False},
  67. {}
  68. ]
  69. for kwargs in options:
  70. parser = self.basicParser()
  71. with instrumentGooey(parser, **kwargs) as (app, frame, gapp):
  72. mockClientRunner = MagicMock()
  73. frame.clientRunner = mockClientRunner
  74. # transition's Gooey to the running state using the now mocked processor.
  75. # so that we can make assertions about the visibility of footer buttons
  76. gapp.onStart()
  77. # the progress bar flag is awkwardly inverted (is_disabled, rather than
  78. # is_enabled). Thus inverting the expectation here. When disabled is true,
  79. # shown should be False,
  80. expect_shown = not kwargs.get('disable_progress_bar_animation', False)
  81. self.assertEqual(gapp.state['progress']['show'], expect_shown)
  82. def basicParser(self):
  83. parser = ArgumentParser()
  84. parser.add_argument('--foo')
  85. return parser
  86. if __name__ == '__main__':
  87. unittest.main()