-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
172 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Test package.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,11 @@ | ||
"""Test cases for custom builders.""" | ||
import sqlite3 | ||
from pathlib import Path | ||
|
||
import pytest | ||
from sphinx.testing.util import SphinxTestApp | ||
|
||
|
||
@pytest.mark.sphinx("sqlite", testroot="default") | ||
def test___work_builder(app: SphinxTestApp, status, warning): # noqa | ||
def test___work_builder(app: SphinxTestApp, status, warning, conn): # noqa | ||
app.build() | ||
db_path = Path(app.outdir) / "db.sqlite" | ||
assert db_path.exists() | ||
conn = sqlite3.connect(db_path) | ||
assert len(conn.execute("SELECT * FROM document").fetchall()) > 0 | ||
assert len(conn.execute("SELECT * FROM section").fetchall()) > 0 | ||
assert len(conn.execute("SELECT * FROM content").fetchall()) > 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,9 @@ | ||
"""Test cases for result of events.""" | ||
import sqlite3 | ||
from pathlib import Path | ||
|
||
import pytest | ||
from sphinx.testing.util import SphinxTestApp | ||
|
||
|
||
@pytest.mark.sphinx("html", testroot="default") | ||
def test___work_builder(app: SphinxTestApp, status, warning): # noqa | ||
def test___work_builder(app: SphinxTestApp, status, warning, conn): # noqa | ||
app.build() | ||
db_path = Path(app.outdir) / "db.sqlite" | ||
assert db_path.exists() | ||
conn = sqlite3.connect(db_path) | ||
assert len(conn.execute("SELECT * FROM document").fetchall()) > 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"""Database wrapper utility.""" | ||
import psycopg2 | ||
|
||
|
||
class Database: | ||
""" | ||
Wrap connection to the database in a test context. | ||
TODO: Re-add adapter for SQLite. | ||
TODO: Add adapters for other databases. | ||
""" | ||
|
||
def __init__(self, dsn: str): | ||
"""Object constructor.""" | ||
self.dsn = dsn | ||
self.conn = None | ||
self.connect() | ||
|
||
def connect(self): | ||
"""Connect to database, optionally disconnecting when already connected.""" | ||
if self.conn is not None: | ||
self.conn.close() | ||
self.conn = psycopg2.connect(self.dsn) | ||
self.conn.autocommit = True | ||
|
||
def execute(self, query): | ||
"""Invoke an SQL statement.""" | ||
cursor = self.conn.cursor() | ||
cursor.execute(query) | ||
return Result(cursor=cursor) | ||
|
||
def reset(self): | ||
"""Clear database content, to provide each test case with a blank slide.""" | ||
cursor = self.conn.cursor() | ||
cursor.execute("DELETE FROM content;") | ||
cursor.execute("DELETE FROM section;") | ||
cursor.execute("DELETE FROM document;") | ||
cursor.close() | ||
|
||
|
||
class Result: | ||
"""Wrap SQLAlchemy result object.""" | ||
|
||
def __init__(self, cursor): | ||
"""Object constructor.""" | ||
self.cursor = cursor | ||
|
||
def fetchall(self): | ||
"""Fetch all records, exhaustively.""" | ||
return self.cursor.fetchall() | ||
|
||
def __del__(self): | ||
"""When object is destroyed, also close the cursor.""" | ||
self.cursor.close() |