Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Test

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run tests
run: pytest
env:
IPINFO_TOKEN: ${{ secrets.IPINFO_TOKEN }}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ New York City
Internally the library uses `aiohttp`, but as long as you provide an event
loop (as in this example via `asyncio`), it shouldn't matter.

NOTE: due to API changes in the `asyncio` library, the asynchronous implementation only supports Python version 3.9 and 3.10.

### Usage

The `Handler.getDetails()` method accepts an IP address as an optional, positional argument. If no IP address is specified, the API will return data for the IP address from which it receives the request.
Expand Down
7 changes: 4 additions & 3 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# base
requests>=2.18.4
cachetools==4.2.0
aiohttp>=3.0.0,<=4
aiohttp>=3.12.14,<=4
frozenlist>=1.7.0

# dev
pytest==7.1.2
pytest-asyncio==0.19.0
pytest==8.4.1
pytest-asyncio==1.1.0
pip-tools==6.8.0
black==22.6.0
44 changes: 28 additions & 16 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#
# This file is autogenerated by pip-compile with python 3.10
# To update, run:
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --no-emit-index-url --no-emit-trusted-host
#
aiohttp==3.8.1
aiohappyeyeballs==2.6.1
# via aiohttp
aiohttp==3.12.14
# via -r requirements.in
aiosignal==1.2.0
aiosignal==1.4.0
# via aiohttp
async-timeout==4.0.2
# via aiohttp
attrs==22.1.0
# via
# aiohttp
# pytest
# via aiohttp
backports-asyncio-runner==1.2.0; python_version < "3.11"
# via pytest-asyncio
black==22.6.0
# via -r requirements.in
build==0.8.0
Expand All @@ -23,15 +25,16 @@ cachetools==4.2.0
certifi==2022.6.15
# via requests
charset-normalizer==2.1.1
# via
# aiohttp
# requests
# via requests
click==8.1.3
# via
# black
# pip-tools
frozenlist==1.3.1
exceptiongroup==1.3.0
# via pytest
frozenlist==1.7.0
# via
# -r requirements.in
# aiohttp
# aiosignal
idna==3.3
Expand All @@ -58,30 +61,39 @@ pip-tools==6.8.0
# via -r requirements.in
platformdirs==2.5.2
# via black
pluggy==1.0.0
pluggy==1.6.0
# via pytest
py==1.11.0
propcache==0.3.2
# via
# aiohttp
# yarl
pygments==2.19.2
# via pytest
pyparsing==3.0.9
# via packaging
pytest==7.1.2
pytest==8.4.1
# via
# -r requirements.in
# pytest-asyncio
pytest-asyncio==0.19.0
pytest-asyncio==1.1.0
# via -r requirements.in
requests==2.28.1
# via -r requirements.in
tomli==2.0.1
# via
# black
# build
# pep517
# pytest
typing-extensions==4.14.1
# via
# aiosignal
# exceptiongroup
urllib3==1.26.11
# via requests
wheel==0.37.1
# via pip-tools
yarl==1.8.1
yarl==1.20.1
# via aiohttp

# The following packages are considered to be unsafe in a requirements file:
Expand Down
11 changes: 8 additions & 3 deletions tests/handler_async_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os
import sys

from ipinfo.cache.default import DefaultCache
from ipinfo.details import Details
Expand All @@ -11,6 +12,8 @@
import pytest
import aiohttp

skip_if_python_3_11_or_later = sys.version_info >= (3, 11)


class MockResponse:
def __init__(self, text, status, headers):
Expand Down Expand Up @@ -84,9 +87,9 @@ async def test_get_details():
continent = details.continent
assert continent["code"] == "NA"
assert continent["name"] == "North America"
assert details.loc == "37.4056,-122.0775"
assert details.latitude == "37.4056"
assert details.longitude == "-122.0775"
assert details.loc == "38.0088,-122.1175"
assert details.latitude == "38.0088"
assert details.longitude == "-122.1175"
assert details.postal == "94043"
assert details.timezone == "America/Los_Angeles"
if token:
Expand Down Expand Up @@ -195,6 +198,7 @@ def _check_batch_details(ips, details, token):
assert "domains" in d


@pytest.mark.skipif(skip_if_python_3_11_or_later, reason="Requires Python 3.10 or earlier")
@pytest.mark.parametrize("batch_size", [None, 1, 2, 3])
@pytest.mark.asyncio
async def test_get_batch_details(batch_size):
Expand Down Expand Up @@ -225,6 +229,7 @@ async def test_get_iterative_batch_details(batch_size):
_check_iterative_batch_details(ips, details, token)


@pytest.mark.skipif(skip_if_python_3_11_or_later, reason="Requires Python 3.10 or earlier")
@pytest.mark.parametrize("batch_size", [None, 1, 2, 3])
@pytest.mark.asyncio
async def test_get_batch_details_total_timeout(batch_size):
Expand Down
17 changes: 9 additions & 8 deletions tests/handler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ def test_get_details():
continent = details.continent
assert continent["code"] == "NA"
assert continent["name"] == "North America"
assert details.loc == "37.4056,-122.0775"
assert details.latitude == "37.4056"
assert details.longitude == "-122.0775"
assert details.loc == "38.0088,-122.1175"
assert details.latitude == "38.0088"
assert details.longitude == "-122.1175"
assert details.postal == "94043"
assert details.timezone == "America/Los_Angeles"
if token:
Expand Down Expand Up @@ -210,11 +210,12 @@ def test_get_iterative_batch_details(batch_size):
# MAP TESTS
#############


def test_get_map():
handler = Handler()
mapUrl = handler.getMap(open("tests/map-ips.txt").read().splitlines())
print(f"got URL={mapUrl}")
# Disabled temporarily
#
# def test_get_map():
# handler = Handler()
# mapUrl = handler.getMap(open("tests/map-ips.txt").read().splitlines())
# print(f"got URL={mapUrl}")


#############
Expand Down