MCPcopy
hub / github.com/tornadoweb/tornado / test_subcommand

Method test_subcommand

tornado/test/options_test.py:84–105  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

82 self.assertIn("Usage:", usage)
83
84 def test_subcommand(self):
85 base_options = OptionParser()
86 base_options.define("verbose", default=False)
87 sub_options = OptionParser()
88 sub_options.define("foo", type=str)
89 rest = base_options.parse_command_line(
90 ["main.py", "--verbose", "subcommand", "--foo=bar"]
91 )
92 self.assertEqual(rest, ["subcommand", "--foo=bar"])
93 self.assertTrue(base_options.verbose)
94 rest2 = sub_options.parse_command_line(rest)
95 self.assertEqual(rest2, [])
96 self.assertEqual(sub_options.foo, "bar")
97
98 # the two option sets are distinct
99 try:
100 orig_stderr = sys.stderr
101 sys.stderr = StringIO()
102 with self.assertRaises(Error):
103 sub_options.parse_command_line(["subcommand", "--verbose"])
104 finally:
105 sys.stderr = orig_stderr
106
107 def test_setattr(self):
108 options = OptionParser()

Callers

nothing calls this directly

Calls 3

defineMethod · 0.95
parse_command_lineMethod · 0.95
OptionParserClass · 0.90

Tested by

no test coverage detected