# Copyright (C) 2017 Google Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from __future__ import absolute_import from __future__ import division from __future__ import print_function from fire import helputils from fire import test_components as tc import six import unittest class HelpUtilsTest(unittest.TestCase): def testHelpStringClass(self): helpstring = helputils.HelpString(tc.NoDefaults) self.assertIn('Type: type', helpstring) self.assertIn("String form: ", helpstring) self.assertIn('test_components.py', helpstring) self.assertIn('Line: ', helpstring) self.assertNotIn('Usage', helpstring) def testHelpStringObject(self): obj = tc.NoDefaults() helpstring = helputils.HelpString(obj) self.assertIn('Type: NoDefaults', helpstring) self.assertIn('String form: ", helpstring) else: self.assertIn("String form: ", helpstring) self.assertNotIn('Usage', helpstring) def testHelpStringEmptyList(self): helpstring = helputils.HelpString([]) self.assertIn('Type: list', helpstring) self.assertIn('String form: []', helpstring) self.assertIn('Length: 0', helpstring) def testHelpStringShortList(self): helpstring = helputils.HelpString([10]) self.assertIn('Type: list', helpstring) self.assertIn('String form: [10]', helpstring) self.assertIn('Length: 1', helpstring) self.assertIn('Usage: [0]', helpstring) # [] denotes optional. def testHelpStringInt(self): helpstring = helputils.HelpString(7) self.assertIn('Type: int', helpstring) self.assertIn('String form: 7', helpstring) self.assertIn('Usage: bit-length\n' ' conjugate\n' ' denominator\n', helpstring) def testHelpClassNoInit(self): helpstring = helputils.HelpString(tc.OldStyleEmpty) if six.PY2: self.assertIn('Type: classobj\n', helpstring) else: self.assertIn('Type: type\n', helpstring) self.assertIn('String form: ', helpstring) self.assertIn('fire.test_components.OldStyleEmpty', helpstring) self.assertIn('fire/test_components.py\n', helpstring) self.assertIn('Line: ', helpstring) if __name__ == '__main__': unittest.main()