コード例 #1
0
def test_printer_counts():
    p = Printer()
    text = "This is a test."
    for i in range(2):
        p.good(text)
    for i in range(1):
        p.fail(text)
    for i in range(4):
        p.warn(text)
    assert p.counts[MESSAGES.GOOD] == 2
    assert p.counts[MESSAGES.FAIL] == 1
    assert p.counts[MESSAGES.WARN] == 4
コード例 #2
0
def test_printer():
    p = Printer(no_print=True)
    text = "This is a test."
    if supports_ansi():
        assert p.good(text) == "\x1b[38;5;2m\u2714 This is a test.\x1b[0m"
        assert p.fail(text) == "\x1b[38;5;1m\u2718 This is a test.\x1b[0m"
        assert p.warn(text) == "\x1b[38;5;3m\u26a0 This is a test.\x1b[0m"
        assert p.info(text) == "\x1b[38;5;4m\u2139 This is a test.\x1b[0m"
        assert p.text(text) == text
    else:
        assert p.good(text) == text
        assert p.fail(text) == text
        assert p.warn(text) == text
        assert p.info(text) == text
        assert p.text(text) == text
コード例 #3
0
def test_printer():
    p = Printer(no_print=True)
    text = "This is a test."
    good = p.good(text)
    fail = p.fail(text)
    warn = p.warn(text)
    info = p.info(text)
    assert p.text(text) == text
    if SUPPORTS_ANSI and not NO_UTF8:
        assert good == "\x1b[38;5;2m\u2714 {}\x1b[0m".format(text)
        assert fail == "\x1b[38;5;1m\u2718 {}\x1b[0m".format(text)
        assert warn == "\x1b[38;5;3m\u26a0 {}\x1b[0m".format(text)
        assert info == "\x1b[38;5;4m\u2139 {}\x1b[0m".format(text)
    if SUPPORTS_ANSI and NO_UTF8:
        assert good == "\x1b[38;5;2m[+] {}\x1b[0m".format(text)
        assert fail == "\x1b[38;5;1m[x] {}\x1b[0m".format(text)
        assert warn == "\x1b[38;5;3m[!] {}\x1b[0m".format(text)
        assert info == "\x1b[38;5;4m[i] {}\x1b[0m".format(text)
    if not SUPPORTS_ANSI and not NO_UTF8:
        assert good == "\u2714 {}".format(text)
        assert fail == "\u2718 {}".format(text)
        assert warn == "\u26a0 {}".format(text)
        assert info == "\u2139 {}".format(text)
    if not SUPPORTS_ANSI and NO_UTF8:
        assert good == "[+] {}".format(text)
        assert fail == "[x] {}".format(text)
        assert warn == "[!] {}".format(text)
        assert info == "[i] {}".format(text)
コード例 #4
0
def test_printer_no_pretty():
    p = Printer(no_print=True, pretty=False)
    text = "This is a test."
    assert p.good(text) == text
    assert p.fail(text) == text
    assert p.warn(text) == text
    assert p.info(text) == text
    assert p.text(text) == text
コード例 #5
0
def test_printer_custom():
    colors = {"yellow": 220, "purple": 99}
    icons = {"warn": "\u26a0\ufe0f", "question": "?"}
    p = Printer(no_print=True, colors=colors, icons=icons)
    text = "This is a test."
    purple_question = p.text(text, color="purple", icon="question")
    warning = p.warn(text)
    if supports_ansi():
        assert purple_question == "\x1b[38;5;99m? This is a test.\x1b[0m"
        assert warning == "\x1b[38;5;3m\u26a0\ufe0f This is a test.\x1b[0m"
    else:
        assert purple_question == "{} {}".format(icons["question"], text)
        assert warning == text
コード例 #6
0
def test_printer_custom():
    colors = {"yellow": 220, "purple": 99}
    icons = {"warn": "\u26a0\ufe0f", "question": "?"}
    p = Printer(no_print=True, colors=colors, icons=icons)
    text = "This is a test."
    purple_question = p.text(text, color="purple", icon="question")
    warning = p.warn(text)
    if SUPPORTS_ANSI and not NO_UTF8:
        assert purple_question == "\x1b[38;5;99m? {}\x1b[0m".format(text)
        assert warning == "\x1b[38;5;3m\u26a0\ufe0f {}\x1b[0m".format(text)
    if SUPPORTS_ANSI and NO_UTF8:
        assert purple_question == "\x1b[38;5;99m? {}\x1b[0m".format(text)
        assert warning == "\x1b[38;5;3m?? {}\x1b[0m".format(text)
    if not SUPPORTS_ANSI and not NO_UTF8:
        assert purple_question == "? {}".format(text)
        assert warning == "\u26a0\ufe0f {}".format(text)
    if not SUPPORTS_ANSI and NO_UTF8:
        assert purple_question == "? {}".format(text)
        assert warning == "?? {}".format(text)