mirror of https://github.com/chriskiehl/Gooey.git
Chris
3 years ago
13 changed files with 394 additions and 23 deletions
Unified View
Diff Options
-
16docs/Gooey-Options.md
-
54gooey/gui/components/options/options.py
-
6gooey/gui/components/widgets/bases.py
-
14gooey/python_bindings/argparse_to_json.py
-
2gooey/tests/test_argparse_to_json.py
-
58gooey/tests/test_checkbox.py
-
54gooey/tests/test_common.py
-
51gooey/tests/test_counter.py
-
40gooey/tests/test_dropdown.py
-
58gooey/tests/test_listbox.py
-
22gooey/tests/test_numeric_inputs.py
-
13gooey/tests/test_slider.py
-
29gooey/tests/test_textfield.py
@ -0,0 +1,58 @@ |
|||||
|
import unittest |
||||
|
|
||||
|
from tests.harness import instrumentGooey |
||||
|
from gooey import GooeyParser |
||||
|
from gooey.tests import * |
||||
|
|
||||
|
|
||||
|
|
||||
|
class TestCheckbox(unittest.TestCase): |
||||
|
|
||||
|
def makeParser(self, **kwargs): |
||||
|
parser = GooeyParser(description='description') |
||||
|
parser.add_argument( |
||||
|
'--widget', |
||||
|
action='store_true', |
||||
|
**kwargs) |
||||
|
return parser |
||||
|
|
||||
|
|
||||
|
def testInitialValue(self): |
||||
|
cases = [ |
||||
|
# `initial` should supersede `default` |
||||
|
{'inputs': {'default': False, |
||||
|
'widget': 'CheckBox', |
||||
|
'gooey_options': {'initial_value': True}}, |
||||
|
'expect': True}, |
||||
|
|
||||
|
{'inputs': {'gooey_options': {'initial_value': True}, |
||||
|
'widget': 'CheckBox'}, |
||||
|
'expect': True}, |
||||
|
|
||||
|
{'inputs': {'gooey_options': {'initial_value': False}, |
||||
|
'widget': 'CheckBox'}, |
||||
|
'expect': False}, |
||||
|
|
||||
|
{'inputs': {'default': True, |
||||
|
'widget': 'CheckBox', |
||||
|
'gooey_options': {}}, |
||||
|
'expect': True}, |
||||
|
|
||||
|
{'inputs': {'default': True, |
||||
|
'widget': 'CheckBox'}, |
||||
|
'expect': True}, |
||||
|
|
||||
|
{'inputs': {'widget': 'CheckBox'}, |
||||
|
'expect': False} |
||||
|
] |
||||
|
for case in cases: |
||||
|
with self.subTest(case): |
||||
|
parser = self.makeParser(**case['inputs']) |
||||
|
with instrumentGooey(parser) as (app, gooeyApp): |
||||
|
widget = gooeyApp.configs[0].reifiedWidgets[0] |
||||
|
self.assertEqual(widget.getValue()['rawValue'], case['expect']) |
||||
|
|
||||
|
|
||||
|
|
||||
|
if __name__ == '__main__': |
||||
|
unittest.main() |
@ -0,0 +1,54 @@ |
|||||
|
import unittest |
||||
|
from collections import namedtuple |
||||
|
|
||||
|
from tests.harness import instrumentGooey |
||||
|
from gooey import GooeyParser |
||||
|
from gooey.tests import * |
||||
|
|
||||
|
Case = namedtuple('Case', 'inputs initialExpected') |
||||
|
|
||||
|
|
||||
|
class TestCommonProperties(unittest.TestCase): |
||||
|
""" |
||||
|
Test options and functionality |
||||
|
common across all widgets. |
||||
|
""" |
||||
|
|
||||
|
def makeParser(self, **kwargs): |
||||
|
parser = GooeyParser(description='description') |
||||
|
parser.add_argument('--widget', **kwargs) |
||||
|
return parser |
||||
|
|
||||
|
def testInitialValue(self): |
||||
|
widgets = ['ColourChooser', |
||||
|
'CommandField', |
||||
|
'DateChooser', 'DirChooser', 'FileChooser', 'FileSaver', |
||||
|
'FilterableDropdown', 'MultiDirChooser', 'MultiFileChooser', |
||||
|
'PasswordField', 'TextField', 'Textarea', 'TimeChooser'] |
||||
|
|
||||
|
cases = [ |
||||
|
# initial_value supersedes, default |
||||
|
Case( |
||||
|
{'default': 'default', 'gooey_options': {'initial_value': 'some val'}}, |
||||
|
'some val'), |
||||
|
Case( |
||||
|
{'gooey_options': {'initial_value': 'some val'}}, |
||||
|
'some val'), |
||||
|
Case( |
||||
|
{'default': 'default', 'gooey_options': {}}, |
||||
|
'default'), |
||||
|
Case({'default': 'default'}, |
||||
|
'default') |
||||
|
] |
||||
|
|
||||
|
for widgetName in widgets: |
||||
|
with self.subTest(widgetName): |
||||
|
for case in cases: |
||||
|
parser = self.makeParser(widget=widgetName, **case.inputs) |
||||
|
with instrumentGooey(parser) as (app, gooeyApp): |
||||
|
widget = gooeyApp.configs[0].reifiedWidgets[0] |
||||
|
self.assertEqual(widget.getValue()['rawValue'], case.initialExpected) |
||||
|
|
||||
|
|
||||
|
if __name__ == '__main__': |
||||
|
unittest.main() |
@ -0,0 +1,51 @@ |
|||||
|
import unittest |
||||
|
|
||||
|
from tests.harness import instrumentGooey |
||||
|
from gooey import GooeyParser |
||||
|
from gooey.tests import * |
||||
|
|
||||
|
|
||||
|
|
||||
|
class TestCounter(unittest.TestCase): |
||||
|
|
||||
|
def makeParser(self, **kwargs): |
||||
|
parser = GooeyParser(description='description') |
||||
|
parser.add_argument( |
||||
|
'--widget', |
||||
|
action='count', |
||||
|
widget="Counter", |
||||
|
**kwargs) |
||||
|
return parser |
||||
|
|
||||
|
|
||||
|
def testInitialValue(self): |
||||
|
cases = [ |
||||
|
# `initial` should supersede `default` |
||||
|
{'inputs': {'default': 1, |
||||
|
'gooey_options': {'initial_value': 3}}, |
||||
|
'expect': '3'}, |
||||
|
|
||||
|
{'inputs': {'gooey_options': {'initial_value': 1}}, |
||||
|
'expect': '1'}, |
||||
|
|
||||
|
{'inputs': {'default': 2, |
||||
|
'gooey_options': {}}, |
||||
|
'expect': '2'}, |
||||
|
|
||||
|
{'inputs': {'default': 1}, |
||||
|
'expect': '1'}, |
||||
|
|
||||
|
{'inputs': {}, |
||||
|
'expect': None} |
||||
|
] |
||||
|
for case in cases: |
||||
|
with self.subTest(case): |
||||
|
parser = self.makeParser(**case['inputs']) |
||||
|
with instrumentGooey(parser) as (app, gooeyApp): |
||||
|
widget = gooeyApp.configs[0].reifiedWidgets[0] |
||||
|
self.assertEqual(widget.getValue()['rawValue'], case['expect']) |
||||
|
|
||||
|
|
||||
|
|
||||
|
if __name__ == '__main__': |
||||
|
unittest.main() |
@ -0,0 +1,58 @@ |
|||||
|
import unittest |
||||
|
|
||||
|
from tests.harness import instrumentGooey |
||||
|
from gooey import GooeyParser |
||||
|
from gooey.tests import * |
||||
|
|
||||
|
|
||||
|
|
||||
|
class TestListbox(unittest.TestCase): |
||||
|
|
||||
|
def makeParser(self, **kwargs): |
||||
|
parser = GooeyParser(description='description') |
||||
|
parser.add_argument( |
||||
|
'--widget', |
||||
|
widget="Listbox", |
||||
|
nargs="*", |
||||
|
**kwargs) |
||||
|
return parser |
||||
|
|
||||
|
def testInitialValue(self): |
||||
|
cases = [ |
||||
|
# `initial` should supersede `default` |
||||
|
{'inputs': {'default': 'b', |
||||
|
'choices': ['a', 'b', 'c'], |
||||
|
'gooey_options': {'initial_value': 'a'}}, |
||||
|
'expect': ['a']}, |
||||
|
|
||||
|
{'inputs': {'choices': ['a', 'b', 'c'], |
||||
|
'gooey_options': {'initial_value': 'a'}}, |
||||
|
'expect': ['a']}, |
||||
|
|
||||
|
{'inputs': {'choices': ['a', 'b', 'c'], |
||||
|
'gooey_options': {'initial_value': ['a', 'c']}}, |
||||
|
'expect': ['a', 'c']}, |
||||
|
|
||||
|
{'inputs': {'choices': ['a', 'b', 'c'], |
||||
|
'default': 'b', |
||||
|
'gooey_options': {}}, |
||||
|
'expect': ['b']}, |
||||
|
|
||||
|
{'inputs': {'choices': ['a', 'b', 'c'], |
||||
|
'default': 'b'}, |
||||
|
'expect': ['b']}, |
||||
|
|
||||
|
{'inputs': {'choices': ['a', 'b', 'c']}, |
||||
|
'expect': []} |
||||
|
] |
||||
|
for case in cases: |
||||
|
with self.subTest(case): |
||||
|
parser = self.makeParser(**case['inputs']) |
||||
|
with instrumentGooey(parser) as (app, gooeyApp): |
||||
|
widget = gooeyApp.configs[0].reifiedWidgets[0] |
||||
|
self.assertEqual(widget.getValue()['rawValue'], case['expect']) |
||||
|
|
||||
|
|
||||
|
|
||||
|
if __name__ == '__main__': |
||||
|
unittest.main() |
Write
Preview
Loading…
Cancel
Save