Skip to content

Commit

Permalink
run tests on linux, windows, and macos (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
cle-b authored Oct 23, 2024
1 parent 2407815 commit 72c0208
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 46 deletions.
26 changes: 14 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Linter and code format verification
Expand All @@ -25,34 +25,36 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.COVERALLS }}

testpythons:
name: Test all Python version
testospython:
name: Test OS/Python version
needs: test
runs-on: ubuntu-20.04
runs-on: ${{ matrix.os }}
timeout-minutes: 15
strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]

os: [macos-latest, windows-latest, ubuntu-latest]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Run tests
run: |
make ci
env:
PIP_USE_PEP517: 1

deploy:
name: Deploy on Pypi
needs: testpythons
needs: testospython
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Install pypa/build
Expand Down
28 changes: 16 additions & 12 deletions tests/test_getaddrinfo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-

import platform
import socket

import pytest
Expand All @@ -20,7 +20,7 @@ def test_real_getaddrinfo_with_name_ipv4():

def test_real_getaddrinfo_with_name_ipv6():
r = socket.getaddrinfo(
"ip6-localhost", 80, family=socket.AF_INET6, proto=socket.IPPROTO_TCP
"localhost", 80, family=socket.AF_INET6, proto=socket.IPPROTO_TCP
)
for _, _, _, _, sockaddr in r:
assert sockaddr == ("::1", 80, 0, 0)
Expand Down Expand Up @@ -48,6 +48,10 @@ def test_real_getaddrinfo_with_public_fqdn_ipv4():
assert ipaddr != "127.0.0.1"


@pytest.mark.skipif(
platform.system().lower() == "windows",
reason="ipv6 issue for windows on github actions",
)
def test_real_getaddrinfo_with_public_fqdn_ipv6():
r = socket.getaddrinfo(
"example.org", 80, family=socket.AF_INET6, proto=socket.IPPROTO_TCP
Expand All @@ -73,10 +77,10 @@ def test_patch_decorator_with_name_ipv4():
assert sockaddr == ("1.2.3.4", 80)


@patch_getaddrinfo({"ip6-localhost": "1::23"})
@patch_getaddrinfo({"localhost": "1::23"})
def test_patch_decorator_with_name_ipv6():
r = socket.getaddrinfo(
"ip6-localhost", 80, family=socket.AF_INET6, proto=socket.IPPROTO_TCP
"localhost", 80, family=socket.AF_INET6, proto=socket.IPPROTO_TCP
)
for _, _, _, _, sockaddr in r:
assert sockaddr == ("1::23", 80, 0, 0)
Expand Down Expand Up @@ -129,11 +133,11 @@ def test_patch_decorator_with_public_fqdn_and_a_name_for_addr_ipv4():
)


@patch_getaddrinfo({"example.org": "ip6-localhost"})
@patch_getaddrinfo({"example.org": "localhost"})
def test_patch_decorator_with_public_fqdn_and_a_name_for_addr_ipv6():
family = socket.AF_INET6
assert socket.getaddrinfo("example.org", 80, family=family) == socket.getaddrinfo(
"ip6-localhost", 80, family=family
"localhost", 80, family=family
)


Expand All @@ -156,7 +160,7 @@ def test_patch_decorator_with_another_hostname_ipv4():
@patch_getaddrinfo({"localhost2": "1.2.3.4"})
def test_patch_decorator_with_another_hostname_ipv6():
r = socket.getaddrinfo(
"ip6-localhost", 80, family=socket.AF_INET6, proto=socket.IPPROTO_TCP
"localhost", 80, family=socket.AF_INET6, proto=socket.IPPROTO_TCP
)
for _, _, _, _, sockaddr in r:
assert sockaddr == ("::1", 80, 0, 0)
Expand All @@ -175,9 +179,9 @@ def test_patch_contextmanager_with_name_ipv4():


def test_patch_contextmanager_with_name_ipv6():
with patch_getaddrinfo({"ip6-localhost": "1::23"}):
with patch_getaddrinfo({"localhost": "1::23"}):
r = socket.getaddrinfo(
"ip6-localhost", 80, family=socket.AF_INET6, proto=socket.IPPROTO_TCP
"localhost", 80, family=socket.AF_INET6, proto=socket.IPPROTO_TCP
)
for _, _, _, _, sockaddr in r:
assert sockaddr == ("1::23", 80, 0, 0)
Expand Down Expand Up @@ -235,11 +239,11 @@ def test_patch_contextmanager_with_public_fqdn_and_a_name_for_addr_ipv4():


def test_patch_contextmanager_with_public_fqdn_and_a_name_for_addr_ipv6():
with patch_getaddrinfo({"example.org": "ip6-localhost"}):
with patch_getaddrinfo({"example.org": "localhost"}):
family = socket.AF_INET6
assert socket.getaddrinfo(
"example.org", 80, family=family
) == socket.getaddrinfo("ip6-localhost", 80, family=family)
) == socket.getaddrinfo("localhost", 80, family=family)


def test_patch_contextmanager_with_unknown_hostname():
Expand All @@ -261,7 +265,7 @@ def test_patch_contextmanager_with_another_hostname_ipv4():
def test_patch_contextmanager_with_another_hostname_ipv6():
with patch_getaddrinfo({"localhost2": "1.2.3.4"}):
r = socket.getaddrinfo(
"ip6-localhost", 80, family=socket.AF_INET6, proto=socket.IPPROTO_TCP
"localhost", 80, family=socket.AF_INET6, proto=socket.IPPROTO_TCP
)
for _, _, _, _, sockaddr in r:
assert sockaddr == ("::1", 80, 0, 0)
1 change: 0 additions & 1 deletion tests/test_gethostbyname_ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

def test_real_gethostbyname_ex_with_name():
(hostname, _, ipaddrlist) = socket.gethostbyname_ex("localhost")
assert hostname == "localhost"
assert "127.0.0.1" in ipaddrlist


Expand Down
28 changes: 16 additions & 12 deletions tests/test_hosts_getaddrinfo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-

import platform
import socket

import pytest
Expand All @@ -20,7 +20,7 @@ def test_real_getaddrinfo_with_name_ipv4():

def test_real_getaddrinfo_with_name_ipv6():
r = socket.getaddrinfo(
"ip6-localhost", 80, family=socket.AF_INET6, proto=socket.IPPROTO_TCP
"localhost", 80, family=socket.AF_INET6, proto=socket.IPPROTO_TCP
)
for _, _, _, _, sockaddr in r:
assert sockaddr == ("::1", 80, 0, 0)
Expand Down Expand Up @@ -48,6 +48,10 @@ def test_real_getaddrinfo_with_public_fqdn_ipv4():
assert ipaddr != "127.0.0.1"


@pytest.mark.skipif(
platform.system().lower() == "windows",
reason="ipv6 issue for windows on github actions",
)
def test_real_getaddrinfo_with_public_fqdn_ipv6():
r = socket.getaddrinfo(
"example.org", 80, family=socket.AF_INET6, proto=socket.IPPROTO_TCP
Expand All @@ -73,10 +77,10 @@ def test_patch_decorator_with_name_ipv4():
assert sockaddr == ("1.2.3.4", 80)


@hosts({"ip6-localhost": "1::23"})
@hosts({"localhost": "1::23"})
def test_patch_decorator_with_name_ipv6():
r = socket.getaddrinfo(
"ip6-localhost", 80, family=socket.AF_INET6, proto=socket.IPPROTO_TCP
"localhost", 80, family=socket.AF_INET6, proto=socket.IPPROTO_TCP
)
for _, _, _, _, sockaddr in r:
assert sockaddr == ("1::23", 80, 0, 0)
Expand Down Expand Up @@ -129,11 +133,11 @@ def test_patch_decorator_with_public_fqdn_and_a_name_for_addr_ipv4():
)


@hosts({"example.org": "ip6-localhost"})
@hosts({"example.org": "localhost"})
def test_patch_decorator_with_public_fqdn_and_a_name_for_addr_ipv6():
family = socket.AF_INET6
assert socket.getaddrinfo("example.org", 80, family=family) == socket.getaddrinfo(
"ip6-localhost", 80, family=family
"localhost", 80, family=family
)


Expand All @@ -156,7 +160,7 @@ def test_patch_decorator_with_another_hostname_ipv4():
@hosts({"localhost2": "1.2.3.4"})
def test_patch_decorator_with_another_hostname_ipv6():
r = socket.getaddrinfo(
"ip6-localhost", 80, family=socket.AF_INET6, proto=socket.IPPROTO_TCP
"localhost", 80, family=socket.AF_INET6, proto=socket.IPPROTO_TCP
)
for _, _, _, _, sockaddr in r:
assert sockaddr == ("::1", 80, 0, 0)
Expand All @@ -175,9 +179,9 @@ def test_patch_contextmanager_with_name_ipv4():


def test_patch_contextmanager_with_name_ipv6():
with hosts({"ip6-localhost": "1::23"}):
with hosts({"localhost": "1::23"}):
r = socket.getaddrinfo(
"ip6-localhost", 80, family=socket.AF_INET6, proto=socket.IPPROTO_TCP
"localhost", 80, family=socket.AF_INET6, proto=socket.IPPROTO_TCP
)
for _, _, _, _, sockaddr in r:
assert sockaddr == ("1::23", 80, 0, 0)
Expand Down Expand Up @@ -235,11 +239,11 @@ def test_patch_contextmanager_with_public_fqdn_and_a_name_for_addr_ipv4():


def test_patch_contextmanager_with_public_fqdn_and_a_name_for_addr_ipv6():
with hosts({"example.org": "ip6-localhost"}):
with hosts({"example.org": "localhost"}):
family = socket.AF_INET6
assert socket.getaddrinfo(
"example.org", 80, family=family
) == socket.getaddrinfo("ip6-localhost", 80, family=family)
) == socket.getaddrinfo("localhost", 80, family=family)


def test_patch_contextmanager_with_unknown_hostname():
Expand All @@ -261,7 +265,7 @@ def test_patch_contextmanager_with_another_hostname_ipv4():
def test_patch_contextmanager_with_another_hostname_ipv6():
with hosts({"localhost2": "1.2.3.4"}):
r = socket.getaddrinfo(
"ip6-localhost", 80, family=socket.AF_INET6, proto=socket.IPPROTO_TCP
"localhost", 80, family=socket.AF_INET6, proto=socket.IPPROTO_TCP
)
for _, _, _, _, sockaddr in r:
assert sockaddr == ("::1", 80, 0, 0)
1 change: 0 additions & 1 deletion tests/test_hosts_gethostbyname_ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

def test_real_gethostbyname_ex_with_name():
(hostname, _, ipaddrlist) = socket.gethostbyname_ex("localhost")
assert hostname == "localhost"
assert "127.0.0.1" in ipaddrlist


Expand Down
12 changes: 4 additions & 8 deletions tests/test_hosts_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
def test_patch_decorator_only_gethostbyname():
assert socket.gethostbyname("localhost") == "1.2.3.4"
(hostname, _, ipaddrlist) = socket.gethostbyname_ex("localhost")
assert hostname == "localhost"
assert "127.0.0.1" in ipaddrlist
r = socket.getaddrinfo(
"localhost", 80, family=socket.AF_INET, proto=socket.IPPROTO_TCP
Expand All @@ -24,7 +23,7 @@ def test_patch_decorator_only_gethostbyname():
@hosts({"localhost": "1.2.3.4"}, only=["gethostbyname_ex"])
def test_patch_decorator_only_gethostbyname_ex():
assert socket.gethostbyname("localhost") == "127.0.0.1"
assert socket.gethostbyname_ex("localhost") == ("localhost", [], ["1.2.3.4"])
assert socket.gethostbyname_ex("localhost")[2] == ["1.2.3.4"]
r = socket.getaddrinfo(
"localhost", 80, family=socket.AF_INET, proto=socket.IPPROTO_TCP
)
Expand All @@ -36,7 +35,6 @@ def test_patch_decorator_only_gethostbyname_ex():
def test_patch_decorator_only_getaddrinfo():
assert socket.gethostbyname("localhost") == "127.0.0.1"
(hostname, _, ipaddrlist) = socket.gethostbyname_ex("localhost")
assert hostname == "localhost"
assert "127.0.0.1" in ipaddrlist
r = socket.getaddrinfo(
"localhost", 80, family=socket.AF_INET, proto=socket.IPPROTO_TCP
Expand All @@ -48,7 +46,7 @@ def test_patch_decorator_only_getaddrinfo():
@hosts({"localhost": "1.2.3.4"}, only=["gethostbyname", "gethostbyname_ex"])
def test_patch_decorator_only_gethostbyname_and_gethostbyname_ex():
assert socket.gethostbyname("localhost") == "1.2.3.4"
assert socket.gethostbyname_ex("localhost") == ("localhost", [], ["1.2.3.4"])
assert socket.gethostbyname_ex("localhost")[2] == ["1.2.3.4"]
r = socket.getaddrinfo(
"localhost", 80, family=socket.AF_INET, proto=socket.IPPROTO_TCP
)
Expand All @@ -63,7 +61,6 @@ def test_patch_contextmanager_only_gethostbyname():
with hosts({"localhost": "1.2.3.4"}, only=["gethostbyname"]):
assert socket.gethostbyname("localhost") == "1.2.3.4"
(hostname, _, ipaddrlist) = socket.gethostbyname_ex("localhost")
assert hostname == "localhost"
assert "127.0.0.1" in ipaddrlist
r = socket.getaddrinfo(
"localhost", 80, family=socket.AF_INET, proto=socket.IPPROTO_TCP
Expand All @@ -75,7 +72,7 @@ def test_patch_contextmanager_only_gethostbyname():
def test_patch_contextmanager_only_gethostbyname_ex():
with hosts({"localhost": "1.2.3.4"}, only=["gethostbyname_ex"]):
assert socket.gethostbyname("localhost") == "127.0.0.1"
assert socket.gethostbyname_ex("localhost") == ("localhost", [], ["1.2.3.4"])
assert socket.gethostbyname_ex("localhost")[2] == ["1.2.3.4"]
r = socket.getaddrinfo(
"localhost", 80, family=socket.AF_INET, proto=socket.IPPROTO_TCP
)
Expand All @@ -87,7 +84,6 @@ def test_patch_contextmanager_only_getaddrinfo():
with hosts({"localhost": "1.2.3.4"}, only=["getaddrinfo"]):
assert socket.gethostbyname("localhost") == "127.0.0.1"
(hostname, _, ipaddrlist) = socket.gethostbyname_ex("localhost")
assert hostname == "localhost"
assert "127.0.0.1" in ipaddrlist
r = socket.getaddrinfo(
"localhost", 80, family=socket.AF_INET, proto=socket.IPPROTO_TCP
Expand All @@ -99,7 +95,7 @@ def test_patch_contextmanager_only_getaddrinfo():
def test_patch_contextmanager_only_gethostbyname_and_gethostbyname_ex():
with hosts({"localhost": "1.2.3.4"}, only=["gethostbyname", "gethostbyname_ex"]):
assert socket.gethostbyname("localhost") == "1.2.3.4"
assert socket.gethostbyname_ex("localhost") == ("localhost", [], ["1.2.3.4"])
assert socket.gethostbyname_ex("localhost")[2] == ["1.2.3.4"]
r = socket.getaddrinfo(
"localhost", 80, family=socket.AF_INET, proto=socket.IPPROTO_TCP
)
Expand Down

0 comments on commit 72c0208

Please sign in to comment.