示例#1
0
  def testUsageOutputConstructorWithParameterVerbose(self):
    component = tc.InstanceVars
    t = trace.FireTrace(component, name='InstanceVars')
    usage_output = helptext.UsageText(component, trace=t, verbose=True)
    expected_output = """
    Usage: InstanceVars <command> | --arg1=ARG1 --arg2=ARG2
      available commands:    run

    For detailed information on this command, run:
      InstanceVars --help"""
    self.assertEqual(
        textwrap.dedent(expected_output).lstrip('\n'),
        usage_output)
示例#2
0
 def testHelpTextFunctionWithLongDefaults(self):
     component = tc.WithDefaults().text
     help_screen = helptext.HelpText(component=component,
                                     trace=trace.FireTrace(component,
                                                           name='text'))
     self.assertIn('NAME\n    text', help_screen)
     self.assertIn('SYNOPSIS\n    text <flags>', help_screen)
     self.assertNotIn('DESCRIPTION', help_screen)
     self.assertIn(
         'FLAGS\n    --string=STRING\n'
         '        Default: \'0001020304050607080910'
         '1112131415161718192021222324252627282...', help_screen)
     self.assertNotIn('NOTES', help_screen)
示例#3
0
  def testUsageOutputFunctionWithDocstring(self):
    component = tc.multiplier_with_docstring
    t = trace.FireTrace(component, name='multiplier_with_docstring')
    usage_output = helptext.UsageText(component, trace=t, verbose=False)
    expected_output = """
    Usage: multiplier_with_docstring NUM <flags>
      optional flags:        --rate

    For detailed information on this command, run:
      multiplier_with_docstring --help"""
    self.assertEqual(
        textwrap.dedent(expected_output).lstrip('\n'),
        usage_output)
示例#4
0
  def testUsageOutputFunctionWithHelp(self):
    component = tc.function_with_help
    t = trace.FireTrace(component, name='function_with_help')
    usage_output = helptext.UsageText(component, trace=t, verbose=False)
    expected_output = """
    Usage: function_with_help <flags>
      optional flags:        --help

    For detailed information on this command, run:
      function_with_help -- --help"""
    self.assertEqual(
        usage_output,
        textwrap.dedent(expected_output).lstrip('\n'))
示例#5
0
 def testHelpTextFunctionWithTypesAndDefaultNone(self):
   component = tc.py3p5.WithDefaultsAndTypes().get_int
   help_screen = helptext.HelpText(
       component=component,
       trace=trace.FireTrace(component, name='get_int'))
   self.assertIn('NAME\n    get_int', help_screen)
   self.assertIn('SYNOPSIS\n    get_int <flags>', help_screen)
   self.assertNotIn('DESCRIPTION', help_screen)
   self.assertIn(
       'FLAGS\n    --value=VALUE\n'
       '        Type: Optional[int]\n        Default: None',
       help_screen)
   self.assertNotIn('NOTES', help_screen)
示例#6
0
  def testUsageOutputMethod(self):
    component = tc.NoDefaults().double
    t = trace.FireTrace(component, name='NoDefaults')
    t.AddAccessedProperty(component, 'double', ['double'], None, None)
    usage_output = helptext.UsageText(component, trace=t, verbose=True)
    expected_output = '''
    Usage: NoDefaults double COUNT

    For detailed information on this command, run:
      NoDefaults double --help'''
    self.assertEqual(
        usage_output,
        textwrap.dedent(expected_output).lstrip('\n'))
示例#7
0
 def testHelpTextFunctionWithTypes(self):
     component = tc.py3.WithTypes().double  # pytype: disable=module-attr
     help_screen = helptext.HelpText(component=component,
                                     trace=trace.FireTrace(component,
                                                           name='double'))
     self.assertIn('NAME\n    double', help_screen)
     self.assertIn('SYNOPSIS\n    double COUNT', help_screen)
     self.assertIn('DESCRIPTION', help_screen)
     self.assertIn('POSITIONAL ARGUMENTS\n    COUNT\n        Type: float',
                   help_screen)
     self.assertIn(
         'NOTES\n    You can also use flags syntax for POSITIONAL ARGUMENTS',
         help_screen)
示例#8
0
 def testAddCalledCallable(self):
     t = trace.FireTrace("initial object")
     args = ("example", "args")
     t.AddCalledComponent("result",
                          "cell",
                          args,
                          "sample.py",
                          10,
                          False,
                          action=trace.CALLED_CALLABLE)
     self.assertEqual(
         str(t),
         '1. Initial component\n2. Called callable "cell" (sample.py:10)')
示例#9
0
 def testAddCalledRoutine(self):
     t = trace.FireTrace("initial object")
     args = ("example", "args")
     t.AddCalledComponent("result",
                          "run",
                          args,
                          "sample.py",
                          12,
                          False,
                          action=trace.CALLED_ROUTINE)
     self.assertEqual(
         str(t),
         '1. Initial component\n2. Called routine "run" (sample.py:12)')
示例#10
0
 def testHelpTextInt(self):
     component = 7
     help_screen = helptext.HelpText(component=component,
                                     trace=trace.FireTrace(component, '7'))
     self.assertIn('NAME\n    7', help_screen)
     self.assertIn('SYNOPSIS\n    7 COMMAND | VALUE', help_screen)
     # TODO(zuhaochen): Change assertion after implementing custom
     # description for int.
     self.assertNotIn('DESCRIPTION', help_screen)
     self.assertIn('COMMANDS\n    COMMAND is one of the following:\n',
                   help_screen)
     self.assertIn('VALUES\n    VALUE is one of the following:\n',
                   help_screen)
示例#11
0
 def testHelpTextNoDefaultsObject(self):
     component = tc.NoDefaults()
     help_screen = helptext.HelpText(component=component,
                                     trace=trace.FireTrace(
                                         component, name='NoDefaults'))
     self.assertIn('NAME\n    NoDefaults', help_screen)
     self.assertIn('SYNOPSIS\n    NoDefaults COMMAND', help_screen)
     self.assertNotIn('DESCRIPTION', help_screen)
     self.assertIn('COMMANDS\n    COMMAND is one of the following:',
                   help_screen)
     self.assertIn('double', help_screen)
     self.assertIn('triple', help_screen)
     self.assertNotIn('NOTES', help_screen)
示例#12
0
 def testHelpTextFunctionWithKwargsAndDefaults(self):
     component = tc.fn_with_kwarg_and_defaults
     help_screen = helptext.HelpText(component=component,
                                     trace=trace.FireTrace(component,
                                                           name='text'))
     self.assertIn('NAME\n    text', help_screen)
     self.assertIn('SYNOPSIS\n    text ARG1 ARG2 <flags>', help_screen)
     self.assertIn('DESCRIPTION\n    Function with kwarg', help_screen)
     self.assertIn(
         'FLAGS\n    --opt=OPT\n        Default: True\n'
         '    The following flags are also accepted.'
         '\n    --arg3\n        Description of arg3.\n    '
         'Additional undocumented flags may also be accepted.', help_screen)
示例#13
0
    def testUsageOutput(self):
        component = tc.NoDefaults()
        t = trace.FireTrace(component, name='NoDefaults')
        usage_output = helptext.UsageText(component, trace=t, verbose=False)
        expected_output = """
    Usage: NoDefaults <command>
      available commands:    double | triple

    For detailed information on this command, run:
      NoDefaults --help"""

        self.assertEqual(usage_output,
                         textwrap.dedent(expected_output).lstrip('\n'))
示例#14
0
 def testHelpTextEmptyList(self):
     component = []
     help_screen = helptext.HelpText(component=component,
                                     trace=trace.FireTrace(
                                         component, 'list'))
     self.assertIn('NAME\n    list', help_screen)
     self.assertIn('SYNOPSIS\n    list COMMAND', help_screen)
     # The list docstring is messy, so it is not shown.
     self.assertNotIn('DESCRIPTION', help_screen)
     # We don't check the listed commands either since the list API could
     # potentially change between Python versions.
     self.assertIn('COMMANDS\n    COMMAND is one of the following:\n',
                   help_screen)
示例#15
0
 def testHelpTextFunctionWithBuiltin(self):
     component = 'test'.upper
     info = inspectutils.Info(component)
     help_screen = helptext.HelpText(component=component,
                                     info=info,
                                     trace=trace.FireTrace(
                                         component, 'upper'))
     self.assertIn('NAME\n    upper', help_screen)
     self.assertIn('SYNOPSIS\n    upper', help_screen)
     # We don't check description content here since the content is python
     # version dependent.
     self.assertIn('DESCRIPTION\n', help_screen)
     self.assertNotIn('NOTES', help_screen)
示例#16
0
 def testHelpTextInt(self):
     component = 7
     info = inspectutils.Info(component)
     help_screen = helptext.HelpText(component=component,
                                     info=info,
                                     trace=trace.FireTrace(component, '7'))
     self.assertIn('NAME\n    7', help_screen)
     self.assertIn('SYNOPSIS\n    7 COMMAND | VALUE', help_screen)
     self.assertIn('DESCRIPTION\n', help_screen)
     self.assertIn('COMMANDS\n    COMMAND is one of the followings:\n',
                   help_screen)
     self.assertIn('VALUES\n    VALUE is one of the followings:\n',
                   help_screen)
示例#17
0
 def testHelpTextFunctionWithTypesAndDefaultNone(self):
     component = tc.py3.WithDefaultsAndTypes().get_int  # pytype: disable=module-attr
     help_screen = helptext.HelpText(
         component=component, trace=trace.FireTrace(component, name="get_int")
     )
     self.assertIn("NAME\n    get_int", help_screen)
     self.assertIn("SYNOPSIS\n    get_int <flags>", help_screen)
     self.assertNotIn("DESCRIPTION", help_screen)
     self.assertIn(
         "FLAGS\n    --value=VALUE\n"
         "        Type: Optional[int]\n        Default: None",
         help_screen,
     )
     self.assertNotIn("NOTES", help_screen)
示例#18
0
 def testHelpTextEmptyList(self):
     component = []
     help_screen = helptext.HelpText(component=component,
                                     trace=trace.FireTrace(
                                         component, 'list'))
     self.assertIn('NAME\n    list', help_screen)
     self.assertIn('SYNOPSIS\n    list COMMAND', help_screen)
     # TODO(zuhaochen): Change assertion after custom description is
     # implemented for list type.
     self.assertNotIn('DESCRIPTION', help_screen)
     # We don't check the listed commands either since the list API could
     # potentially change between Python versions.
     self.assertIn('COMMANDS\n    COMMAND is one of the following:\n',
                   help_screen)
示例#19
0
 def testHelpTextNoDefaults(self):
   component = tc.NoDefaults
   # TODO(joejoevictor): We should have inspectutils.Info to generate
   # info['docstring_info'] as well.
   info = inspectutils.Info(component)
   info['docstring_info'] = docstrings.parse(info['docstring'])
   help_screen = helptext.HelpText(
       component=component,
       info=info,
       trace=trace.FireTrace(component, name='NoDefaults'))
   self.assertIn('NAME\n    NoDefaults', help_screen)
   self.assertIn('SYNOPSIS\n    NoDefaults', help_screen)
   self.assertNotIn('DESCRIPTION', help_screen)
   self.assertNotIn('NOTES', help_screen)
示例#20
0
    def testUsageOutputFunctionWithDocstring(self):
        component = tc.multiplier_with_docstring
        t = trace.FireTrace(component, name='multiplier_with_docstring')
        usage_output = helputils.UsageText(component, trace=t, verbose=True)
        expected_output = '''
    Usage: multiplier_with_docstring NUM <flags>

    Available flags: --rate

    For detailed information on this command, run:
    multiplier_with_docstring --help
    '''
        self.assertEqual(usage_output,
                         textwrap.dedent(expected_output).lstrip('\n'))
示例#21
0
 def testHelpTextEmptyList(self):
     component = []
     help_screen = helptext.HelpText(component=component,
                                     trace=trace.FireTrace(
                                         component, 'list'))
     self.assertIn('NAME\n    list', help_screen)
     self.assertIn('SYNOPSIS\n    list COMMAND', help_screen)
     # We don't check description content here since the content could be python
     # version dependent.
     self.assertIn('DESCRIPTION\n', help_screen)
     # We don't check the listed commands either since the list API could
     # potentially change between Python versions.
     self.assertIn('COMMANDS\n    COMMAND is one of the following:\n',
                   help_screen)
示例#22
0
 def testHelpTextObjectWithGroupAndValues(self):
   component = tc.TypedProperties()
   t = trace.FireTrace(component, name='TypedProperties')
   help_screen = helptext.HelpText(
       component=component, trace=t, verbose=True)
   print(help_screen)
   self.assertIn('GROUPS', help_screen)
   self.assertIn('GROUP is one of the following:', help_screen)
   self.assertIn(
       'charlie\n       Class with functions that have default arguments.',
       help_screen)
   self.assertIn('VALUES', help_screen)
   self.assertIn('VALUE is one of the following:', help_screen)
   self.assertIn('alpha', help_screen)
示例#23
0
 def validate(self, url, username, password):
     error_trace = trace.FireTrace(self,
                                   verbose=True,
                                   show_help=True,
                                   show_trace=True)
     self.__is_valid_value(url, 'url', self.XL_DEPLOY_URL, error_trace)
     self.__is_valid_value(username, 'username', self.XL_DEPLOY_USERNAME,
                           error_trace)
     self.__is_valid_value(password, 'password', self.XL_DEPLOY_PASSWORD,
                           error_trace)
     if error_trace.HasError():
         # log the error trace on console, as raising the Exception does not log it on its own.
         self.__print_validation_errors(error_trace)
         raise core.FireExit(2, error_trace)
示例#24
0
 def testHelpTextFunction(self):
     component = tc.NoDefaults().double
     info = inspectutils.Info(component)
     help_screen = helptext.HelpText(component=component,
                                     info=info,
                                     trace=trace.FireTrace(component,
                                                           name='double'))
     self.assertIn('NAME\n    double', help_screen)
     self.assertIn('SYNOPSIS\n    double COUNT', help_screen)
     self.assertNotIn('DESCRIPTION', help_screen)
     self.assertIn('POSITIONAL ARGUMENTS\n    COUNT', help_screen)
     self.assertIn(
         'NOTES\n    You could also use flags syntax for POSITIONAL ARGUMENTS',
         help_screen)
示例#25
0
  def testUsageOutputConstructorWithParameter(self):
    component = tc.InstanceVars
    t = trace.FireTrace(component, name='InstanceVars')
    info = inspectutils.Info(component)
    usage_output = helptext.UsageText(component, info, trace=t, verbose=True)
    expected_output = '''
    Usage: InstanceVars ARG1 ARG2

    For detailed information on this command, run:
      InstanceVars --help
    '''
    self.assertEqual(
        usage_output,
        textwrap.dedent(expected_output).lstrip('\n'))
示例#26
0
 def testHelpTextFunctionWithLongDefaults(self):
     component = tc.WithDefaults().text
     help_screen = helptext.HelpText(
         component=component, trace=trace.FireTrace(component, name="text")
     )
     self.assertIn("NAME\n    text", help_screen)
     self.assertIn("SYNOPSIS\n    text <flags>", help_screen)
     self.assertNotIn("DESCRIPTION", help_screen)
     self.assertIn(
         "FLAGS\n    --string=STRING\n"
         "        Default: '0001020304050607080910"
         "1112131415161718192021222324252627282...",
         help_screen,
     )
     self.assertNotIn("NOTES", help_screen)
示例#27
0
    def testUsageOutputVerbose(self):
        component = tc.NoDefaults()
        t = trace.FireTrace(component, name='NoDefaults')
        usage_output = helputils.UsageText(component, trace=t, verbose=True)
        expected_output = '''
    Usage: NoDefaults <groups|commands|values>
    available groups:   __delattr__ | __dict__ | __doc__ | __getattribute__ | __hash__ | __init__ | __repr__ | __setattr__ | __str__ | __weakref__
    available commands: __class__ | __format__ | __new__ | __reduce__ | __reduce_ex__ | __sizeof__ | __subclasshook__ | double | triple
    available values:   __module__

    For detailed information on this command, run:
    NoDefaults --help
    '''
        self.assertEqual(usage_output,
                         textwrap.dedent(expected_output).lstrip('\n'))
示例#28
0
    def testUsageOutputNone(self):
        component = None
        t = trace.FireTrace(component, name='None')
        info = inspectutils.Info(component)
        usage_output = helptext.UsageText(component,
                                          info,
                                          trace=t,
                                          verbose=True)
        expected_output = '''
    Usage: None

    For detailed information on this command, run:
      None --help'''
        self.assertEqual(usage_output,
                         textwrap.dedent(expected_output).lstrip('\n'))
示例#29
0
  def testUsageOutputVerbose(self):
    component = tc.NoDefaults()
    t = trace.FireTrace(component, name='NoDefaults')
    info = inspectutils.Info(component)
    usage_output = helptext.UsageText(component, info, trace=t, verbose=True)
    expected_output = '''
    Usage: NoDefaults <command>
      available commands:    double | triple

    For detailed information on this command, run:
      NoDefaults --help
    '''
    self.assertEqual(
        usage_output,
        textwrap.dedent(expected_output).lstrip('\n'))
示例#30
0
    def testUsageOutputCallable(self):
        # This is both a group and a command.
        component = tc.CallableWithKeywordArgument()
        t = trace.FireTrace(
            component, name="CallableWithKeywordArgument", separator="@"
        )
        usage_output = helptext.UsageText(component, trace=t, verbose=False)
        expected_output = """
    Usage: CallableWithKeywordArgument <command> | <flags>
      available commands:    print_msg
      flags are accepted

    For detailed information on this command, run:
      CallableWithKeywordArgument -- --help"""
        self.assertEqual(textwrap.dedent(expected_output).lstrip("\n"), usage_output)