Exemple #1
0
def test_default_help_for_subcommand():
    # Arrange.
    @cli
    def main():
        pass

    @main.command
    def sub():
        pass

    # Act.
    _, out_a = execute(cli, '--help', redirect_stdout)
    _, out_b = execute(cli, 'sub --help', redirect_stdout)

    # Assert.
    assert out_a.startswith('usage: main')
    assert out_b.startswith('usage: main sub')
Exemple #2
0
def test_flag_with_two_trailing_underscores():
    # Arrange.
    @cli
    def main(x__: Flag):
        return x__

    # Act.
    cx = execute(cli, '--x')

    # Assert.
    assert cx is True
Exemple #3
0
def test_two_flags_with_same_prefix():
    # Arrange.
    @cli
    def main(x: Flag(prefix='+'), y: Flag(prefix='+')):
        return x, y

    # Act.
    cx = execute(cli, '++x ++y')

    # Assert.
    assert cx == (True, True)
Exemple #4
0
def test_flag_with_letter_prefix():
    # Arrange.
    @cli
    def main(x: Flag(prefix='a')):
        return x

    # Act.
    cx = execute(cli, 'aax')

    # Assert.
    assert cx is True
Exemple #5
0
def test_flag_with_custom_but_default_prefix():
    # Arrange.
    @cli
    def main(x: Flag(prefix='-')):
        return x

    # Act.
    cx = execute(cli, '--x')

    # Assert.
    assert cx is True
Exemple #6
0
def test_flag_with_custom_prefix_and_short():
    # Arrange.
    @cli
    def main(xyz: Flag(short='x', prefix='+')):
        return xyz

    # Act.
    cx = execute(cli, '+x')

    # Assert.
    assert cx is True
Exemple #7
0
def test_flag_specified_twice():
    # Arrange.
    @cli
    def main(x: Flag):
        return x

    # Act.
    cx = execute(cli, '--x --x')

    # Assert.
    assert cx is True