예제 #1
0
 def test_okOptType(self):
     """valid option types"""
     for typ in bool, str, int, all:
         with self.subTest(i=typ):
             parse({
                 "s": ("schmooze", typ, 0, "schmooziness"),
             }, [])
예제 #2
0
 def test_Invalid_Keyword(self):
     """invalid keyword"""
     with self.assertRaises(AssertionError):
         parse({
             "s": ("schmooze", bool, 0, "increase schmooziness"),
             "__arguments": ["file1", "...", "destination"],
         }, ["bla", "blubb"])
예제 #3
0
 def test_invOptType(self):
     """invalid option types"""
     for typ in float, "dudi", 3:
         with self.subTest(i=typ):
             with self.assertRaises(AssertionError):
                 parse({
                     "s": ("schmooze", typ, 0, "schmooziness"),
                 }, [])
예제 #4
0
 def test_Valid_Keyword(self):
     """valid keyword"""
     given_args = ["bla", "blubb"]
     ovc, args = parse({
         "s": ("schmooze", bool, 0, "increase schmooziness"),
         "_arguments": ["file1", "...", "destination"],
     }, given_args)
     self.assertEqual(args, given_args)
예제 #5
0
 def test_usage_empty_string_arguments(self):
     """_arguments as string"""
     ovc, args = parse({
         "v": ("verbose", bool, 0, "increase verbosity"),
         "_arguments": "",
         "_program": "lala",
     })
     self.assertEqual(ovc.ovc_usage_msg(), "usage: lala [-v]")
예제 #6
0
 def test_usage_short2(self):
     """own usage option 2"""
     ovc, args = parse(
         {
             "v": ("verbose", bool, 1, "increase verbosity"),
             "?": ("usage", int, 2, "opposite of overly"),
             "_arguments": [],
         }, ["-v"],
         exit_on_error=False)
     self.assertEqual(ovc.ovc_values(), dict(verbose=2, usage=2))
예제 #7
0
 def test_help_bool(self):
     """-h/--help option"""
     ovc, args = parse(
         {
             "v": ("verbose", bool, 1, "increase verbosity"),
             "h": ("own_help", bool, 1, "number of hounds"),
             "_arguments": [],
         }, ["-v", "--own-help"],
         exit_on_error=False)
     self.assertEqual(ovc.ovc_values(), dict(verbose=2, own_help=2))
예제 #8
0
 def test_help_def(self):
     """-h/--help default"""
     ovc, args = parse(
         {
             "v": ("verbose", bool, 1, "increase verbosity"),
             "h": ("help", int, 1, "number of hounds"),
             "_arguments": [],
         }, ["-v"],
         exit_on_error=False)
     self.assertEqual(ovc.ovc_values(), dict(verbose=2, help=1))
예제 #9
0
 def test_hounds(self):
     """-h/--hounds option"""
     ovc, args = parse(
         {
             "v": ("verbose", bool, 1, "increase verbosity"),
             "h": ("hounds", int, 1, "number of hounds"),
             "_arguments": [],
         }, ["-vh5"],
         exit_on_error=False)
     self.assertEqual(ovc.ovc_values(), dict(verbose=2, hounds=5))
예제 #10
0
 def test_help_func(self):
     """call help function"""
     ovc, args = parse(
         {
             "v": ("verbose", bool, 1, "increase verbosity"),
             "?": ("help", my_help, None, "number of hounds"),
             "_arguments": [],
         }, ["-v", "--help"],
         exit_on_error=False)
     self.assertEqual(ovc.ovc_values(), dict(verbose=2, help=6))
     self.assertTrue(help_called)
예제 #11
0
 def test_usage0(self):
     """-h/--hounds option"""
     ovc, args = parse(
         {
             "v": ("verbose", bool, 1, "increase verbosity"),
             "z": ("zounds", int, 1, "number of zounds"),
             "_arguments": [],
         }, ["-v"],
         exit_on_error=False)
     self.assertEqual(ovc.ovc_usage_msg(),
                      "usage: {} [-vz]".format(ovc._program))
예제 #12
0
 def test_usage_program(self):
     """-h/--hounds option"""
     ovc, args = parse(
         {
             "v": ("verbose", bool, 1, "increase verbosity"),
             "z": ("zounds", int, 1, "number of zounds"),
             "_arguments": ["mangia", "[file1 ...]"],
             "_program": "schnörkelate",
         }, ["-v", "foo!"],
         exit_on_error=False)
     self.assertEqual(ovc.ovc_usage_msg(),
                      "usage: schnörkelate [-vz] mangia [file1 ...]")
예제 #13
0
 def test_usage_own(self):
     """-h/--hounds option"""
     ovc, args = parse(
         {
             "v": ("verbose", bool, 1, "increase verbosity"),
             "z": ("zounds", int, 1, "number of zounds"),
             "_arguments": ["mangia", "[file1 ...]"],
             "_usage": "usage: gniddle [-v] [-z 5] mangia [file1 ...]"
         }, ["-v", "foo!"],
         exit_on_error=False)
     self.assertEqual(ovc.ovc_usage_msg(),
                      "usage: gniddle [-v] [-z 5] mangia [file1 ...]")
예제 #14
0
    def test_usage1(self):
        """test usage output 0 args, to err, other exit status"""
        ovc, args = parse(
            {
                "v": ("verbose", bool, 1, "increase verbosity"),
                "z": ("zounds", int, 1, "number of zounds"),
                "_arguments": [],
            }, ["-v"])
        with outputAndExitCaptured() as (out, err, status):
            ovc.ovc_usage(exit_status=63)
        self.assertEqual(out.getvalue(), "")
        self.assertEqual(
            err.getvalue().rstrip(), """usage: {} [-vz]
use '-?' option to get more help""".format(ovc._program))
        self.assertEqual(status.value, 63)
예제 #15
0
    def test_usage5(self):
        """test usage output 3 args, to stdout, no message"""
        ovc, args = parse(
            {
                "v": ("verbose", bool, 1, "increase verbosity"),
                "z": ("zounds", int, 1, "number of zounds"),
                "_arguments": ["1", "2", "drei"],
            }, ["-v", "hahaha", "hihihi", "hohoho"])
        with outputAndExitCaptured() as (out, err, status):
            ovc.ovc_usage(exit_status=0)
        self.assertEqual(err.getvalue(), "")
        self.assertEqual(
            out.getvalue().rstrip(), """usage: {} [-vz] 1 2 drei
use '-?' option to get more help""".format(ovc._program))
        self.assertEqual(status.value, 0)
예제 #16
0
    def test_called_help(self):
        """Test called ovc_help()."""
        with outputAndExitCaptured() as (out, err, status):
            ovc, args = parse(
                {
                    # opt: (name,        type, default value, helptext[, arg name])
                    "s": ("schmooze", bool, 0, "more schmooziness"),
                    "o": ("output_file", str, None, "output file (or stdout)",
                          "NAME"),
                    "n": ("repetitions", int, 3, "number of repetitions"),
                    "d": ("debug", str, [], "debug topics", "DEBUG_TOPIC"),
                    # keyword:        value
                    "_arguments": ["string_to_print", "..."],
                    "_help_header":
                    "print a string a number of times",
                    "_help_footer":
                    "This is just an example program.",
                    "_program":
                    "schmooze",
                },
                ["narg"],
                exit_on_error=False)
            ovc.ovc_help()
        self.assertEqual(err.getvalue(), "")
        self.assertEqual(status.value, 0)
        self.assertEqual(
            out.getvalue(), """\
usage: schmooze [-ns] [-o NAME] [-d DEBUG_TOPIC] string_to_print ...
print a string a number of times

 -?, --help:
    show help on options and things
 -d, --debug DEBUG_TOPIC:
    debug topics (str arg, default [])
 -h, --help:
    show help on options and things
 -n, --repetitions ARG:
    number of repetitions (int arg, default 3)
 -o, --output-file NAME:
    output file (or stdout) (str arg, default None)
 -s, --schmooze:
    more schmooziness

This is just an example program.
""")
예제 #17
0
    def test_help_msg(self):
        """Test help message."""
        ovc, args = parse(
            {
                # opt: (name,        type, default value, helptext[, arg name])
                "s": ("schmooze", bool, 0, "more schmooziness"),
                "o":
                ("output_file", str, None, "output file (or stdout)", "NAME"),
                "n": ("repetitions", int, 3, "number of repetitions"),
                "d": ("debug", str, [], "debug topics", "DEBUG_TOPIC"),
                # keyword:        value
                "_arguments": ["string_to_print", "..."],
                "_help_header": "print a string a number of times",
                "_help_footer": "This is just an example program.",
                "_program": "schmooze",
            },
            ["gnaddel"])
        self.assertEqual(
            ovc.ovc_help_msg(), """\
usage: schmooze [-ns] [-o NAME] [-d DEBUG_TOPIC] string_to_print ...
print a string a number of times

 -?, --help:
    show help on options and things
 -d, --debug DEBUG_TOPIC:
    debug topics (str arg, default [])
 -h, --help:
    show help on options and things
 -n, --repetitions ARG:
    number of repetitions (int arg, default 3)
 -o, --output-file NAME:
    output file (or stdout) (str arg, default None)
 -s, --schmooze:
    more schmooziness

This is just an example program.""")
예제 #18
0
 def test_emptyDesc(self):
     """does it work without any options or keywords?"""
     ovc, args = parse({}, [], exit_on_error=False)
     self.assertEqual(ovc.ovc_values(), {})
     self.assertEqual(args, [])
예제 #19
0
 def test_emptyOpts(self):
     """does it work without any options but _arguments?"""
     ovc, args = parse({"_arguments": "arg1 ..."}, [], exit_on_error=False)
     self.assertEqual(ovc.ovc_values(), {})
     self.assertEqual(args, [])
예제 #20
0
 def test_shortDesc(self):
     """short option descriptor"""
     with self.assertRaises(AssertionError):
         parse({
             "s": ("schmooze", bool, 0),
         }, [])
예제 #21
0
 def test_Long_Key(self):
     """option key too long"""
     with self.assertRaises(AssertionError):
         parse({
             "sc": ("schmooze", bool, 0, "increase schmooziness"),
         }, [])
예제 #22
0
 def test_NameType(self):
     """invalid option name type"""
     with self.assertRaises(AssertionError):
         parse({
             "s": (12, bool, 0, "increase schmooziness"),
         }, [])
예제 #23
0
 def test_DescType(self):
     """invalid descriptor type"""
     with self.assertRaises(AssertionError):
         parse({
             "s": 17,
         }, [])
예제 #24
0
 def test_longDesc(self):
     """long option descriptor"""
     with self.assertRaises(AssertionError):
         parse({
             "s": ("schmooze", bool, 0, "huhu", "huhu", "huhu"),
         }, [])