Beispiel #1
0
 def testFireObject(self):
     self.assertEqual(
         fire.Fire(tc.WithDefaults(), command=["double", "--count", "5"]),
         10)
     self.assertEqual(
         fire.Fire(tc.WithDefaults(), command=["triple", "--count", "5"]),
         15)
Beispiel #2
0
 def testFireObject(self):
     self.assertEqual(
         fire.Fire(tc.WithDefaults(), command=['double', '--count', '5']),
         10)
     self.assertEqual(
         fire.Fire(tc.WithDefaults(), command=['triple', '--count', '5']),
         15)
Beispiel #3
0
 def testHelpTextNameSectionCommandWithSeparatorVerbose(self):
   component = tc.WithDefaults().double
   t = trace.FireTrace(component, name='double', separator='-')
   t.AddSeparator()
   help_screen = helptext.HelpText(component=component, trace=t, verbose=True)
   self.assertIn('double -', help_screen)
   self.assertIn('double - -', help_screen)
    def testHelpScreenForFunctionFunctionWithDefaultArgs(self):
        component = tc.WithDefaults().double
        t = trace.FireTrace(component, name='double')
        info = inspectutils.Info(component)
        info['docstring_info'] = docstrings.parse(info['docstring'])
        help_output = helputils.HelpText(component, info, t)
        expected_output = """
    NAME
        double - Returns the input multiplied by 2.

    SYNOPSIS
        double [--count=COUNT]

    DESCRIPTION
        Returns the input multiplied by 2.

    FLAGS
        --count
            Input number that you want to double.

    NOTES
        You could also use flags syntax for POSITIONAL ARGUMENTS
    """
        self.assertEqual(
            textwrap.dedent(expected_output).lstrip('\n'), help_output)
Beispiel #5
0
 def testHelpTextUnderlineFlag(self):
     component = tc.WithDefaults().triple
     t = trace.FireTrace(component, name='triple')
     help_screen = helptext.HelpText(component, t)
     self.assertIn(formatting.Bold('NAME') + '\n    triple', help_screen)
     self.assertIn(
         formatting.Bold('SYNOPSIS') + '\n    triple <flags>', help_screen)
     self.assertIn(
         formatting.Bold('FLAGS') + '\n    --' +
         formatting.Underline('count'), help_screen)
Beispiel #6
0
 def testHelpTextFunctionWithDefaults(self):
   component = tc.WithDefaults().triple
   help_screen = helptext.HelpText(
       component=component,
       trace=trace.FireTrace(component, name='triple'))
   self.assertIn('NAME\n    triple', help_screen)
   self.assertIn('SYNOPSIS\n    triple <flags>', help_screen)
   self.assertNotIn('DESCRIPTION', help_screen)
   self.assertIn('FLAGS\n    --count=COUNT\n        Default: 0', help_screen)
   self.assertNotIn('NOTES', help_screen)
Beispiel #7
0
 def testHelpTextFunctionWithDefaults(self):
     component = tc.WithDefaults().triple
     help_screen = helptext.HelpText(
         component=component, trace=trace.FireTrace(component, name="triple")
     )
     self.assertIn("NAME\n    triple", help_screen)
     self.assertIn("SYNOPSIS\n    triple <flags>", help_screen)
     self.assertNotIn("DESCRIPTION", help_screen)
     self.assertIn("FLAGS\n    --count=COUNT\n        Default: 0", help_screen)
     self.assertNotIn("NOTES", help_screen)
Beispiel #8
0
 def testHelpTextUnderlineFlag(self):
     component = tc.WithDefaults().triple
     t = trace.FireTrace(component, name="triple")
     help_screen = helptext.HelpText(component, t)
     self.assertIn(formatting.Bold("NAME") + "\n    triple", help_screen)
     self.assertIn(formatting.Bold("SYNOPSIS") + "\n    triple <flags>", help_screen)
     self.assertIn(
         formatting.Bold("FLAGS") + "\n    --" + formatting.Underline("count"),
         help_screen,
     )
Beispiel #9
0
 def testHelpTextFunctionWithDefaults(self):
     component = tc.WithDefaults().triple
     info = inspectutils.Info(component)
     help_screen = helptext.HelpText(component=component,
                                     info=info,
                                     trace=trace.FireTrace(component,
                                                           name='triple'))
     self.assertIn('NAME\n    triple', help_screen)
     self.assertIn('SYNOPSIS\n    triple [--count=COUNT]', help_screen)
     self.assertNotIn('DESCRIPTION', help_screen)
     self.assertIn('FLAGS\n    --count', help_screen)
     self.assertNotIn('NOTES', help_screen)
Beispiel #10
0
 def testHelpTextUnderlineFlag(self):
     component = tc.WithDefaults().triple
     info = inspectutils.Info(component)
     t = trace.FireTrace(component, name='triple')
     help_screen = helptext.HelpText(component, info, t)
     self.assertIn(formatting.Bold('NAME') + '\n    triple', help_screen)
     self.assertIn(
         formatting.Bold('SYNOPSIS') + '\n    triple [--count=COUNT]',
         help_screen)
     self.assertIn(
         formatting.Bold('FLAGS') + '\n    --' +
         formatting.Underline('count'), help_screen)
Beispiel #11
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)
 def testHelpStringFunctionWithDefaults(self):
     obj = tc.WithDefaults()
     helpstring = helputils.HelpString(obj.triple)
     if six.PY2:
         self.assertIn('Type:        instancemethod\n', helpstring)
     else:
         self.assertIn('Type:        method\n', helpstring)
     self.assertIn(
         'String form: <bound method WithDefaults.triple of '
         '<fire.test_components.WithDefaults object', helpstring)
     self.assertIn('test_components.py', helpstring)
     self.assertIn('Line:        ', helpstring)
     self.assertIn('Usage:       [COUNT]\n'
                   '             [--count COUNT]', helpstring)
Beispiel #13
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)
Beispiel #14
0
    def testHelpScreenForFunctionFunctionWithDefaultArgs(self):
        component = tc.WithDefaults().double
        t = trace.FireTrace(component, name='double')
        help_output = helptext.HelpText(component, t)
        expected_output = """
    NAME
        double - Returns the input multiplied by 2.

    SYNOPSIS
        double [--count=COUNT]

    DESCRIPTION
        Returns the input multiplied by 2.

    FLAGS
        --count
          Input number that you want to double."""
        self.assertEqual(
            textwrap.dedent(expected_output).strip(), help_output.strip())
Beispiel #15
0
 def testFireObject(self):
   self.assertEqual(fire.Fire(tc.WithDefaults(), 'double --count 5'), 10)
   self.assertEqual(fire.Fire(tc.WithDefaults(), 'triple --count 5'), 15)