OLD | NEW |
(Empty) | |
| 1 # Copyright 2014 Dirk Pranke. All rights reserved. |
| 2 # |
| 3 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 # you may not use this file except in compliance with the License. |
| 5 # You may obtain a copy of the License at |
| 6 # |
| 7 # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 # |
| 9 # Unless required by applicable law or agreed to in writing, software |
| 10 # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 # See the License for the specific language governing permissions and |
| 13 # limitations under the License. |
| 14 |
| 15 import optparse |
| 16 import unittest |
| 17 |
| 18 from typ import ArgumentParser |
| 19 |
| 20 |
| 21 class ArgumentParserTest(unittest.TestCase): |
| 22 |
| 23 def test_optparse_options(self): |
| 24 parser = optparse.OptionParser() |
| 25 ArgumentParser.add_option_group(parser, 'foo', |
| 26 discovery=True, |
| 27 running=True, |
| 28 reporting=True, |
| 29 skip='[-d]') |
| 30 options, _ = parser.parse_args(['-j', '1']) |
| 31 self.assertEqual(options.jobs, 1) |
| 32 |
| 33 def test_argv_from_args(self): |
| 34 |
| 35 def check(argv, expected=None): |
| 36 parser = ArgumentParser() |
| 37 args = parser.parse_args(argv) |
| 38 actual_argv = parser.argv_from_args(args) |
| 39 expected = expected or argv |
| 40 self.assertEqual(expected, actual_argv) |
| 41 |
| 42 check(['--version']) |
| 43 check(['--coverage', '--coverage-omit', 'foo']) |
| 44 check(['--jobs', '3']) |
| 45 check(['-vv'], ['--verbose', '--verbose']) |
OLD | NEW |