# Path: pyqi/commands/make_optparse.py
# class MakeOptparse(CodeHeaderGenerator):
#     BriefDescription = "Consume a Command, stub out an optparse configuration"
#     LongDescription = """Construct and stub out the basic optparse configuration for a given Command. This template provides comments and examples of what to fill in."""
# 
#     CommandIns = ParameterCollection(
#         CodeHeaderGenerator.CommandIns.Parameters + [
#         CommandIn(Name='command', DataType=Command,
#                   Description='an existing Command', Required=True),
#         CommandIn(Name='command_module', DataType=str,
#                   Description='the Command source module', Required=True)
#         ]
#     )
# 
#     CommandOuts = ParameterCollection([
#         CommandOut(Name='result', DataType=list,
#                    Description='The resulting template configuration')
#     ])
# 
#     def run(self, **kwargs):
#         code_header_lines = super(MakeOptparse, self).run(
#                 author=kwargs['author'], email=kwargs['email'],
#                 license=kwargs['license'], copyright=kwargs['copyright'],
#                 version=kwargs['version'], credits=kwargs['credits'])['result']
# 
#         result_lines = code_header_lines
# 
#         # construct inputs based off of CommandIns
#         cmdin_formatted = []
#         for cmdin in sorted(kwargs['command'].CommandIns.values(),
#                             key=attrgetter('Name')):
#             if cmdin.Required:
#                 default_block = ''
#             else:
#                 default_fmt = {
#                         'default': repr(cmdin.Default),
#                         'default_description': repr(cmdin.DefaultDescription)
#                 }
#                 default_block = default_block_format % default_fmt
# 
#             if cmdin.DataType is bool:
#                 action = 'store_true'
#                 data_type = None
#             else:
#                 action = 'store'
#                 data_type = cmdin.DataType
# 
#             fmt = {'name':cmdin.Name,
#                    'datatype':getattr(data_type, '__name__', None),
#                    'action':action, 'required':str(cmdin.Required),
#                    'help':cmdin.Description, 'default_block':default_block}
#             cmdin_formatted.append(input_format % fmt)
# 
#         cmdout_formatted = []
#         for cmdin in sorted(kwargs['command'].CommandOuts.values(),
#                             key=attrgetter('Name')):
#             fmt = {'name':cmdin.Name}
#             cmdout_formatted.append(output_format % fmt)
# 
# 
#         cmdin_formatted = ''.join(cmdin_formatted)
#         cmdout_formatted = ''.join(cmdout_formatted)
#         header_fmt = {'command_module':kwargs['command_module'],
#                       'input_fmt': cmdin_formatted,
#                       'output_fmt':cmdout_formatted}
# 
#         result_lines.extend((header_format % header_fmt).split('\n'))
#         return {'result': result_lines}
# 
# Path: pyqi/core/command.py
# class CommandIn(Parameter):
#     """A ``Command`` input variable type"""
#     def __init__(self, Name, DataType, Description, Required=False,
#                  Default=None, DefaultDescription=None, **kwargs):
#         self.Required = Required
#         self.Default = Default
#         self.DefaultDescription = DefaultDescription
# 
#         if Required and Default is not None:
#             raise IncompetentDeveloperError("Found required CommandIn '%s' "
#                     "with default value '%r'. Required CommandIns cannot have "
#                     "default values." % (Name, Default))
# 
#         super(CommandIn, self).__init__(Name, DataType, Description, **kwargs)
# 
# class ParameterCollection(dict):
#     """A collection of parameters with dict like lookup"""
#     def __init__(self, Parameters):
#         self.Parameters = Parameters
# 
#         for p in self.Parameters:
#             if p.Name in self:
#                 raise IncompetentDeveloperError("Found duplicate Parameter "
#                                                 "name '%s'. Parameter names "
#                                                 "must be unique." % p.Name)
#             else:
#                 super(ParameterCollection, self).__setitem__(p.Name, p)
# 
#     def __getitem__(self, key):
#         try:
#             return super(ParameterCollection, self).__getitem__(key)
#         except KeyError:
#             raise UnknownParameterError("Parameter not found: %s" % key)
# 
#     def __setitem__(self, key, val):
#         raise TypeError("ParameterCollections are immutable")
#     __delattr__ = __setitem__


from pyqi.commands.make_optparse import MakeOptparse
from pyqi.core.command import CommandIn, ParameterCollection
from unittest import TestCase, main
#!/usr/bin/env python

#-----------------------------------------------------------------------------
# Copyright (c) 2013, The BiPy Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------

from __future__ import division

__credits__ = ["Daniel McDonald", "Jai Ram Rideout", "Doug Wendel",
    "Greg Caporaso"]

class MakeOptparseTests(TestCase):
    def setUp(self):
        self.cmd = MakeOptparse()

    def test_run(self):
        exp = win_text

        pc = CommandIn(Name='DUN', Required=True, DataType=str, Description="")

# Path: pyqi/commands/make_optparse.py
# class MakeOptparse(CodeHeaderGenerator):
#     BriefDescription = "Consume a Command, stub out an optparse configuration"
#     LongDescription = """Construct and stub out the basic optparse configuration for a given Command. This template provides comments and examples of what to fill in."""
# 
#     CommandIns = ParameterCollection(
#         CodeHeaderGenerator.CommandIns.Parameters + [
#         CommandIn(Name='command', DataType=Command,
#                   Description='an existing Command', Required=True),
#         CommandIn(Name='command_module', DataType=str,
#                   Description='the Command source module', Required=True)
#         ]
#     )
# 
#     CommandOuts = ParameterCollection([
#         CommandOut(Name='result', DataType=list,
#                    Description='The resulting template configuration')
#     ])
# 
#     def run(self, **kwargs):
#         code_header_lines = super(MakeOptparse, self).run(
#                 author=kwargs['author'], email=kwargs['email'],
#                 license=kwargs['license'], copyright=kwargs['copyright'],
#                 version=kwargs['version'], credits=kwargs['credits'])['result']
# 
#         result_lines = code_header_lines
# 
#         # construct inputs based off of CommandIns
#         cmdin_formatted = []
#         for cmdin in sorted(kwargs['command'].CommandIns.values(),
#                             key=attrgetter('Name')):
#             if cmdin.Required:
#                 default_block = ''
#             else:
#                 default_fmt = {
#                         'default': repr(cmdin.Default),
#                         'default_description': repr(cmdin.DefaultDescription)
#                 }
#                 default_block = default_block_format % default_fmt
# 
#             if cmdin.DataType is bool:
#                 action = 'store_true'
#                 data_type = None
#             else:
#                 action = 'store'
#                 data_type = cmdin.DataType
# 
#             fmt = {'name':cmdin.Name,
#                    'datatype':getattr(data_type, '__name__', None),
#                    'action':action, 'required':str(cmdin.Required),
#                    'help':cmdin.Description, 'default_block':default_block}
#             cmdin_formatted.append(input_format % fmt)
# 
#         cmdout_formatted = []
#         for cmdin in sorted(kwargs['command'].CommandOuts.values(),
#                             key=attrgetter('Name')):
#             fmt = {'name':cmdin.Name}
#             cmdout_formatted.append(output_format % fmt)
# 
# 
#         cmdin_formatted = ''.join(cmdin_formatted)
#         cmdout_formatted = ''.join(cmdout_formatted)
#         header_fmt = {'command_module':kwargs['command_module'],
#                       'input_fmt': cmdin_formatted,
#                       'output_fmt':cmdout_formatted}
# 
#         result_lines.extend((header_format % header_fmt).split('\n'))
#         return {'result': result_lines}
# 
# Path: pyqi/core/command.py
# class CommandIn(Parameter):
#     """A ``Command`` input variable type"""
#     def __init__(self, Name, DataType, Description, Required=False,
#                  Default=None, DefaultDescription=None, **kwargs):
#         self.Required = Required
#         self.Default = Default
#         self.DefaultDescription = DefaultDescription
# 
#         if Required and Default is not None:
#             raise IncompetentDeveloperError("Found required CommandIn '%s' "
#                     "with default value '%r'. Required CommandIns cannot have "
#                     "default values." % (Name, Default))
# 
#         super(CommandIn, self).__init__(Name, DataType, Description, **kwargs)
# 
# class ParameterCollection(dict):
#     """A collection of parameters with dict like lookup"""
#     def __init__(self, Parameters):
#         self.Parameters = Parameters
# 
#         for p in self.Parameters:
#             if p.Name in self:
#                 raise IncompetentDeveloperError("Found duplicate Parameter "
#                                                 "name '%s'. Parameter names "
#                                                 "must be unique." % p.Name)
#             else:
#                 super(ParameterCollection, self).__setitem__(p.Name, p)
# 
#     def __getitem__(self, key):
#         try:
#             return super(ParameterCollection, self).__getitem__(key)
#         except KeyError:
#             raise UnknownParameterError("Parameter not found: %s" % key)
# 
#     def __setitem__(self, key, val):
#         raise TypeError("ParameterCollections are immutable")
#     __delattr__ = __setitem__


# Path: tests/test_commands/test_make_optparse.py
from pyqi.commands.make_optparse import MakeOptparse
from pyqi.core.command import CommandIn, ParameterCollection
from unittest import TestCase, main

#!/usr/bin/env python

#-----------------------------------------------------------------------------
# Copyright (c) 2013, The BiPy Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------

from __future__ import division

__credits__ = ["Daniel McDonald", "Jai Ram Rideout", "Doug Wendel",
    "Greg Caporaso"]

class MakeOptparseTests(TestCase):
    def setUp(self):
        self.cmd = MakeOptparse()

    def test_run(self):
        exp = win_text

        pc = CommandIn(Name='DUN', Required=True, DataType=str, Description="")

        bool_param = CommandIn(Name='imabool', DataType=bool,