(self)
| 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() |
nothing calls this directly
no test coverage detected