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.

84 lines
1.9 KiB

  1. '''
  2. Created on Jan 4, 2014
  3. @author: Chris
  4. '''
  5. import os
  6. import sys
  7. import unittest
  8. from argparse import ArgumentParser
  9. import wx
  10. from gooey.gui import components
  11. class ComponentsTest(unittest.TestCase):
  12. def setUp(self):
  13. parser = ArgumentParser(description='Example Argparse Program')
  14. parser.add_argument("filename", help="Name of the file you want to read")
  15. parser.add_argument('-T', '--tester', choices=['yes', 'no'])
  16. parser.add_argument('-o', '--outfile', help='Redirects output to the specified file')
  17. parser.add_argument('-v', '--verbose', help='Toggles verbosity off')
  18. parser.add_argument('-e', '--repeat', action='count')
  19. action = parser._actions
  20. self.actions = {
  21. 'help': action[0],
  22. 'Positional': action[1],
  23. 'Choice': action[2],
  24. 'Optional': action[3],
  25. 'Flag': action[4],
  26. 'Counter': action[5]
  27. }
  28. def BuildWindow(self, component, _type):
  29. app = wx.PySimpleApp()
  30. module_name = os.path.split(sys.argv[0])[-1]
  31. frame = wx.Frame(None, -1, _type)
  32. panel = wx.Panel(frame, -1, size=(320, 240))
  33. component_sizer = component.Build(panel)
  34. panel.SetSizer(component_sizer)
  35. frame.Show(True)
  36. app.MainLoop()
  37. def testPositionalWidgetBuild(self):
  38. self.SetupWidgetAndBuildWindow('Positional')
  39. def testChoiceWidgetBuild(self):
  40. self.SetupWidgetAndBuildWindow('Choice')
  41. def testOptionalWidgetBuild(self):
  42. self.SetupWidgetAndBuildWindow('Optional')
  43. def testFlagWidgetBuild(self):
  44. self.SetupWidgetAndBuildWindow('Flag')
  45. def testCounterWidgetBuild(self):
  46. self.SetupWidgetAndBuildWindow('Counter')
  47. def SetupWidgetAndBuildWindow(self, _type):
  48. component = getattr(components, _type)(self.actions[_type])
  49. self.BuildWindow(component, _type)
  50. if __name__ == "__main__":
  51. # import sys;sys.argv = ['', 'Test.testName']
  52. unittest.main()