コード例 #1
0
def test_handle_args_validation(args, expected):
    output_file = mock.MagicMock(__enter__=devnull())
    main = mock.MagicMock(return_value="")
    with mock.patch("sigprobs.output_file", output_file):
        with mock.patch("sigprobs.main", main):
            with pytest.raises(expected):
                sigprobs.handle_args(args)
コード例 #2
0
def test_handle_args(cliargs, margs, ofargs):
    output_file = mock.MagicMock(__enter__=devnull())
    main = mock.MagicMock(return_value="")
    with mock.patch("sigprobs.output_file", output_file):
        with mock.patch("sigprobs.main", main):
            sigprobs.handle_args(cliargs)

    assert output_file.call_args_list == ofargs
    assert main.call_args_list == margs
コード例 #3
0
def test_handle_args_input_validation(args, data, expected, tmp_path):
    path = tmp_path / "data.json"
    with path.open("w") as f:
        json.dump(data, f)

    args = [arg % dict(path=str(path)) for arg in args]
    output_file = mock.MagicMock(__enter__=devnull())
    main = mock.MagicMock(return_value="")
    with mock.patch("sigprobs.output_file", output_file):
        with mock.patch("sigprobs.main", main):
            with pytest.raises(expected):
                sigprobs.handle_args(args)
コード例 #4
0
def test_handle_args_input(tmp_path, data):
    path = tmp_path / "data.json"
    with path.open("w") as f:
        json.dump(data, f)
    cliargs, kwargs, ofargs = (
        ["en.wikipedia.org", "--input", str(path)],
        {"days": 30, "checks": Checks.DEFAULT, "data": data},
        ("", "en.wikipedia.org", True),
    )
    output_file = mock.MagicMock(__enter__=devnull())
    main = mock.MagicMock(return_value="")
    with mock.patch("sigprobs.output_file", output_file):
        with mock.patch("sigprobs.main", main):
            sigprobs.handle_args(cliargs)

    output_file.assert_called_with(*ofargs)
    main.assert_called_with("en.wikipedia.org", **kwargs)