示例#1
0
def test_print(monkeypatch):
    mock = Mock(return_value=None)
    monkeypatch.setattr(DummyOutput, "write", mock)

    print_formatted_text("Hello World", output=DummyOutput())

    mock.assert_has_calls([call("Hello World"), call("\r\n")])
示例#2
0
def test_print_with_style(monkeypatch):
    mock = Mock(return_value=None)
    monkeypatch.setattr(DummyOutput, "write", mock.write)
    monkeypatch.setattr(DummyOutput, "set_attributes", mock.set_attributes)

    print_formatted_text("Hello World",
                         style="bold italic fg:darkred",
                         output=DummyOutput())

    assert len(mock.method_calls) == 4
    assert mock.method_calls[0][0] == "set_attributes"
    assert mock.method_calls[0][1][0] == Attrs(
        color="8b0000",
        bgcolor="",
        bold=True,
        underline=False,
        italic=True,
        blink=False,
        reverse=False,
        hidden=False,
    )

    assert mock.method_calls[1][0] == "write"
    assert mock.method_calls[1][1][0] == "Hello World"