相关: 粉碎机/彩色#23
我正在重新实现python中的纯提示,以便它能够支持更多的shell。
然而,在测试颜色时,我得到了“未执行”的行为,即我不明白的行为。
测试输出
def test_prompt_symbol_is_colored_for_successful_command():
assert str(prompt.prompt_symbol()) == str(colors.primary('❯'))
> assert str(prompt.prompt_symbol()) == '\x1b[38;2;155;48;255m❯\x1b[39m'
E AssertionError: assert '❯' == '\x1b[38;2;155;48;255m❯\x1b[39m'
E - ❯
E + ❯ ← this one is purple_colors_test.py_
def test_prompt_symbol_is_colored_for_successful_command():
assert str(prompt.prompt_symbol()) == str(colors.primary('❯'))
assert str(prompt.prompt_symbol()) == '\x1b[38;2;155;48;255m❯\x1b[39m'我测试的对象是:
pytest -v tests/colors.py
import colorful
primary = colorful.purple1
mute = colorful.grayprompt.py
from pure import colors
def prompt_symbol(last_command_status=0):
symbol = colors.primary('❯') if last_command_status == 0 else colors.danger('❯')
return symbol问题
第一个断言成功了,而第二个断言失败了,尽管它们应该是等效的。当我否定第一个断言时,不存在转义序列:
> assert str(prompt.prompt_symbol()) != str(colors.primary('❯'))
E AssertionError: assert '❯' != '❯'
E + where '❯' = str(<colorful.core.ColorfulString object at 0x7f545276f080>)
E + where <colorful.core.ColorfulString object at 0x7f545276f080> = <function prompt_symbol at 0x7f54527b79d8>()
E + where <function prompt_symbol at 0x7f54527b79d8> = prompt.prompt_symbol
E + and '❯' = str(<colorful.core.ColorfulString object at 0x7f545276f0b8>)
E + where <colorful.core.ColorfulString object at 0x7f545276f0b8> = <colorful.core.Colorful.ColorfulStyle object at 0x7f54527c2278>('❯')
E + where <colorful.core.Colorful.ColorfulStyle object at 0x7f54527c2278> = colors.primary在python中手动执行命令给我:
>>> from pure import colors, prompt
>>> str(colors.primary('❯'))
'\x1b[38;2;155;48;255m❯\x1b[39m'
>>> str(prompt.prompt_symbol())
'\x1b[38;2;155;48;255m❯\x1b[39m'发布于 2019-02-27 20:46:19
用pytest固定
pytest -v --capture=no tests/有关详细信息,请参阅https://github.com/timofurrer/colorful/issues/23#issuecomment-468008070。
https://stackoverflow.com/questions/54884561
复制相似问题