Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tests/terminal_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

"""Unittest for terminal module."""

import contextlib
import io
import sys
import unittest

Expand Down Expand Up @@ -240,5 +242,16 @@ def testBlankLines(self):
buffer.splitlines())



class UnitTestMain(unittest.TestCase):

def testHelp(self):
out = io.StringIO()
with contextlib.redirect_stdout(out):
self.assertEqual(0, terminal.main(['terminal', '--help']))
self.assertIn('terminal [--help] [--size] [--nodelay] [input_file]',
out.getvalue())


if __name__ == '__main__':
unittest.main()
13 changes: 13 additions & 0 deletions tests/textfsm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

"""Unittest for textfsm module."""

import contextlib
import io
import unittest

Expand Down Expand Up @@ -1011,5 +1012,17 @@ def testTemplateValue(self):
self.assertEqual(str(t), buf_result)



class UnitTestMain(unittest.TestCase):

def testHelp(self):
out = io.StringIO()
with contextlib.redirect_stdout(out):
self.assertEqual(0, textfsm.parser.main(['textfsm', '--help']))
self.assertIn(
'textfsm [--help] template [input_file [output_file]]', out.getvalue()
)


if __name__ == '__main__':
unittest.main()
3 changes: 2 additions & 1 deletion textfsm/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,8 @@ def main(argv=None):
if argv is None:
argv = sys.argv

help_msg = '%s [--help] template [input_file [output_file]]\n' % argv[0]

try:
opts, args = getopt.getopt(argv[1:], 'h', ['help'])
except getopt.error as exc:
Expand Down Expand Up @@ -1133,7 +1135,6 @@ def main(argv=None):


if __name__ == '__main__':
help_msg = '%s [--help] template [input_file [output_file]]\n' % sys.argv[0]
try:
sys.exit(main())
except UsageError as err:
Expand Down
3 changes: 2 additions & 1 deletion textfsm/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,8 @@ def main(argv=None):
if argv is None:
argv = sys.argv

help_msg = '%s [--help] [--size] [--nodelay] [input_file]\n' % argv[0]

try:
opts, args = getopt.getopt(argv[1:], 'dhs', ['nodelay', 'help', 'size'])
except getopt.error as exc:
Expand Down Expand Up @@ -543,7 +545,6 @@ def main(argv=None):


if __name__ == '__main__':
help_msg = '%s [--help] [--size] [--nodelay] [input_file]\n' % sys.argv[0]
try:
sys.exit(main())
except UsageError as err:
Expand Down
Loading