From 5ab8db061fbbd50be779e9fa33dcad07613f38c1 Mon Sep 17 00:00:00 2001 From: Simon Brunning Date: Fri, 26 Apr 2024 09:44:36 +0100 Subject: [PATCH] Use public httpbin for mac runner in github actions. --- .github/workflows/ci.yml | 8 ----- setup.py | 2 +- tests/integration/conftest.py | 7 +++-- tests/integration/matchers/test_response.py | 34 ++++++++++----------- 4 files changed, 23 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8e6a8f1..10744ad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,14 +73,6 @@ jobs: python-version: ${{ matrix.python }} - name: Install build tools run: python3 -m pip install --upgrade pip setuptools wheel tox~=3.0 - - name: Install and Start Colima - run: | - if [[ "${{ matrix.os }}" == *"macos"* ]] - then - brew install docker docker-compose - colima status || colima start - fi - shell: bash - name: Run Tests # Run tox using the version of Python in `PATH` run: tox -e py diff --git a/setup.py b/setup.py index aabcf4a..527ce2b 100644 --- a/setup.py +++ b/setup.py @@ -58,7 +58,7 @@ extras_require={ "optional": [ "furl>=2.0", - "imurl>=0.2", + "yarl>=1.9", "requests>=2.0", "Werkzeug>=2.0", ], diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 490587e..50a8658 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -1,12 +1,15 @@ # encoding=utf-8 import logging +import os import platform import sqlite3 import pytest -from imurl import URL +from yarl import URL logger = logging.getLogger(__name__) +LOCAL = "GITHUB_ACTIONS" not in os.environ +HTTPBIN_CONTAINERISED = platform.system() == "Linux" or LOCAL @pytest.fixture(scope="session") @@ -28,7 +31,7 @@ def db(): @pytest.fixture(scope="session") def httpbin(docker_ip, docker_services) -> URL: - if platform.system() != "Windows": + if HTTPBIN_CONTAINERISED: docker_services.start("httpbin") port = docker_services.wait_for_service("httpbin", 80) return URL(f"http://{docker_ip}:{port}") diff --git a/tests/integration/matchers/test_response.py b/tests/integration/matchers/test_response.py index 8b4319a..e0150bd 100644 --- a/tests/integration/matchers/test_response.py +++ b/tests/integration/matchers/test_response.py @@ -1,5 +1,6 @@ # encoding=utf-8 import logging +import os import platform from datetime import timedelta @@ -17,14 +18,16 @@ logger = logging.getLogger(__name__) INTERNET_CONNECTED = internet_connection() +LOCAL = "GITHUB_ACTIONS" not in os.environ +HTTPBIN_CONTAINERISED = platform.system() == "Linux" or LOCAL -@pytest.mark.xfail(platform.system() == "Windows", reason="Public httpbin horribly flaky.") +@pytest.mark.xfail(not HTTPBIN_CONTAINERISED, reason="Public httpbin horribly flaky.") def test_response_status_code(httpbin): # Given # When - actual = requests.get(httpbin.replace(path="/status/345")) + actual = requests.get(httpbin / "status/345") # Then assert_that(actual, is_response().with_status_code(345)) @@ -35,26 +38,25 @@ def test_response_status_code(httpbin): ) -@pytest.mark.xfail(platform.system() == "Windows", reason="Public httpbin horribly flaky.") +@pytest.mark.xfail(not HTTPBIN_CONTAINERISED, reason="Public httpbin horribly flaky.") def test_response_json(httpbin): # Given # When - actual = requests.get(httpbin.replace(path="/json")) + actual = requests.get(httpbin / "json") # Then assert_that(actual, is_response().with_json(has_key("slideshow"))) assert_that(actual, not_(is_response().with_json(has_key("shitshow")))) -@pytest.mark.xfail(platform.system() == "Windows", reason="Public httpbin horribly flaky.") +@pytest.mark.xfail(not HTTPBIN_CONTAINERISED, reason="Public httpbin horribly flaky.") def test_response_content(httpbin): # Given # When actual = requests.get( - httpbin.replace(path="/anything").set_query("foo", "bar"), - headers={"X-Clacks-Overhead": "Sir Terry Pratchett"}, + httpbin / "anything" % {"foo": "bar"}, headers={"X-Clacks-Overhead": "Sir Terry Pratchett"} ) # Then @@ -65,25 +67,23 @@ def test_response_content(httpbin): assert_that(actual, not_(is_response().with_content(b"seems unlikely"))) -@pytest.mark.xfail(platform.system() == "Windows", reason="Public httpbin horribly flaky.") +@pytest.mark.xfail(not HTTPBIN_CONTAINERISED, reason="Public httpbin horribly flaky.") def test_response_cookies(httpbin): # Given # When - actual = requests.get( - httpbin.replace(path="/cookies/set").set_query("foo", "bar"), allow_redirects=False - ) + actual = requests.get(httpbin / "cookies/set" % {"foo": "bar"}, allow_redirects=False) # Then assert_that(actual, is_response().with_status_code(302).and_cookies(has_entries(foo="bar"))) -@pytest.mark.xfail(platform.system() == "Windows", reason="Public httpbin horribly flaky.") +@pytest.mark.xfail(not HTTPBIN_CONTAINERISED, reason="Public httpbin horribly flaky.") def test_response_elapsed(httpbin): # Given # When - actual = requests.get(httpbin.replace(path="/delay/0.5")) + actual = requests.get(httpbin / "delay/0.5") # Then assert_that( @@ -94,12 +94,12 @@ def test_response_elapsed(httpbin): ) -@pytest.mark.xfail(platform.system() == "Windows", reason="Public httpbin horribly flaky.") +@pytest.mark.xfail(not HTTPBIN_CONTAINERISED, reason="Public httpbin horribly flaky.") def test_response_history(httpbin): # Given # When - actual = requests.get(httpbin.replace(path="/cookies/set").set_query("foo", "bar")) + actual = requests.get(httpbin / "cookies/set" % {"foo": "bar"}) # Then assert_that( @@ -111,12 +111,12 @@ def test_response_history(httpbin): ) -@pytest.mark.xfail(platform.system() == "Windows", reason="Public httpbin horribly flaky.") +@pytest.mark.xfail(not HTTPBIN_CONTAINERISED, reason="Public httpbin horribly flaky.") def test_response_encoding(httpbin): # Given # When - actual = requests.get(httpbin.replace(path="/encoding/utf8")) + actual = requests.get(httpbin / "encoding/utf8") # Then assert_that(actual, is_response().with_encoding("utf-8"))