Skip to content

Commit ccdca61

Browse files
Add PostgreSQL tests
Change-Id: If2f295e0b6d5ed69c994b4bf90772f25c47b4aeb
1 parent c94dc94 commit ccdca61

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ nosetests.xml
8080
coverage.xml
8181
*.cover
8282
.hypothesis/
83+
reports
8384

8485
# Translations
8586
*.mo

bluepyparallel/database.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ def __init__(self, url, *args, create=False, **kwargs):
3232
self.metadata = None
3333
self.table = None
3434

35+
def __del__(self):
36+
self.connection.close()
37+
3538
def get_url(self):
3639
return self.engine.url
3740

tests/test_database.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,33 @@
66
from sqlalchemy import Table
77
from sqlalchemy import create_engine
88
from sqlalchemy import select
9+
from sqlalchemy.exc import OperationalError
910

1011
from bluepyparallel import database
1112

12-
URLS = ["/tmpdir/test.db", "sqlite:////tmpdir/test.db"]
13+
URLS = [
14+
"/tmpdir/test.db",
15+
"sqlite:////tmpdir/test.db",
16+
]
17+
try:
18+
# Set up the PostGIS database:
19+
# Create the ``test_bpp`` role::
20+
# $ sudo -u postgres psql -c "CREATE ROLE test_bpp PASSWORD 'test_bpp' SUPERUSER CREATEDB
21+
# CREATEROLE INHERIT LOGIN;"
22+
# Create the ``test_bpp`` database::
23+
# $ sudo -u postgres createdb -E UTF-8 test_bpp
24+
# $ sudo -u postgres psql -d test_bpp -c 'CREATE SCHEMA test_bpp;'
25+
# $ sudo -u postgres psql -c 'GRANT CREATE ON DATABASE test_bpp TO "test_bpp";'
26+
# $ sudo -u postgres psql -d test_bpp -c 'GRANT USAGE,CREATE ON SCHEMA test_bpp TO
27+
# "test_bpp";'
28+
PG_URL = "postgresql://test_bpp:test_bpp@localhost/test_bpp"
29+
create_engine(PG_URL).connect()
30+
URLS.append(PG_URL)
31+
except OperationalError:
32+
pass
33+
except ModuleNotFoundError as e:
34+
if "psycopg2" not in str(e):
35+
raise
1336

1437

1538
@pytest.fixture(params=URLS)

0 commit comments

Comments
 (0)