mirror of
https://github.com/httpie/cli.git
synced 2024-11-29 11:13:28 +01:00
a3a08a9a22
* Use relative imports in test * Use relative imports * Add myself to contributors :)
33 lines
896 B
Python
33 lines
896 B
Python
from typing import Iterable
|
|
|
|
import pytest
|
|
|
|
from .parsing import OutputMatchingError, expect_tokens, Expect
|
|
|
|
|
|
__all__ = [
|
|
'assert_output_matches',
|
|
'assert_output_does_not_match',
|
|
'Expect',
|
|
]
|
|
|
|
|
|
def assert_output_matches(output: str, tokens: Iterable[Expect]):
|
|
r"""
|
|
Check the command `output` for an exact full sequence of `tokens`.
|
|
|
|
>>> out = 'GET / HTTP/1.1\r\nAAA:BBB\r\n\r\nCCC\n\n'
|
|
>>> assert_output_matches(out, [Expect.REQUEST_HEADERS, Expect.BODY, Expect.SEPARATOR])
|
|
|
|
"""
|
|
# TODO: auto-remove ansi colors to allow for testing of colorized output as well.
|
|
expect_tokens(tokens=tokens, s=output)
|
|
|
|
|
|
def assert_output_does_not_match(output: str, tokens: Iterable[Expect]):
|
|
r"""
|
|
>>> assert_output_does_not_match('\r\n', [Expect.BODY])
|
|
"""
|
|
with pytest.raises(OutputMatchingError):
|
|
assert_output_matches(output=output, tokens=tokens)
|