def test_invalid_params(capsys): """ Check that invalid parameters are early and correctly detected. Arguments: capsys: Pytest fixture to capture output. """ assert cli.main( ["-d", "tests/fixtures/booleans.py", "boolean", "zore=off"]) == 1 captured = capsys.readouterr() assert "unexpected keyword argument 'zore'" in captured.err assert cli.main(["-d", "tests/fixtures/code.py", "exit_with"]) == 1 captured = capsys.readouterr() assert "missing 1 required positional argument: 'code'" in captured.err
def test_options_precedence(): """Test options precedence.""" # @duty(nofail=True) is overridden by ctx.run(nofail=False) assert cli.main(["-d", "tests/fixtures/precedence.py", "precedence"]) == 1 # ctx.run(nofail=False) is overridden by local option -z assert cli.main(["-d", "tests/fixtures/precedence.py", "precedence", "-z"]) == 0 # ctx.run(nofail=False) is overridden by global option -z assert cli.main(["-d", "tests/fixtures/precedence.py", "-z", "precedence"]) == 0 # global option -z is overridden by local option -z assert cli.main( ["-d", "tests/fixtures/precedence.py", "-z", "precedence", "-Z"]) == 1
def test_duty_failure(code): """ Check exit code. Arguments: code: Code to match. """ assert cli.main( ["-d", "tests/fixtures/code.py", "exit_with", f"code={code}"]) == code
def test_no_duty(capsys): """ Run no duties. Arguments: capsys: Pytest fixture to capture output. """ assert cli.main([]) == 1 captured = capsys.readouterr() assert "choose at least one duty" in captured.err
def test_show_help_unknown_duty(capsys): """ Show help for an unknown duty. Arguments: capsys: Pytest fixture to capture output. """ assert cli.main(["-d", "tests/fixtures/basic.py", "-h", "not-here"]) == 0 captured = capsys.readouterr() assert "Unknown duty" in captured.out
def test_show_help_for_given_duties(capsys): """ Show help for given duties. Arguments: capsys: Pytest fixture to capture output. """ assert cli.main(["-d", "tests/fixtures/basic.py", "-h", "hello"]) == 0 captured = capsys.readouterr() assert "hello" in captured.out
def test_cast_bool_parameter(param, expected): """ Test parameters casting as boolean. Arguments: param: Pytest parametrization fixture. expected: Pytest parametrization fixture. """ assert cli.main(["-d", "tests/fixtures/booleans.py", "boolean", param]) == expected
def test_show_help(capsys): """ Show help. Arguments: capsys: Pytest fixture to capture output. """ assert cli.main(["-h"]) == 0 captured = capsys.readouterr() assert "duty" in captured.out
def test_duty_arguments(capsys): # noqa: WPS218 (too many assert statements) """ Run duty with arguments. Arguments: capsys: Pytest fixture to capture output. """ assert cli.main( ["-d", "tests/fixtures/arguments.py", "say_hello", "cat=fabric"]) == 0 captured = capsys.readouterr() assert "cat fabric" in captured.out assert "dog dog" in captured.out assert cli.main([ "-d", "tests/fixtures/arguments.py", "say_hello", "dog=paramiko", "cat=invoke" ]) == 0 captured = capsys.readouterr() assert "cat invoke" in captured.out assert "dog paramiko" in captured.out
def test_list_duties(capsys): """ List duties. Arguments: capsys: Pytest fixture to capture output. """ assert cli.main(["-d", "tests/fixtures/list.py", "-l"]) == 0 captured = capsys.readouterr() assert "Tong..." in captured.out assert "DEUM!" in captured.out
def test_multiple_duties(capsys): """ Run multiple duties. Arguments: capsys: Pytest fixture to capture output. """ assert cli.main( ["-d", "tests/fixtures/multiple.py", "first_duty", "second_duty"]) == 0 captured = capsys.readouterr() assert "first" in captured.out assert "second" in captured.out
def test_incorrect_arguments(): """Use incorrect arguments.""" assert cli.main(["-d", "tests/fixtures/basic.py", "hello=1"]) == 1
def test_unknown_duty(): """Don't run an unknown duty.""" assert cli.main(["-d", "tests/fixtures/basic.py", "byebye"]) == 1
def test_select_duties(): """Run a duty.""" assert cli.main(["-d", "tests/fixtures/basic.py", "hello"]) == 0
def test_global_and_local_options(): """Test global and local options.""" assert cli.main( ["-d", "tests/fixtures/code.py", "-z", "exit_with", "-Z", "1"]) == 1
""" Entry-point module, in case you use `python -m duty`. Why does this file exist, and why `__main__`? For more info, read: - https://www.python.org/dev/peps/pep-0338/ - https://docs.python.org/3/using/cmdline.html#cmdoption-m """ import sys from duty.cli import main if __name__ == "__main__": sys.exit(main(sys.argv[1:]))