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.

68 lines
2.4 KiB

  1. import unittest
  2. from argparse import ArgumentParser
  3. from collections import namedtuple
  4. from unittest.mock import patch
  5. from unittest.mock import MagicMock
  6. from tests.harness import instrumentGooey
  7. class TestGooeyApplication(unittest.TestCase):
  8. def testFullscreen(self):
  9. parser = self.basicParser()
  10. for shouldShow in [True, False]:
  11. with self.subTest('Should set full screen: {}'.format(shouldShow)):
  12. with instrumentGooey(parser, fullscreen=shouldShow) as (app, gapp):
  13. self.assertEqual(gapp.IsFullScreen(), shouldShow)
  14. @patch("gui.containers.application.modals.confirmForceStop")
  15. def testGooeyRequestsConfirmationWhenShowStopWarningModalTrue(self, mockModal):
  16. """
  17. When show_stop_warning=False, Gooey should immediately kill the
  18. running program without additional user confirmation.
  19. Otherwise, Gooey should show a confirmation modal and, dependending on the
  20. user's choice, either do nothing or kill the running program.
  21. """
  22. Case = namedtuple('Case', ['show_warning', 'shouldSeeConfirm', 'userChooses', 'shouldHaltProgram'])
  23. testcases = [
  24. Case(show_warning=True, shouldSeeConfirm=True, userChooses=True, shouldHaltProgram=True),
  25. Case(show_warning=True, shouldSeeConfirm=True, userChooses=False, shouldHaltProgram=False),
  26. Case(show_warning=False, shouldSeeConfirm=False, userChooses='N/A', shouldHaltProgram=True),
  27. ]
  28. for case in testcases:
  29. mockModal.reset_mock()
  30. parser = self.basicParser()
  31. with instrumentGooey(parser, show_stop_warning=case.show_warning) as (app, gapp):
  32. mockClientRunner = MagicMock()
  33. mockModal.return_value = case.userChooses
  34. gapp.clientRunner = mockClientRunner
  35. gapp.onStopExecution()
  36. if case.shouldSeeConfirm:
  37. mockModal.assert_called()
  38. else:
  39. mockModal.assert_not_called()
  40. if case.shouldHaltProgram:
  41. mockClientRunner.stop.assert_called()
  42. else:
  43. mockClientRunner.stop.assert_not_called()
  44. def basicParser(self):
  45. parser = ArgumentParser()
  46. parser.add_argument('--foo')
  47. return parser
  48. if __name__ == '__main__':
  49. unittest.main()