Ejemplo n.º 1
0
    def test_good_options(self):
        mod_args = args.ModuleArgs('test args', 'test')
        mod_args.add_option('test', default="", type=str, help="no", dest="test")
        mod_args.add_option('other', default="x", type=str, help="no", dest="test_other")
        parser = args.AntismashParser(parents=[mod_args])
        options = parser.parse_args(["--test", "thing"])
        assert options.test_other == "x"
        assert options.test == "thing"
        options = parser.parse_args(["--test", "1", "--test-other", "y"])
        assert options.test == "1"
        assert options.test_other == "y"

        mod_args = args.ModuleArgs('test', 't2pks')
Ejemplo n.º 2
0
 def test_bad_option_names(self):
     mod_args = args.ModuleArgs('test args', 'test')
     mod_args.add_option('--test',
                         default="",
                         type=str,
                         help="no",
                         dest="test")
     with self.assertRaisesRegex(
             ArgumentError,
             "argument --test: conflicting option string: --test"):
         mod_args.add_option('--test',
                             default="",
                             type=str,
                             help="no",
                             dest="test")
Ejemplo n.º 3
0
    def test_bad_values(self):
        with self.assertRaisesRegex(ValueError,
                                    "Argument prefixes must be alphanumeric"):
            mod_args = args.ModuleArgs('test options', 'prefix-has-dash')
        with self.assertRaisesRegex(
                ValueError, "Argument prefixes cannot start with numbers"):
            mod_args = args.ModuleArgs('test options', '2prefix')
        with self.assertRaisesRegex(TypeError,
                                    "Argument prefix must be a string"):
            mod_args = args.ModuleArgs('test options', 7)
        with self.assertRaisesRegex(
                ValueError, "Argument prefixes must be at least 2 chars"):
            args.ModuleArgs('test options', '')
        with self.assertRaisesRegex(ValueError,
                                    "Argument group must have a title"):
            args.ModuleArgs('', 'prefix')
        mod_args = args.ModuleArgs('test args', 'test')
        with self.assertRaisesRegex(ValueError, "Options must have a name"):
            mod_args.add_option('',
                                dest='some_place',
                                type=int,
                                default=0,
                                help="help")

        with self.assertRaisesRegex(
                ValueError, "Destination for option cannot contain hyphens"):
            mod_args.add_option('name',
                                dest='some-place',
                                type=int,
                                default=0,
                                help="help")
        with self.assertRaisesRegex(ValueError,
                                    "Arguments must have a default"):
            mod_args.add_option('name',
                                dest='some-place',
                                type=int,
                                help="help")
        with self.assertRaisesRegex(ValueError, "Arguments must have a type"):
            mod_args.add_option('name',
                                dest='some-place',
                                default="",
                                help="help")
        with self.assertRaisesRegex(ValueError, "Arguments must have a help"):
            mod_args.add_option('name',
                                dest='some-place',
                                default="",
                                type=str)
        with self.assertRaisesRegex(ValueError,
                                    "Arguments must have a destination"):
            mod_args.add_option('name', help='help', default="", type=str)