Ejemplo n.º 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:")
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 5
0
def test_many_places(monkeypatch):
    monkeypatch.setattr("sys.stdin", StringIO(many_place_inputs))
    solution.collect_places()
    assert len(solution.visits) == 3
Ejemplo n.º 6
0
def test_no_places(monkeypatch):
    monkeypatch.setattr("sys.stdin", StringIO("\n"))
    solution.collect_places()
    assert len(solution.visits) == 0