Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

Commit 6e36535

Browse files
committed
add support for local tests in docker
1 parent e28a8d9 commit 6e36535

File tree

7 files changed

+102
-10
lines changed

7 files changed

+102
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.vscode/
2+
.idea/
23
*.pyc
34
test.db
45
.coverage

scripts/check

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
#!/bin/sh -e
22

33
export PREFIX=""
4-
if [ -d 'venv' ] ; then
4+
UNAME=$(uname)
5+
case "$UNAME" in
6+
"Linux") export SYSTEM="Linux" ;;
7+
"Darwin") export SYSTEM="Linux" ;;
8+
CYGWIN*) export SYSTEM="Windows" ;;
9+
MINGW*) export SYSTEM="Windows" ;;
10+
*) export SYSTEM="Linux" ;;
11+
esac
12+
13+
if [ -d 'venv' ]; then
14+
if [ $SYSTEM = "Linux" ] ; then
515
export PREFIX="venv/bin/"
16+
else
17+
export PREFIX="venv/Scripts/"
18+
fi
619
fi
20+
721
export SOURCE_FILES="databases tests"
822

923
set -x

scripts/coverage

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
#!/bin/sh -e
22

33
export PREFIX=""
4-
if [ -d 'venv' ] ; then
4+
UNAME=$(uname)
5+
case "$UNAME" in
6+
"Linux") export SYSTEM="Linux" ;;
7+
"Darwin") export SYSTEM="Linux" ;;
8+
CYGWIN*) export SYSTEM="Windows" ;;
9+
MINGW*) export SYSTEM="Windows" ;;
10+
*) export SYSTEM="Linux" ;;
11+
esac
12+
13+
if [ -d 'venv' ]; then
14+
if [ $SYSTEM = "Linux" ] ; then
515
export PREFIX="venv/bin/"
16+
else
17+
export PREFIX="venv/Scripts/"
18+
fi
619
fi
720

821
set -x

scripts/docker-compose.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: '2.1'
2+
services:
3+
postgres:
4+
image: postgres:10.8
5+
environment:
6+
POSTGRES_USER: username
7+
POSTGRES_PASSWORD: password
8+
POSTGRES_DB: testsuite
9+
ports:
10+
- 5432:5432
11+
12+
mysql:
13+
image: mysql:5.7
14+
environment:
15+
MYSQL_USER: username
16+
MYSQL_PASSWORD: password
17+
MYSQL_ROOT_PASSWORD: password
18+
MYSQL_DATABASE: testsuite
19+
ports:
20+
- 3306:3306

scripts/lint

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
#!/bin/sh -e
22

33
export PREFIX=""
4-
if [ -d 'venv' ] ; then
4+
UNAME=$(uname)
5+
case "$UNAME" in
6+
"Linux") export SYSTEM="Linux" ;;
7+
"Darwin") export SYSTEM="Linux" ;;
8+
CYGWIN*) export SYSTEM="Windows" ;;
9+
MINGW*) export SYSTEM="Windows" ;;
10+
*) export SYSTEM="Linux" ;;
11+
esac
12+
13+
if [ -d 'venv' ]; then
14+
if [ $SYSTEM = "Linux" ]; then
515
export PREFIX="venv/bin/"
16+
else
17+
export PREFIX="venv/Scripts/"
18+
fi
619
fi
720

821
set -x

scripts/test

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,51 @@
11
#!/bin/sh
22

33
export PREFIX=""
4-
if [ -d 'venv' ] ; then
4+
UNAME=$(uname)
5+
case "$UNAME" in
6+
"Linux") export SYSTEM="Linux" ;;
7+
"Darwin") export SYSTEM="Linux" ;;
8+
CYGWIN*) export SYSTEM="Windows" ;;
9+
MINGW*) export SYSTEM="Windows" ;;
10+
*) export SYSTEM="Linux" ;;
11+
esac
12+
13+
if [ -d 'venv' ]; then
14+
if [ $SYSTEM = "Linux" ]; then
515
export PREFIX="venv/bin/"
16+
else
17+
export PREFIX="venv/Scripts/"
18+
fi
19+
fi
20+
21+
if [ -z "$TEST_DATABASE_URLS" ]; then
22+
echo "Variable TEST_DATABASE_URLS must be set."
23+
exit 1
624
fi
725

8-
if [ -z "$TEST_DATABASE_URLS" ] ; then
9-
echo "Variable TEST_DATABASE_URLS must be set."
10-
exit 1
26+
if [ -n "${TEST_IN_DOCKER+x}" ]; then
27+
docker-compose -f ./scripts/docker-compose.yml up -d
28+
export TEST_DATABASE_URLS="sqlite:///test.db,
29+
sqlite+aiosqlite:///test.db,
30+
mysql+aiomysql://username:password@localhost:3306/testsuite,
31+
mysql+asyncmy://username:password@localhost:3306/testsuite,
32+
postgresql+aiopg://username:[email protected]:5432/testsuite,
33+
postgresql+asyncpg://username:password@localhost:5432/testsuite
34+
"
1135
fi
1236

1337
set -ex
1438

1539
if [ -z $GITHUB_ACTIONS ]; then
16-
scripts/check
40+
scripts/check
1741
fi
1842

1943
${PREFIX}coverage run -m pytest $@
2044

2145
if [ -z $GITHUB_ACTIONS ]; then
22-
scripts/coverage
46+
scripts/coverage
47+
fi
48+
49+
if [ -n "${TEST_IN_DOCKER+x}" ]; then
50+
docker-compose -f ./scripts/docker-compose.yml down
2351
fi

tests/test_databases.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
from databases import Database, DatabaseURL
1414

15+
if sys.version_info >= (3, 8) and sys.platform.lower().startswith("win"):
16+
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
17+
1518
assert "TEST_DATABASE_URLS" in os.environ, "TEST_DATABASE_URLS is not set."
1619

1720
DATABASE_URLS = [url.strip() for url in os.environ["TEST_DATABASE_URLS"].split(",")]
@@ -23,7 +26,7 @@ def mysql_versions(wrapped_func):
2326
"""
2427

2528
@functools.wraps(wrapped_func)
26-
def check(*args, **kwargs):
29+
def check(*args, **kwargs): # pragma: no cover
2730
url = DatabaseURL(kwargs["database_url"])
2831
if url.scheme in ["mysql", "mysql+aiomysql"] and sys.version_info >= (3, 10):
2932
pytest.skip("aiomysql supports python 3.9 and lower")

0 commit comments

Comments
 (0)