From 8b4b44babdd1acc3373fd4e8e59cb4a19ca7bf6b Mon Sep 17 00:00:00 2001 From: Gabriel Date: Thu, 9 Jun 2022 21:51:12 -0400 Subject: [PATCH] Fix sort bug (#10) * sort error --- csv2http/_version.py | 2 +- csv2http/utils.py | 6 +++++- pyproject.toml | 2 +- tests/test_csv2http.py | 2 +- tests/test_utils.py | 27 +++++++++++++++++++++++++++ 5 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 tests/test_utils.py diff --git a/csv2http/_version.py b/csv2http/_version.py index d50a7ae..f48e01a 100644 --- a/csv2http/_version.py +++ b/csv2http/_version.py @@ -1,2 +1,2 @@ """_version""" -__version__ = "0.0.2a" +__version__ = "0.0.2a1" diff --git a/csv2http/utils.py b/csv2http/utils.py index 977ba14..d41ecb1 100644 --- a/csv2http/utils.py +++ b/csv2http/utils.py @@ -56,7 +56,11 @@ def summarize_responses(responses: list[Response]) -> str: [getattr(r, "status_code", r.__class__.__name__) for r in responses] ) # TODO: maybe don't bother sorting this - sorted_dict = dict(sorted(counter.items(), key=lambda item: item[0])) + sorted_dict = dict( + sorted( + counter.items(), key=lambda item: item[0] if isinstance(item[0], int) else 0 + ) + ) return f"status codes - {sorted_dict}" diff --git a/pyproject.toml b/pyproject.toml index 2c55532..02cab72 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "csv2http" -version = "0.0.2a" +version = "0.0.2a1" description = "Make http requests based on a CSV input file" authors = ["Gabriel Gore "] license = "MIT License" diff --git a/tests/test_csv2http.py b/tests/test_csv2http.py index 56bfb5b..4f7c02a 100644 --- a/tests/test_csv2http.py +++ b/tests/test_csv2http.py @@ -2,4 +2,4 @@ def test_version(): - assert __version__ == "0.0.2a" + assert __version__ == "0.0.2a1" diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 0000000..aec0d6f --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,27 @@ +import httpx +import pytest +from respx import MockResponse + +from csv2http import utils + + +@pytest.mark.parametrize( + "responses", + [ + [ + MockResponse(200), + MockResponse(201), + httpx.ConnectTimeout("Ooops"), + MockResponse(201), + httpx.ConnectError("Oh no"), + ] + ], +) +def test_summarize_responses(responses): + summary = utils.summarize_responses(responses) + print(summary) + assert summary + + +if __name__ == "__main__": + pytest.main(["-vv"])