Browse Source

Removed old files

pull/150/head
chriskiehl 9 years ago
parent
commit
6a94bdaf2b
10 changed files with 51 additions and 568 deletions
  1. 0
      gooey/tests/component_builder_unittest.py
  2. 75
      gooey/tests/components_unittest.py
  3. 13
      gooey/tests/config_generator_unittest.py
  4. 1
      gooey/tests/gui/__init__.py
  5. 1
      gooey/tests/gui/widgets/__init__.py
  6. 194
      gooey/tests/gui/widgets/componenets2_runner.py
  7. 35
      gooey/tests/i18n_unittest.py
  8. 238
      gooey/tests/source_parser_unittest.py
  9. 62
      gooey/tests/test_argparse_to_json.py
  10. 0
      gooey/tests/test_image_repositoy.py

0
gooey/tests/component_builder_unittest.py

75
gooey/tests/components_unittest.py

@ -1,75 +0,0 @@
# '''
# Created on Jan 4, 2014
#
# @author: Chris
#
#
#
#
# '''
#
# import os
# import sys
# import unittest
# from argparse import ArgumentParser
#
# import wx
#
#
# class ComponentsTest(unittest.TestCase):
# def setUp(self):
# parser = ArgumentParser(description='Example Argparse Program')
# parser.add_argument("filename", help="Name of the file you want to read")
# parser.add_argument('-T', '--tester', choices=['yes', 'no'])
# parser.add_argument('-o', '--outfile', help='Redirects output to the specified file')
# parser.add_argument('-v', '--verbose', help='Toggles verbosity off')
# parser.add_argument('-e', '--repeat', action='count')
# action = parser._actions
# self.actions = {
# 'help': action[0],
# 'Positional': action[1],
# 'Choice': action[2],
# 'Optional': action[3],
# 'Flag': action[4],
# 'Counter': action[5]
# }
#
#
# def BuildWindow(self, component, _type):
# app = wx.PySimpleApp()
# module_name = os.path.split(sys.argv[0])[-1]
# frame = wx.Frame(None, -1, _type)
#
# panel = wx.Panel(frame, -1, size=(320, 240))
# component_sizer = component.Build(panel)
# panel.SetSizer(component_sizer)
#
# frame.Show(True)
#
# app.MainLoop()
#
#
# def testPositionalWidgetBuild(self):
# self.SetupWidgetAndBuildWindow('Positional')
#
# def testChoiceWidgetBuild(self):
# self.SetupWidgetAndBuildWindow('Choice')
#
# def testOptionalWidgetBuild(self):
# self.SetupWidgetAndBuildWindow('Optional')
#
# def testFlagWidgetBuild(self):
# self.SetupWidgetAndBuildWindow('Flag')
#
# def testCounterWidgetBuild(self):
# self.SetupWidgetAndBuildWindow('Counter')
#
# def SetupWidgetAndBuildWindow(self, _type):
# component = getattr(components, _type)(self.actions[_type])
# self.BuildWindow(component, _type)
#
#
# if __name__ == "__main__":
# # import sys;sys.argv = ['', 'Test.testName']
# unittest.main()
#

13
gooey/tests/config_generator_unittest.py

@ -1,13 +0,0 @@
from gooey.python_bindings.config_generator import *
def test_create_from_parser(empty_parser):
build_spec = create_from_parser(empty_parser,'.')
assert build_spec['manual_start'] == True
def test_create_from_parser_show_config(empty_parser):
build_spec = create_from_parser(empty_parser,
'.',
show_config=True)
assert build_spec['program_description'] == 'description'

1
gooey/tests/gui/__init__.py

@ -1 +0,0 @@
__author__ = 'Chris'

1
gooey/tests/gui/widgets/__init__.py

@ -1 +0,0 @@
__author__ = 'Chris'

194
gooey/tests/gui/widgets/componenets2_runner.py

@ -1,194 +0,0 @@
from gooey.gui.widgets import components2
__author__ = 'Chris'
import unittest
import wx
from wx.lib.scrolledpanel import ScrolledPanel
TEXT_FIELD = components2.TextField({
'display_name': 'cool title',
'help_msg': 'a help message',
'nargs': '+',
'commands': ['-f', '--fudge'],
'choices': []
})
DROPDOWN = components2.Dropdown({
'display_name': 'cool title',
'help_msg': 'a help message',
'nargs': '+',
'commands': ['-f', '--fudge'],
'choices': ['one', 'two', 'three']
})
COUNTER = components2.Counter({
'display_name': 'cool title',
'help_msg': 'a help message',
'nargs': '+',
'commands': ['-f', '--fudge'],
'choices': []
})
CHECKBOX = components2.CheckBox({
'display_name': 'cool title',
'help_msg': 'a help message',
'nargs': '+',
'commands': ['-f', '--fudge'],
'choices': []
})
RADIOGROUP = components2.RadioGroup({
'display_name': 'mutux options',
'data': [{
'help_msg': 'a help message',
'nargs': '+',
'commands': ['-f', '--fudge'],
'choices': []
}, {
'help_msg': 'a help message',
'nargs': '+',
'commands': ['-g', '--gudge'],
'choices': []
}]
})
class TestPanel(ScrolledPanel):
def __init__(self, parent, widget):
ScrolledPanel.__init__(self, parent)
self.SetupScrolling(scroll_x=False)
sizer = wx.BoxSizer(wx.VERTICAL)
self.widget = widget
sizer.Add(self.widget.build(self), 0, wx.EXPAND)
self.SetSizer(sizer)
class MyFrame(wx.Frame):
def __init__(self, parent, widget):
wx.Frame.__init__(self, parent, title="test", size=(320, 240))
self.SetBackgroundColour('#ffffff')
self.panel = TestPanel(self, widget)
self.Show()
def get_widget(self):
return self.panel.widget
def close(self):
self.Destroy()
class TestComponents(unittest.TestCase):
def setUp(self):
self.app = wx.App(False)
self.frame = None
def tearDown(self):
# self.app = wx.App(False)
self.frame.Destroy()
self.frame = None
def test_textfield_returns_option_and_value_else_none(self):
self.build_test_frame(TEXT_FIELD)
self.assertTrue(self.get_value() == '')
self.get_widget().SetLabelText('value')
self.assertEqual('-f value', self.get_value())
def test_dropdown_returns_option_and_value_else_none(self):
self.build_test_frame(DROPDOWN)
self.assertTrue(self.get_value() == '')
# grab first item from the combo box
self.frame.get_widget()._GetWidget().SetSelection(0)
self.assertEqual('-f one', self.get_value())
def test_counter_returns_option_and_value_else_none(self):
self.build_test_frame(COUNTER)
self.assertTrue(self.get_value() == '')
# counter objects stack,
# so
# 1 = -f,
# 4 = -ffff
self.frame.get_widget()._GetWidget().SetSelection(0)
self.assertEqual('-f', self.get_value())
self.frame.get_widget()._GetWidget().SetSelection(4)
self.assertEqual('-fffff', self.get_value())
def test_checkbox_returns_option_if_checked_else_none(self):
self.build_test_frame(CHECKBOX)
self.assertTrue(self.get_value() == '')
self.frame.get_widget()._GetWidget().SetValue(1)
self.assertEqual('-f', self.get_value())
def test_radiogroup_returns_option_if_checked_else_none(self):
self.build_test_frame(RADIOGROUP)
self.assertTrue(self.get_value() == '')
# self.frame.get_widget()._GetWidget()[0].SetValue(1)
# self.assertEqual('-f', self.get_value())
def build_test_frame(self, widget):
# self.app = wx.App(False)
self.frame = MyFrame(None, widget)
def get_widget(self):
return self.frame.get_widget()._GetWidget()
def get_value(self):
return self.frame.get_widget().GetValue()
if __name__ == '__main__':
unittest.main()
# a = {
# 'required' : [
# {
# 'component': 'TextField',
# 'data': {
# 'display_name': 'filename',
# 'help_text': 'path to file you want to process',
# 'command_args': ['-f', '--infile']
# }
# },
# {
# 'component': 'FileChooser',
# 'data': {
# 'display_name': 'Output Location',
# 'help_text': 'Where to save the file',
# 'command_args': ['-o', '--outfile']
# }
# }
# ],
# 'optional' : [
# {
# 'component': 'RadioGroup',
# 'data': [
# {
# 'display_name': 'Output Location',
# 'help_text': 'Where to save the file',
# 'command_args': ['-o', '--outfile']
# }, {
# 'display_name': 'Output Location',
# 'help_text': 'Where to save the file',
# 'command_args': ['-o', '--outfile']
# }
# ]
# }
# ]
# }
#
# ]
# }

35
gooey/tests/i18n_unittest.py

@ -1,35 +0,0 @@
# '''
# Created on Jan 25, 2014
#
# @author: Chris
# '''
#
# import unittest
#
# import i18n
#
#
# class Test(unittest.TestCase):
#
# def test_i18n_loads_module_by_name(self):
# self.assertTrue(i18n._DICTIONARY is None)
#
# i18n.load('english')
# self.assertTrue(i18n._DICTIONARY is not None)
# self.assertEqual('Cancel', i18n._('cancel'))
#
# i18n.load('french')
# self.assertEqual('Annuler', i18n._('cancel'))
#
#
# def test_i18n_throws_exception_on_no_lang_file_found(self):
# self.assertRaises(IOError, i18n.load, 'chionenglish')
#
#
#
#
#
# if __name__ == "__main__":
# pass
# #import sys;sys.argv = ['', 'Test.testName']
# unittest.main()

238
gooey/tests/source_parser_unittest.py

@ -1,238 +0,0 @@
# '''
# Created on Feb 2, 2014
#
# @author: Chris
#
# TODO:
# - test no argparse module
# - test argparse in main
# - test argparse in try/catch
# -
#
# '''
#
# import os
# import ast
# import unittest
# from gooey.python_bindings import source_parser
#
#
# basic_pyfile = \
# '''
# import os
#
# def say_jello():
# print "Jello!"
#
# def main():
# print "hello!"
# parser = ArgumentParser(description='Example Argparse Program', formatter_class=RawDescriptionHelpFormatter)
# parser.add_argument("filename", help="filename")
# parser.add_argument("-r", "--recursive", dest="recurse", action="store_true",
# help="recurse into subfolders [default: %(default)s]")
# parser.add_argument("-v", "--verbose", dest="verbose", action="count",
# help="set verbosity level [default: %(default)s]")
# parser.add_argument("-i", "--include", action="append",
# help="only include paths matching this regex pattern. Note: exclude is given preference over include. [default: %(default)s]",
# metavar="RE")
# parser.add_argument("-m", "--mycoolargument", help="mycoolargument")
# parser.add_argument("-e", "--exclude", dest="exclude",
# help="exclude paths matching this regex pattern. [default: %(default)s]", metavar="RE")
# parser.add_argument('-V', '--version', action='version')
# parser.add_argument('-T', '--tester', choices=['yes', 'no'])
# parser.add_argument(dest="paths", help="paths to folder(s) with source file(s) [default: %(default)s]",
# metavar="path", nargs='+')
#
# if __name__ == '__main__':
# main()
# '''
#
#
#
# class TestSourceParser(unittest.TestCase):
# PATH = os.path.join(os.path.dirname(__file__), 'examples')
#
# def module_path(self, name):
# return os.path.join(self.PATH, name)
#
# def setUp(self):
# self._mockapp = self.module_path('examples.py')
# self._module_with_noargparse = self.module_path('module_with_no_argparse.py')
# self._module_with_arparse_in_try = self.module_path('TODO.py')
# self._module_with_argparse_in_main = self.module_path('example_argparse_souce_in_main.py')
#
# def test_should_throw_parser_exception_if_no_argparse_found_in_module(self):
# with self.assertRaises(source_parser.ParserError):
# source_parser.parse_source_file(self._module_with_noargparse)
#
#
# def test_find_main(self):
# example_source = '''
# def main(): pass
# '''
# nodes = ast.parse(example_source)
# main_node = source_parser.find_main(nodes)
# self.assertEqual('main', main_node.name)
#
#
# def test_find_main_throws_exception_if_not_found(self):
# example_source = '''
# def some_cool_function_that_is_not_main(): pass
# '''
# with self.assertRaises(source_parser.ParserError):
# nodes = ast.parse(example_source)
# main_node = source_parser.find_main(nodes)
# self.assertEqual('main', main_node.name)
#
#
# def test_find_try_blocks_finds_all_tryblock_styles(self):
# example_source = '''
# try: a = 1
# except: pass
#
# try: pass
# finally: pass
#
# try: pass
# except: pass
# else: pass
# '''
# nodes = ast.parse(example_source)
# try_blocks = source_parser.find_try_blocks(nodes)
# self.assertEqual(3, len(try_blocks))
#
#
# def test_find_try_blocks_returns_empty_if_no_blocks_present(self):
# example_source = 'def main(): pass'
# nodes = ast.parse(example_source)
# result = source_parser.find_try_blocks(nodes)
# self.assertEqual(list(), result)
#
# def test_find_argparse_located_object_when_imported_by_direct_name(self):
# example_source = '''
# def main():
# parser = ArgumentParser(description='Example Argparse Program', formatter_class=RawDescriptionHelpFormatter)
# '''
# nodes = ast.parse(example_source)
# main_node = source_parser.find_main(nodes)
# self.assertEqual('main', main_node.name)
# containing_block = source_parser.find_block_containing_argparse([main_node])
# self.assertTrue(containing_block is not None)
#
# def test_find_argparse_located_object_when_access_through_module_dot_notation(self):
# example_source = '''
# def main():
# parser = argparse.ArgumentParser(description='Example Argparse Program', formatter_class=RawDescriptionHelpFormatter)
# '''
# nodes = ast.parse(example_source)
# main_node = source_parser.find_main(nodes)
# self.assertEqual('main', main_node.name)
# containing_block = source_parser.find_block_containing_argparse([main_node])
# self.assertTrue(containing_block is not None)
#
# def test_find_argparse_locates_assignment_stmnt_in_main(self):
# nodes = ast.parse(source_parser._openfile(self._module_with_argparse_in_main))
# main_node = source_parser.find_main(nodes)
# self.assertEqual('main', main_node.name)
# containing_block = source_parser.find_block_containing_argparse([main_node])
# self.assertTrue(containing_block is not None)
# self.assertEqual('main', containing_block.name)
#
#
# def test_find_argparse_locates_assignment_stmnt_in_try_block(self):
# nodes = ast.parse(source_parser._openfile(self._module_with_arparse_in_try))
# main_node = source_parser.find_main(nodes)
# self.assertEqual('main', main_node.name)
# try_nodes = source_parser.find_try_blocks(main_node)
# self.assertTrue(len(try_nodes) > 0)
# containing_block = source_parser.find_block_containing_argparse([main_node] + try_nodes)
# self.assertEqual(ast.TryExcept, type(containing_block))
#
#
# def test_find_argparse_throws_exception_if_not_found(self):
# with self.assertRaises(source_parser.ParserError):
# nodes = ast.parse(source_parser._openfile(self._module_with_noargparse))
# main_node = source_parser.find_main(nodes)
# self.assertEqual('main', main_node.name)
# try_nodes = source_parser.find_try_blocks(main_node)
# containing_block = source_parser.find_block_containing_argparse([main_node] + try_nodes)
#
#
# def test_has_instantiator_returns_true_if_object_found(self):
# source = '''
# parser = ArgumentParser(description='Example Argparse Program', formatter_class=RawDescriptionHelpFormatter)
# parser.add_argument("filename", help="filename")
# '''
# nodes = ast.parse(source)
# self.assertTrue(source_parser.has_instantiator(nodes.body[0], 'ArgumentParser'))
#
#
# def test_has_instantiator_returns_false_if_object_not_found(self):
# source = '''
# parser = NopeParser(description='Example Argparse Program', formatter_class=RawDescriptionHelpFormatter)
# parser.add_argument("filename", help="filename")
# '''
# nodes = ast.parse(source)
# self.assertFalse(source_parser.has_instantiator(nodes.body[0], 'ArgumentParser'))
#
# def test_has_assignment_returns_true_if_object_found(self):
# source = '''
# parser = ArgumentParser(description='Example Argparse Program', formatter_class=RawDescriptionHelpFormatter)
# parser.add_argument("filename", help="filename")
# '''
# nodes = ast.parse(source)
# self.assertTrue(source_parser.has_assignment(nodes.body[1], 'add_argument'))
#
# def test_has_assignment_returns_false_if_object_not_found(self):
# source = '''
# parser = ArgumentParser(description='Example Argparse Program', formatter_class=RawDescriptionHelpFormatter)
# parser.add_argument("filename", help="filename")
# '''
# nodes = ast.parse(source)
# self.assertFalse(source_parser.has_instantiator(nodes.body[1], 'add_argument'))
#
# def test_parser_identifies_import_module(self):
# source = '''
# import os
# import itertools
# from os import path
# '''
# import _ast
# nodes = ast.parse(source)
# module_imports = source_parser.get_nodes_by_instance_type(nodes, _ast.Import)
# self.assertEqual(2, len(module_imports))
#
# def test_parser_identifies_import_from(self):
# source = '''
# import os
# import itertools
# from os import path
# from gooey.gooey_decorator import Gooey
# '''
# import _ast
# nodes = ast.parse(source)
# from_imports = source_parser.get_nodes_by_instance_type(nodes, _ast.ImportFrom)
# self.assertEqual(2, len(from_imports))
#
#
# def test_get_indent_return_indent_amount_for_tabs_and_spaces(self):
# spaced_lines = ["def main"," def main"," def main"," def main"]
# expected_indent = ["", " ", " ", " "]
# for line, expected in zip(spaced_lines, expected_indent):
# self.assertEqual(expected, source_parser.get_indent(line))
#
# # def test_parse_source_file__file_with_argparse_in_main__succesfully_finds_and_returns_ast_obejcts(self):
# # ast_objects = source_parser.parse_source_file(self._module_with_argparse_in_main)
# # for obj in ast_objects:
# # self.assertTrue(type(obj) in (ast.Assign, ast.Expr))
# #
# # def test_parse_source_file__file_with_argparse_in_try_block__succesfully_finds_and_returns_ast_obejcts(self):
# # ast_objects = source_parser.parse_source_file(self._module_with_arparse_in_try)
# # for obj in ast_objects:
# # self.assertTrue(type(obj) in (ast.Assign, ast.Expr))
#
#
# if __name__ == "__main__":
# #import sys;sys.argv = ['', 'Test.testName']
# unittest.main()
#

gooey/tests/argparse_to_json_unittest.py → gooey/tests/test_argparse_to_json.py

@ -7,24 +7,64 @@ def test_parser_converts_to_correct_type(empty_parser, complete_parser, subparse
assert convert(empty_parser)['layout_type'] == 'standard'
assert convert(complete_parser)['layout_type'] == 'standard'
def test_parser_without_subparser_recieves_root_entry(complete_parser):
'''
Non-subparser setups should receive a default root key called 'primary'
'''
result = convert(complete_parser)
assert 'primary' in result['widgets']
def test_convert_std_parser(complete_parser):
def test_grouping_structure(complete_parser):
'''
The output of the 'widgets' branch is now wrapped in another
layer to facilitate interop with the subparser structure
old: widgets: []
new: widgets: {'a': {}, 'b': {}, ..}
'''
result = convert(complete_parser)
assert result['layout_type'] == 'standard'
assert result['widgets']
assert isinstance(result['widgets'], list)
groupings = result['widgets']
# should now be a dict rather than a list
assert isinstance(groupings, dict)
# make sure our expected root keys are there
for name, group in groupings.iteritems():
assert 'command' in group
assert 'contents' in group
# contents should be the old list of widget info
assert isinstance(group['contents'], list)
def test_subparser_uses_prog_value_if_available():
parser = argparse.ArgumentParser(description='qidev')
parser.add_argument('--verbose', help='be verbose', dest='verbose', action='store_true', default=False)
subs = parser.add_subparsers(help='commands', dest='command')
# NO prog definition for the sub parser
subs.add_parser('config', help='configure defaults for qidev')
# The stock parser name supplied above (e.g. config) is
# now in the converted doc
result = convert(parser)
assert 'config' in result['widgets']
# new subparser
parser = argparse.ArgumentParser(description='qidev')
parser.add_argument('--verbose', help='be verbose', dest='verbose', action='store_true', default=False)
subs = parser.add_subparsers(help='commands', dest='command')
# prog definition for the sub parser IS supplied
subs.add_parser('config', prog="My Config", help='configure defaults for qidev')
# Should've picked up the prog value
result = convert(parser)
assert 'My Config' in result['widgets']
entry = result['widgets'][0]
def test_convert_std_parser(complete_parser):
result = convert(complete_parser)
# grab the first entry from the dict
entry = result['widgets']['primary']['contents'][0]
print entry
assert 'type' in entry
assert 'required' in entry
assert 'data' in entry
required = filter(lambda x: x['required'], result['widgets'])
optional = filter(lambda x: not x['required'], result['widgets'])
assert len(required) == 4
assert len(optional) == 8
def test_convert_sub_parser(subparser):
result = convert(subparser)
assert result['layout_type'] == 'column'

gooey/tests/image_repositoy_unittest.py → gooey/tests/test_image_repositoy.py

Loading…
Cancel
Save