mirror of https://github.com/chriskiehl/Gooey.git
Browse Source
nightly work. Added unittests from advanced_config. Fixed bug in ActionSorter, tweaked display elements, fixed wrapping
pull/1/head
nightly work. Added unittests from advanced_config. Fixed bug in ActionSorter, tweaked display elements, fixed wrapping
pull/1/head
Chris Kiehl
11 years ago
13 changed files with 324 additions and 56 deletions
Split View
Diff Options
-
9src/app/dialogs/action_sorter.py
-
80src/app/dialogs/action_sorter_unittest.py
-
74src/app/dialogs/advanced_config.py
-
BINsrc/app/dialogs/advanced_config.pyc
-
26src/app/dialogs/advanced_config_unittest.py
-
22src/app/dialogs/argparse_test_data.py
-
29src/app/dialogs/component_factory.py
-
BINsrc/app/dialogs/component_factory.pyc
-
105src/app/dialogs/components.py
-
10src/app/dialogs/components_unittest.py
-
3src/app/dialogs/simple_config_panel.py
-
0src/experiments/__init__.py
-
22src/experiments/command.py
@ -0,0 +1,80 @@ |
|||
''' |
|||
Created on Jan 16, 2014 |
|||
|
|||
@author: Chris |
|||
''' |
|||
|
|||
import time |
|||
import unittest |
|||
import argparse_test_data |
|||
from functools import partial |
|||
from argparse import _StoreAction, _HelpAction |
|||
from action_sorter import ActionSorter |
|||
|
|||
class Test(unittest.TestCase): |
|||
|
|||
|
|||
def setUp(self): |
|||
self._actions = argparse_test_data.parser._actions |
|||
self.sorted_actions = ActionSorter(self._actions) |
|||
# pain in the A... PEP8 be damned! |
|||
self.expected_positionals = [ |
|||
"_StoreAction(option_strings=[], dest='filename', nargs=None, const=None, default=None, type=None, choices=None, help='Name of the file you want to read', metavar=None)", |
|||
'''_StoreAction(option_strings=[], dest='outfile', nargs=None, const=None, default=None, type=None, choices=None, help="Name of the file where you'll save the output", metavar=None)''' |
|||
] |
|||
self.expected_choices = [ |
|||
'''_StoreAction(option_strings=['-T', '--tester'], dest='tester', nargs=None, const=None, default=None, type=None, choices=['yes', 'no'], help="Yo, what's up man? I'm a help message!", metavar=None)''' |
|||
] |
|||
self.expected_optionals = [ |
|||
'''_StoreAction(option_strings=['-o', '--outfile'], dest='outfile', nargs=None, const=None, default=None, type=None, choices=None, help='Redirects output to the file specified by you, the awesome user', metavar=None)''', |
|||
'''_StoreAction(option_strings=['-v', '--verbose'], dest='verbose', nargs=None, const=None, default=None, type=None, choices=None, help='Toggles verbosity off', metavar=None)''', |
|||
'''_StoreAction(option_strings=['-s', '--schimzammy'], dest='schimzammy', nargs=None, const=None, default=None, type=None, choices=None, help='Add in an optional shimzammy parameter', metavar=None)''' |
|||
] |
|||
self.expected_counters = [ |
|||
'''_CountAction(option_strings=['-e', '--repeat'], dest='repeat', nargs=0, const=None, default=None, type=None, choices=None, help='Set the number of times to repeat', metavar=None)''' |
|||
] |
|||
|
|||
self.expected_flags = [ |
|||
'''_StoreConstAction(option_strings=['-c', '--constoption'], dest='constoption', nargs=0, const='myconstant', default=None, type=None, choices=None, help='Make sure the const action is correctly sorted', metavar=None)''', |
|||
'''_StoreTrueAction(option_strings=['-t', '--truify'], dest='truify', nargs=0, const=True, default=False, type=None, choices=None, help='Ensure the store_true actions are sorted', metavar=None)''', |
|||
'''_StoreFalseAction(option_strings=['-f', '--falsificle'], dest='falsificle', nargs=0, const=False, default=True, type=None, choices=None, help='Ensure the store_false actions are sorted', metavar=None)''' |
|||
] |
|||
|
|||
def testPositionalsReturnsOnlyPositionalActions(self): |
|||
positionals = self.sorted_actions._positionals |
|||
self.assertEqual(len(positionals), 2) |
|||
|
|||
self.assertForAllActionsInList(positionals,self.expected_positionals) |
|||
|
|||
def testHelpActionNotInOptionals(self): |
|||
_isinstance = lambda x: isinstance(x, _HelpAction) |
|||
self.assertFalse(any(map(_isinstance, self.sorted_actions._optionals))) |
|||
|
|||
def testChoicesOnlyReturnsChoices(self): |
|||
self.assertForAllActionsInList(self.sorted_actions._choices, |
|||
self.expected_choices) |
|||
|
|||
def testOptionalsOnlyReturnsOptionals(self): |
|||
self.assertForAllActionsInList(self.sorted_actions._optionals, |
|||
self.expected_optionals) |
|||
|
|||
def testCounterSortOnlyReturnsCounters(self): |
|||
self.assertForAllActionsInList(self.sorted_actions._counters, |
|||
self.expected_counters) |
|||
|
|||
def testFlagSortReturnsOnlyFlags(self): |
|||
self.assertForAllActionsInList(self.sorted_actions._flags, |
|||
self.expected_flags) |
|||
|
|||
def assertForAllActionsInList(self, actions, expected_actions): |
|||
for index, action in enumerate(actions): |
|||
self.assertEqual(str(action), expected_actions[index]) |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
if __name__ == "__main__": |
|||
#import sys;sys.argv = ['', 'Test.testName'] |
|||
unittest.main() |
@ -0,0 +1,22 @@ |
|||
''' |
|||
Created on Jan 16, 2014 |
|||
|
|||
@author: Chris |
|||
''' |
|||
|
|||
from argparse import ArgumentParser |
|||
|
|||
|
|||
parser = ArgumentParser(description='Example Argparse Program') |
|||
parser.add_argument("filename", help="Name of the file you want to read") # positional |
|||
parser.add_argument("outfile", help="Name of the file where you'll save the output") # positional |
|||
parser.add_argument('-T', '--tester', choices=['yes','no'], help="Yo, what's up man? I'm a help message!") # Choice |
|||
parser.add_argument('-o', '--outfile', help='Redirects output to the file specified by you, the awesome user') # Optional |
|||
parser.add_argument('-v', '--verbose', help='Toggles verbosity off') # Optional |
|||
parser.add_argument('-s', '--schimzammy', help='Add in an optional shimzammy parameter') # Optional |
|||
parser.add_argument('-e', '--repeat', action='count', help='Set the number of times to repeat') # Counter |
|||
parser.add_argument('-c', '--constoption', action="store_const", const="myconstant", help='Make sure the const action is correctly sorted') # Flag |
|||
parser.add_argument('-t', '--truify', action="store_true", help='Ensure the store_true actions are sorted') # Flag |
|||
parser.add_argument('-f', '--falsificle', action="store_false", help='Ensure the store_false actions are sorted') # Flag |
|||
|
|||
|
@ -0,0 +1,22 @@ |
|||
''' |
|||
Created on Jan 7, 2014 |
|||
|
|||
@author: Chris |
|||
''' |
|||
|
|||
class Command(object): |
|||
def __init__(self): |
|||
pass |
|||
|
|||
def execute(self): |
|||
pass |
|||
|
|||
|
|||
class NextButton(Command): |
|||
def execute(self): |
|||
print "Next Button" |
|||
|
|||
class CancelButton(Command): |
|||
def execute(self): |
|||
print 'Cancel button!' |
|||
|
Write
Preview
Loading…
Cancel
Save