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.

194 lines
4.8 KiB

  1. from gooey.gui.widgets import components2
  2. __author__ = 'Chris'
  3. import unittest
  4. import wx
  5. from wx.lib.scrolledpanel import ScrolledPanel
  6. TEXT_FIELD = components2.TextField({
  7. 'display_name': 'cool title',
  8. 'help_msg': 'a help message',
  9. 'nargs': '+',
  10. 'commands': ['-f', '--fudge'],
  11. 'choices': []
  12. })
  13. DROPDOWN = components2.Dropdown({
  14. 'display_name': 'cool title',
  15. 'help_msg': 'a help message',
  16. 'nargs': '+',
  17. 'commands': ['-f', '--fudge'],
  18. 'choices': ['one', 'two', 'three']
  19. })
  20. COUNTER = components2.Counter({
  21. 'display_name': 'cool title',
  22. 'help_msg': 'a help message',
  23. 'nargs': '+',
  24. 'commands': ['-f', '--fudge'],
  25. 'choices': []
  26. })
  27. CHECKBOX = components2.CheckBox({
  28. 'display_name': 'cool title',
  29. 'help_msg': 'a help message',
  30. 'nargs': '+',
  31. 'commands': ['-f', '--fudge'],
  32. 'choices': []
  33. })
  34. RADIOGROUP = components2.RadioGroup({
  35. 'display_name': 'mutux options',
  36. 'data': [{
  37. 'help_msg': 'a help message',
  38. 'nargs': '+',
  39. 'commands': ['-f', '--fudge'],
  40. 'choices': []
  41. }, {
  42. 'help_msg': 'a help message',
  43. 'nargs': '+',
  44. 'commands': ['-g', '--gudge'],
  45. 'choices': []
  46. }]
  47. })
  48. class TestPanel(ScrolledPanel):
  49. def __init__(self, parent, widget):
  50. ScrolledPanel.__init__(self, parent)
  51. self.SetupScrolling(scroll_x=False)
  52. sizer = wx.BoxSizer(wx.VERTICAL)
  53. self.widget = widget
  54. sizer.Add(self.widget.build(self), 0, wx.EXPAND)
  55. self.SetSizer(sizer)
  56. class MyFrame(wx.Frame):
  57. def __init__(self, parent, widget):
  58. wx.Frame.__init__(self, parent, title="test", size=(320, 240))
  59. self.SetBackgroundColour('#ffffff')
  60. self.panel = TestPanel(self, widget)
  61. self.Show()
  62. def get_widget(self):
  63. return self.panel.widget
  64. def close(self):
  65. self.Destroy()
  66. class TestComponents(unittest.TestCase):
  67. def setUp(self):
  68. self.app = wx.App(False)
  69. self.frame = None
  70. def tearDown(self):
  71. # self.app = wx.App(False)
  72. self.frame.Destroy()
  73. self.frame = None
  74. def test_textfield_returns_option_and_value_else_none(self):
  75. self.build_test_frame(TEXT_FIELD)
  76. self.assertTrue(self.get_value() == '')
  77. self.get_widget().SetLabelText('value')
  78. self.assertEqual('-f value', self.get_value())
  79. def test_dropdown_returns_option_and_value_else_none(self):
  80. self.build_test_frame(DROPDOWN)
  81. self.assertTrue(self.get_value() == '')
  82. # grab first item from the combo box
  83. self.frame.get_widget()._GetWidget().SetSelection(0)
  84. self.assertEqual('-f one', self.get_value())
  85. def test_counter_returns_option_and_value_else_none(self):
  86. self.build_test_frame(COUNTER)
  87. self.assertTrue(self.get_value() == '')
  88. # counter objects stack,
  89. # so
  90. # 1 = -f,
  91. # 4 = -ffff
  92. self.frame.get_widget()._GetWidget().SetSelection(0)
  93. self.assertEqual('-f', self.get_value())
  94. self.frame.get_widget()._GetWidget().SetSelection(4)
  95. self.assertEqual('-fffff', self.get_value())
  96. def test_checkbox_returns_option_if_checked_else_none(self):
  97. self.build_test_frame(CHECKBOX)
  98. self.assertTrue(self.get_value() == '')
  99. self.frame.get_widget()._GetWidget().SetValue(1)
  100. self.assertEqual('-f', self.get_value())
  101. def test_radiogroup_returns_option_if_checked_else_none(self):
  102. self.build_test_frame(RADIOGROUP)
  103. self.assertTrue(self.get_value() == '')
  104. # self.frame.get_widget()._GetWidget()[0].SetValue(1)
  105. # self.assertEqual('-f', self.get_value())
  106. def build_test_frame(self, widget):
  107. # self.app = wx.App(False)
  108. self.frame = MyFrame(None, widget)
  109. def get_widget(self):
  110. return self.frame.get_widget()._GetWidget()
  111. def get_value(self):
  112. return self.frame.get_widget().GetValue()
  113. if __name__ == '__main__':
  114. unittest.main()
  115. # a = {
  116. # 'required' : [
  117. # {
  118. # 'component': 'TextField',
  119. # 'data': {
  120. # 'display_name': 'filename',
  121. # 'help_text': 'path to file you want to process',
  122. # 'command_args': ['-f', '--infile']
  123. # }
  124. # },
  125. # {
  126. # 'component': 'FileChooser',
  127. # 'data': {
  128. # 'display_name': 'Output Location',
  129. # 'help_text': 'Where to save the file',
  130. # 'command_args': ['-o', '--outfile']
  131. # }
  132. # }
  133. # ],
  134. # 'optional' : [
  135. # {
  136. # 'component': 'RadioGroup',
  137. # 'data': [
  138. # {
  139. # 'display_name': 'Output Location',
  140. # 'help_text': 'Where to save the file',
  141. # 'command_args': ['-o', '--outfile']
  142. # }, {
  143. # 'display_name': 'Output Location',
  144. # 'help_text': 'Where to save the file',
  145. # 'command_args': ['-o', '--outfile']
  146. # }
  147. # ]
  148. # }
  149. # ]
  150. # }
  151. #
  152. # ]
  153. # }