Assert the options are what we expected when parsing arguments. Otherwise, fail with a nicely formatted message. Keyword arguments: args -- A list of arguments to parse with OptionParser. expected_opts -- The options expected. expected_positional_args -- The
(self, args, expected_opts, expected_positional_args)
| 48 | |
| 49 | class BaseTest(unittest.TestCase): |
| 50 | def assertParseOK(self, args, expected_opts, expected_positional_args): |
| 51 | """Assert the options are what we expected when parsing arguments. |
| 52 | |
| 53 | Otherwise, fail with a nicely formatted message. |
| 54 | |
| 55 | Keyword arguments: |
| 56 | args -- A list of arguments to parse with OptionParser. |
| 57 | expected_opts -- The options expected. |
| 58 | expected_positional_args -- The positional arguments expected. |
| 59 | |
| 60 | Returns the options and positional args for further testing. |
| 61 | """ |
| 62 | |
| 63 | (options, positional_args) = self.parser.parse_args(args) |
| 64 | optdict = vars(options) |
| 65 | |
| 66 | self.assertEqual(optdict, expected_opts, |
| 67 | """ |
| 68 | Options are %(optdict)s. |
| 69 | Should be %(expected_opts)s. |
| 70 | Args were %(args)s.""" % locals()) |
| 71 | |
| 72 | self.assertEqual(positional_args, expected_positional_args, |
| 73 | """ |
| 74 | Positional arguments are %(positional_args)s. |
| 75 | Should be %(expected_positional_args)s. |
| 76 | Args were %(args)s.""" % locals ()) |
| 77 | |
| 78 | return (options, positional_args) |
| 79 | |
| 80 | def assertRaises(self, |
| 81 | func, |
no test coverage detected