コード例 #1
0
def test_no_datasets_avail(capsys, mocker, aocd_dir):
    datasets_file = aocd_dir / "tokens.json"
    datasets_file.write_text("{}")
    mocker.patch("sys.argv", ["aoc"])
    msg = ("There are no datasets available to use.\n"
           "Either export your AOC_SESSION or put some auth tokens into {}\n".
           format(datasets_file))
    with pytest.raises(SystemExit(1)):
        main()
    out, err = capsys.readouterr()
    assert msg in err
コード例 #2
0
def test_no_plugins_avail(capsys, mocker):
    mock = mocker.patch("pkg_resources.iter_entry_points", return_value=iter([]))
    mocker.patch("sys.argv", ["aoc"])
    msg = (
        "There are no plugins available. Install some package(s) with a registered 'adventofcode.user' entry-point.\n"
        "See https://github.com/wimglenn/advent-of-code-sample for an example plugin package structure.\n"
    )
    with pytest.raises(SystemExit(1)):
        main()
    out, err = capsys.readouterr()
    assert msg in err
    mock.assert_called_once_with(group="adventofcode.user")
コード例 #3
0
def test_main(capsys, mocker, aocd_dir):
    mock = mocker.patch("aocd.runner.run_for")
    ep1 = mocker.Mock()
    ep1.name = "user1"
    ep2 = mocker.Mock()
    ep2.name = "user2"
    mocker.patch("pkg_resources.iter_entry_points", return_value=iter([ep1, ep2]))
    datasets_file = aocd_dir / "tokens.json"
    datasets_file.write_text('{"data1": "token1", "data2": "token2"}')
    mocker.patch("sys.argv", ["aoc", "--years=2015", "--days", "3", "7"])
    main()
    mock.assert_called_once_with(
        plugins=["user1", "user2"],
        years=[2015],
        days=[3, 7],
        datasets={"data1": "token1", "data2": "token2"},
        timeout=60,
    )