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