コード例 #1
0
def test_default_boolean_input(monkeypatch: MonkeyPatch) -> None:
    monkeypatch.setattr("sys.stdin", io.StringIO("\n"))
    assert quickstart.input_or_default("Hello", "N", quickstart.boolean) is False
コード例 #2
0
def test_bad_then_good_boolean_input_false(monkeypatch: MonkeyPatch) -> None:
    monkeypatch.setattr("sys.stdin", io.StringIO("pouette\nn"))
    assert quickstart.input_or_default("Hello", "N", quickstart.boolean) is False
コード例 #3
0
def test_2nd_time(monkeypatch: MonkeyPatch) -> None:
    monkeypatch.setattr("sys.stdin", io.StringIO("youpi\nyes"))
    assert quickstart.input_or_default("Say yes?", validator=quickstart.boolean) is True
コード例 #4
0
def test_invalid_default_value() -> None:
    with pytest.raises(ValueError):
        quickstart.input_or_default(
            "Give a bool", "not a bool", validator=quickstart.boolean
        )
コード例 #5
0
def test_input(monkeypatch: MonkeyPatch) -> None:
    monkeypatch.setattr("sys.stdin", io.StringIO("youpi"))
    assert quickstart.input_or_default("Say youpi?") == "youpi"