Skip to content

Commit

Permalink
fix(httpx): support 0.28
Browse files Browse the repository at this point in the history
  • Loading branch information
Shillaker committed Dec 10, 2024
1 parent d543c74 commit fb59d90
Showing 10 changed files with 281 additions and 206 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ DOCKER_NAME := boavizta/boaviztapi:${CURRENT_VERSION}
SEMVERS := major minor patch

MINIMUM_PY_VERSION=3.9
MAXIMUM_PY_VERSION=3.11
MAXIMUM_PY_VERSION=3.12

clean:
find . -name "*.pyc" -exec rm -rf {} \;
317 changes: 177 additions & 140 deletions poetry.lock

Large diffs are not rendered by default.

19 changes: 8 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -9,9 +9,9 @@ readme = "README.md"
python = "^3.9"
pydantic = "^2.9.2"
fastapi = "^0.115.0"
uvicorn = '^0.22'
pandas = '^2.0'
aiofile = '^3.8'
uvicorn = "^0.22"
pandas = "^2.0"
aiofile = "^3.8"
numpy = "^1.24"
scipy = "^1.9"
rapidfuzz = "^3.0"
@@ -21,17 +21,15 @@ importlib-metadata = "^6.6.0"
pyyaml = "^6.0"
toml = "^0.10.2"


[tool.poetry.group.dev]
optional = true

[tool.poetry.group.dev.dependencies]
pytest = '*'
pytest-asyncio = '*'
atomicwrites = "*"
httpx = '*'
requests = '*'

pytest = "^8.3.4"
pytest-asyncio = "^0.24.0"
atomicwrites = "^1.4.1"
httpx = "^0.28.1"
requests = "^2.32.3"

[tool.poetry.group.docs]
optional = true
@@ -42,7 +40,6 @@ mkdocs-material = "^9.4.4"
mkdocs-render-swagger-plugin = "^0.1.0"
mkdocs-macros-plugin = "^1.0.4"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
11 changes: 7 additions & 4 deletions tests/api/test_cloud.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from httpx import AsyncClient
from httpx import AsyncClient, ASGITransport

from boaviztapi.main import app

@@ -31,7 +31,8 @@ async def check_result(self):
url = self.request.to_url()
body = self.request.to_dict()

async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
if self.request.use_url_params:
res = await ac.get(url)
else:
@@ -134,7 +135,8 @@ async def test_empty_usage_with_url_params_r5ad():

@pytest.mark.asyncio
async def test_wrong_input():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post(
"/v1/cloud/instance?verbose=false",
json={"provider": "test", "instance_type": "a1.4xlarge", "usage": {}},
@@ -144,7 +146,8 @@ async def test_wrong_input():

@pytest.mark.asyncio
async def test_wrong_input_1():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post(
"/v1/cloud/instance?verbose=false",
json={"provider": "aws", "instance_type": "test", "usage": {}},
44 changes: 29 additions & 15 deletions tests/api/test_component.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from httpx import AsyncClient
from httpx import AsyncClient, ASGITransport

from boaviztapi.main import app

@@ -8,7 +8,8 @@

@pytest.mark.asyncio
async def test_complete_cpu():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/component/cpu?verbose=false', json={"core_units": 12, "die_size_per_core": 24.5})

assert res.json() == {"impacts": {'adp': {'description': 'Use of minerals and fossil ressources',
@@ -39,7 +40,8 @@ async def test_complete_cpu():

@pytest.mark.asyncio
async def test_complete_cpu_verbose():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/component/cpu?verbose=true', json={"core_units": 12, "die_size_per_core": 24.5})

assert res.json() == {'impacts': {'adp': {'description': 'Use of minerals and fossil ressources',
@@ -172,7 +174,8 @@ async def test_complete_cpu_verbose():

@pytest.mark.asyncio
async def test_complete_cpu_with_low_precision():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/component/cpu?verbose=false', json={"core_units": 12, "die_size_per_core": 20})

assert res.json() == {"impacts": {'adp': {'description': 'Use of minerals and fossil ressources',
@@ -203,7 +206,8 @@ async def test_complete_cpu_with_low_precision():

@pytest.mark.asyncio
async def test_empty_cpu():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/component/cpu?verbose=false', json={})

assert res.json() == {"impacts": {'adp': {'description': 'Use of minerals and fossil ressources',
@@ -234,7 +238,8 @@ async def test_empty_cpu():

@pytest.mark.asyncio
async def test_multiple_cpu():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/component/cpu?verbose=false', json={
"units": 3, "core_units": 12, "die_size_per_core": 24.5})

@@ -268,7 +273,8 @@ async def test_multiple_cpu():

@pytest.mark.asyncio
async def test_incomplete_cpu_verbose():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/component/cpu?verbose=true', json={
"core_units": 24, "family": "Skylake"})

@@ -400,7 +406,8 @@ async def test_incomplete_cpu_verbose():

@pytest.mark.asyncio
async def test_incomplete_cpu_verbose_2():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/component/cpu?verbose=true', json={
"core_units": 24, "family": "skylak"})

@@ -533,7 +540,8 @@ async def test_incomplete_cpu_verbose_2():

@pytest.mark.asyncio
async def test_complete_ram():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/component/ram?verbose=false', json={"units": 12, "capacity": 32, "density": 1.79})

assert res.json() == {'impacts': {'adp': {'description': 'Use of minerals and fossil ressources',
@@ -572,7 +580,8 @@ async def test_complete_ram():

@pytest.mark.asyncio
async def test_empty_ram():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/component/ram?verbose=false', json={})

assert res.json() == {"impacts": {'adp': {'description': 'Use of minerals and fossil ressources',
@@ -609,7 +618,8 @@ async def test_empty_ram():

@pytest.mark.asyncio
async def test_wrong_manuf_ram():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/component/ram?verbose=false', json={"manufacturer": "oieoiudhehz"})

assert res.json() == {'impacts': {'adp': {'description': 'Use of minerals and fossil ressources',
@@ -648,7 +658,8 @@ async def test_wrong_manuf_ram():

@pytest.mark.asyncio
async def test_wrong_manuf_ssd():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/component/ssd?verbose=false', json={"manufacturer": "oieoiudhehz"})

assert res.json() == {'impacts': {'adp': {'description': 'Use of minerals and fossil ressources',
@@ -694,7 +705,8 @@ async def test_wrong_manuf_ssd():

@pytest.mark.asyncio
async def test_complete_ssd():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/component/ssd?verbose=false', json={"capacity": 400, "density": 50.6})

assert res.json() == {"impacts": {'adp': {'description': 'Use of minerals and fossil ressources',
@@ -725,7 +737,8 @@ async def test_complete_ssd():

@pytest.mark.asyncio
async def test_empty_ssd():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/component/ssd?verbose=false', json={})

assert res.json() == {"impacts": {'adp': {'description': 'Use of minerals and fossil ressources',
@@ -765,7 +778,8 @@ async def test_empty_ssd():

@pytest.mark.asyncio
async def test_empty_blade():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/component/case?verbose=false', json={"case_type": "blade"})

assert res.json() == {"impacts": {'adp': {'description': 'Use of minerals and fossil ressources',
7 changes: 4 additions & 3 deletions tests/api/test_cp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from httpx import AsyncClient
from httpx import AsyncClient, ASGITransport

from boaviztapi.main import app

@@ -8,7 +8,8 @@

@pytest.mark.asyncio
async def test_complete_cpu():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/consumption_profile/cpu', json={"cpu": {"name": "intel xeon gold 6134", "tdp": 130}})

assert res.json() == {'a': 35.5688, 'b': 0.2438, 'c': 9.6694, 'd': -0.6087}
assert res.json() == {'a': 35.5688, 'b': 0.2438, 'c': 9.6694, 'd': -0.6087}
17 changes: 11 additions & 6 deletions tests/api/test_iot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from httpx import AsyncClient
from httpx import AsyncClient, ASGITransport

from boaviztapi.main import app

@@ -8,7 +8,8 @@

@pytest.mark.asyncio
async def test_empty_iot_device():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.get('/v1/iot/iot_device?verbose=false')

assert res.json() == {"impacts": {'adp': {'description': 'Use of minerals and fossil ressources',
@@ -62,7 +63,8 @@ async def test_empty_iot_device():

@pytest.mark.asyncio
async def test_drone_mini():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.get('/v1/iot/iot_device?verbose=false&archetype=drone_mini&criteria=gwp')

assert res.json() == {"impacts": {'gwp': {'description': 'Total climate change',
@@ -82,7 +84,8 @@ async def test_drone_mini():

@pytest.mark.asyncio
async def test_drone_mini_verbose():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.get('/v1/iot/iot_device?verbose=true&archetype=drone_mini')

assert res.json() == {'impacts': {'adp': {'description': 'Use of minerals and fossil ressources',
@@ -425,7 +428,8 @@ async def test_drone_mini_verbose():

@pytest.mark.asyncio
async def test_drone_mini_costume_usage():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/iot/iot_device?verbose=false&archetype=drone_mini&duration=1', json={
"usage": {
"avg_power": 100,
@@ -465,7 +469,8 @@ async def test_drone_mini_costume_usage():

@pytest.mark.asyncio
async def test_custom_iot():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/iot/iot_device?verbose=false&criteria=lu', json={
"functional_blocks": [
{
Loading

0 comments on commit fb59d90

Please sign in to comment.