Skip to content

Commit

Permalink
Remove aiodocker and related fixtures, since they are not used anyway. (
Browse files Browse the repository at this point in the history
  • Loading branch information
jettify authored Oct 28, 2023
1 parent 26982f5 commit 53fe8a6
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 164 deletions.
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
-e .
aiodocker==0.21.0
bandit==1.7.5
black==23.3.0
flake8-bugbear==23.3.23
Expand Down
164 changes: 1 addition & 163 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import asyncio
import gc
import os
import random
import time
import uuid
from concurrent.futures import ThreadPoolExecutor
from contextlib import asynccontextmanager

import pyodbc
import pytest
import pytest_asyncio
import uvloop
from aiodocker import Docker

import aioodbc

Expand Down Expand Up @@ -43,163 +38,6 @@ def loop(event_loop):
return event_loop


@pytest.fixture(scope="session")
async def docker():
client = Docker()

try:
yield client
finally:
await client.close()


@pytest.fixture(scope="session")
def host():
# Alternative: host.docker.internal, however not working on travis
return os.environ.get("DOCKER_MACHINE_IP", "127.0.0.1")


@pytest_asyncio.fixture
async def pg_params(pg_server):
server_info = pg_server["pg_params"]
return dict(**server_info)


@asynccontextmanager
async def _pg_server_helper(host, docker, session_id):
pg_tag = "9.5"

await docker.pull(f"postgres:{pg_tag}")
container = await docker.containers.create_or_replace(
name=f"aioodbc-test-server-{pg_tag}-{session_id}",
config={
"Image": f"postgres:{pg_tag}",
"AttachStdout": False,
"AttachStderr": False,
"HostConfig": {
"PublishAllPorts": True,
},
},
)
await container.start()
container_port = await container.port(5432)
port = container_port[0]["HostPort"]

pg_params = {
"database": "postgres",
"user": "postgres",
"password": "mysecretpassword",
"host": host,
"port": port,
}

start = time.time()
dsn = create_pg_dsn(pg_params)
last_error = None
container_info = {
"port": port,
"pg_params": pg_params,
"container": container,
"dsn": dsn,
}
try:
while (time.time() - start) < 40:
try:
conn = pyodbc.connect(dsn)
cur = conn.execute("SELECT 1;")
cur.close()
conn.close()
break
except pyodbc.Error as e:
last_error = e
await asyncio.sleep(random.uniform(0.1, 1))
else:
pytest.fail(f"Cannot start postgres server: {last_error}")

yield container_info
finally:
container = container_info["container"]
if container:
await container.kill()
await container.delete(v=True, force=True)


@pytest.fixture(scope="session")
async def pg_server(host, docker, session_id):
async with _pg_server_helper(host, docker, session_id) as helper:
yield helper


@pytest.fixture
async def pg_server_local(host, docker):
async with _pg_server_helper(host, docker, None) as helper:
yield helper


@pytest.fixture
async def mysql_params(mysql_server):
server_info = (mysql_server)["mysql_params"]
return dict(**server_info)


@pytest.fixture(scope="session")
async def mysql_server(host, docker, session_id):
mysql_tag = "5.7"
await docker.pull(f"mysql:{mysql_tag}")
container = await docker.containers.create_or_replace(
name=f"aioodbc-test-server-{mysql_tag}-{session_id}",
config={
"Image": f"mysql:{mysql_tag}",
"AttachStdout": False,
"AttachStderr": False,
"Env": [
"MYSQL_USER=aioodbc",
"MYSQL_PASSWORD=mysecretpassword",
"MYSQL_DATABASE=aioodbc",
"MYSQL_ROOT_PASSWORD=mysecretpassword",
],
"HostConfig": {
"PublishAllPorts": True,
},
},
)
await container.start()
port = (await container.port(3306))[0]["HostPort"]
mysql_params = {
"database": "aioodbc",
"user": "aioodbc",
"password": "mysecretpassword",
"host": host,
"port": port,
}
dsn = create_mysql_dsn(mysql_params)
start = time.time()
try:
last_error = None
while (time.time() - start) < 30:
try:
conn = pyodbc.connect(dsn)
cur = conn.execute("SELECT 1;")
cur.close()
conn.close()
break
except pyodbc.Error as e:
last_error = e
await asyncio.sleep(random.uniform(0.1, 1))
else:
pytest.fail(f"Cannot start mysql server: {last_error}")

container_info = {
"port": port,
"mysql_params": mysql_params,
}

yield container_info
finally:
await container.kill()
await container.delete(v=True, force=True)


@pytest.fixture
def executor():
executor = ThreadPoolExecutor(max_workers=1)
Expand All @@ -215,7 +53,7 @@ def pytest_configure():


@pytest.fixture
def db(request):
def db():
return "sqlite"


Expand Down

0 comments on commit 53fe8a6

Please sign in to comment.