1
0
mirror of https://github.com/httpie/cli.git synced 2025-08-10 22:42:05 +02:00

Fix time elapsed (#1277)

* Show the actual time elapsed; add docs

* `requests.Response._headers_parsed_at` → `requests.Response._httpie_headers_parsed_at`

* Add `ELAPSED_TIME_LABEL` constant

* Tweak docs

* Tweak docs

* Allow multiple blank lines in Markdown files

* Add rudimentary tests for --meta with different --style’s

* Cleanup tests

* Cleanup tests

* Cleanup tests
This commit is contained in:
Jakub Roztocil
2022-01-23 13:52:38 +01:00
committed by GitHub
parent 8a03b7a824
commit c815e21ef9
10 changed files with 105 additions and 61 deletions

View File

@@ -1,7 +1,17 @@
from .utils import http
import pytest
from httpie.models import ELAPSED_TIME_LABEL
from httpie.output.formatters.colors import PIE_STYLE_NAMES
from .utils import http, MockEnvironment, COLOR
def test_meta_elapsed_time(httpbin, monkeypatch):
r = http('--meta', httpbin + '/get')
for line in r.splitlines():
assert 'Elapsed time' in r
def test_meta_elapsed_time(httpbin):
r = http('--meta', httpbin + '/delay/1')
assert f'{ELAPSED_TIME_LABEL}: 1.' in r
@pytest.mark.parametrize('style', ['auto', 'fruity', *PIE_STYLE_NAMES])
def test_meta_elapsed_time_colors(httpbin, style):
r = http('--style', style, '--meta', httpbin + '/get', env=MockEnvironment(colors=256))
assert COLOR in r
assert ELAPSED_TIME_LABEL in r

View File

@@ -17,7 +17,7 @@ from httpie.cli.argtypes import (
)
from httpie.cli.definition import parser
from httpie.encoding import UTF8
from httpie.output.formatters.colors import PIE_STYLES, get_lexer
from httpie.output.formatters.colors import get_lexer, PIE_STYLE_NAMES
from httpie.status import ExitStatus
from .fixtures import XML_DATA_RAW, XML_DATA_FORMATTED
from .utils import COLOR, CRLF, HTTP_OK, MockEnvironment, http, DUMMY_URL
@@ -227,7 +227,7 @@ def test_ensure_contents_colored(httpbin, endpoint):
assert COLOR in r
@pytest.mark.parametrize('style', PIE_STYLES.keys())
@pytest.mark.parametrize('style', PIE_STYLE_NAMES)
def test_ensure_meta_is_colored(httpbin, style):
env = MockEnvironment(colors=256)
r = http('--meta', '--style', style, 'GET', httpbin + '/get', env=env)

View File

@@ -2,6 +2,7 @@
Here we test our output parsing and matching implementation, not HTTPie itself.
"""
from httpie.models import ELAPSED_TIME_LABEL
from httpie.output.writer import MESSAGE_SEPARATOR
from ...utils import CRLF
from . import assert_output_does_not_match, assert_output_matches, Expect
@@ -111,7 +112,7 @@ def test_assert_output_matches_response_meta():
assert_output_matches(
(
'Key: Value\n'
'Elapsed Time: 3.3s'
f'{ELAPSED_TIME_LABEL}: 3.3s'
),
[Expect.RESPONSE_META]
)
@@ -124,7 +125,7 @@ def test_assert_output_matches_whole_response():
f'AAA:BBB{CRLF}'
f'{CRLF}'
f'CCC{MESSAGE_SEPARATOR}'
'Elapsed Time: 3.3s'
f'{ELAPSED_TIME_LABEL}: 3.3s'
),
[Expect.RESPONSE_HEADERS, Expect.BODY, Expect.RESPONSE_META]
)