コード例 #1
0
def test_invalid_input(monkeypatch, capsys):
    monkeypatch.setattr("sys.stdin", StringIO("abcd\n\n"))
    solution.collect_places()
    captured_out, captured_err = capsys.readouterr()
    err_str = "Tell me where you went: That's not a legal city, country combination"
    assert captured_out.strip().startswith(err_str)
    assert captured_out.strip().endswith("Tell me where you went:")
コード例 #2
0
def test_counting(monkeypatch, capsys):
    monkeypatch.setattr("sys.stdin", StringIO(shanghai_bj_bj))
    solution.collect_places()
    captured_out, captured_err = capsys.readouterr()
    assert len(solution.visits["China"]) == 2

    solution.display_places()
    captured_out, captured_err = capsys.readouterr()
    assert "Beijing (2)" in captured_out
    assert "Shanghai" in captured_out
コード例 #3
0
def test_sorting_cities(monkeypatch, capsys):
    monkeypatch.setattr("sys.stdin", StringIO(shanghai_bj_bj))
    solution.collect_places()
    captured_out, captured_err = capsys.readouterr()

    solution.display_places()
    captured_out, captured_err = capsys.readouterr()
    beijing_index = captured_out.index("Beijing")
    shanghai_index = captured_out.index("Shanghai")
    assert beijing_index < shanghai_index
コード例 #4
0
def test_sorting_countries(monkeypatch, capsys):
    monkeypatch.setattr("sys.stdin", StringIO(haifa_london_nyc))
    solution.collect_places()
    captured_out, captured_err = capsys.readouterr()

    solution.display_places()
    captured_out, captured_err = capsys.readouterr()
    israel_index = captured_out.index("Israel")
    england_index = captured_out.index("England")
    usa_index = captured_out.index("USA")
    assert england_index < israel_index
    assert israel_index < usa_index
コード例 #5
0
def test_many_places(monkeypatch):
    monkeypatch.setattr("sys.stdin", StringIO(many_place_inputs))
    solution.collect_places()
    assert len(solution.visits) == 3
コード例 #6
0
def test_no_places(monkeypatch):
    monkeypatch.setattr("sys.stdin", StringIO("\n"))
    solution.collect_places()
    assert len(solution.visits) == 0