Exemplo n.º 1
0
    def test_get_usage(self):
        cli = CLI(
            application_name=u("spam"),
            positionals=[String(metavar=u("foo"))]
        )
        self.assert_equal(cli.get_usage(), u("spam [-h] foo"))

        cli.usage = u("blubb")
        self.assert_equal(cli.get_usage(), u("blubb"))
Exemplo n.º 2
0
 def test_help_option(self):
     stringio = StringIO()
     cli = CLI(application_name=u("app"), stdout=stringio, width=40)
     try:
         cli.run(["-h"])
     except SystemExit:
         pass
     self.assert_equal(
         stringio.getvalue(),
         u(
             "Usage: app [-h]\n"
             "\n"
             "Options\n"
             "  -h, --help   Show this message\n"
         )
     )
Exemplo n.º 3
0
 def test_print_usage(self):
     stringio = StringIO()
     cli = CLI(
         usage=(u("foobarbaz ") * 10).strip(),
         width=40,
         stdout=stringio
     )
     cli.print_usage()
     self.assert_equal(
         stringio.getvalue(), u(
             "Usage: foobarbaz foobarbaz foobarbaz\n"
             "       foobarbaz foobarbaz foobarbaz\n"
             "       foobarbaz foobarbaz foobarbaz\n"
             "       foobarbaz\n"
         )
     )
Exemplo n.º 4
0
    def test_print_help(self):
        stringio = StringIO()
        cli = CLI(
            application_name=u("app"),
            stdout=stringio,
            width=40,
            positionals=[String(metavar=u("foo"))]
        )
        cli.print_help()
        self.assert_equal(stringio.getvalue(), u(
            "Usage: app [-h] foo\n"
            "\n"
            "Positional Arguments\n"
            "  foo\n"
            "\n"
            "Options\n"
            "  -h, --help   Show this message\n"
        ))

        cli.stdout = stringio = StringIO()
        cli.add_option("bar", Option("-a", String()))
        cli.print_help()
        self.assert_equal(stringio.getvalue(), u(
            "Usage: app [-h] [-a bar] foo\n"
            "\n"
            "Positional Arguments\n"
            "  foo\n"
            "\n"
            "Options\n"
            "  -h, --help   Show this message\n"
            "  -a bar\n"
        ))

        cli.stdout = stringio = StringIO()
        cli.add_command("baz", Command())
        cli.add_command("spam", Command())
        cli.print_help()
        self.assert_equal(stringio.getvalue() , u(
            "Usage: app [-h] [-a bar] {baz,spam} foo\n"
            "\n"
            "Positional Arguments\n"
            "  foo\n"
            "\n"
            "Options\n"
            "  -h, --help   Show this message\n"
            "  -a bar\n"
            "\n"
            "Commands\n"
            "  baz [-h]\n"
            "  spam [-h]\n"
        ))