pgtest 
Creates a temporary, local PostgreSQL database cluster and server specifically for unittesting, and cleans up after itself.
PGTest(username='postgres', port=None, log_file=None, no_cleanup=False,
copy_cluster=None, base_dir=None, pg_ctl=None, max_connections=5)
Args:
username - str, username for default database superuser
port - int, port to connect on; you must ensure that the port is unused
log_file - str, path to place the log file
no_cleanup - bool, don't clean up dirs after PGTest.close() is called
copy_cluster - str, copies cluster from this path
base_dir - str, path to the base directory to init the cluster
pg_ctl - str, path to the pg_ctl executable to use
max_connections - int, maximum number of connections to the cluster
Attributes:
PGTest.port - int, port number bound by PGTest
PGTest.cluster - str, cluster directory generated by PGTest
PGTest.username - str, username used by PGTest. Default is 'postgres'
PGTest.log_file - str, path to postgres log file
PGTest.pg_ctl - str, path to pg_ctl executable
PGTest.url - str, url for default postgres database on the cluster
PGTest.dsn - dict, dictionary containing dsn key-value pairs for the
default postgres database on the cluster
Methods:
close() - Closes this instance of PGTest, cleans up directories
Usage as an instance
>>> from pgtest.pgtest import PGTest
>>> import psycopg2
>>> pg = PGTest()
Server started: postgresql://postgres@localhost:47251/postgres
>>> pg.port
47251
>>> pg.cluster
'/tmp/tmpiDtBjs/data'
>>> pg.username
'postgres'
>>> pg.log_file
'/tmp/tmpiDtBjs/pgtest_log.txt'
>>> pg.pg_ctl
u'/usr/lib/postgresql/9.4/bin/pg_ctl'
>>> pg.url
'postgresql://postgres@localhost:47251/postgres'
>>> pg.dsn
{'user': 'postgres', 'host': 'localhost',
'port': 47251, 'database': 'postgres'}
>>> # Connect with other db driver here, e.g. psql, psycopg2,
>>> # sqlalchemy etc
>>> psycopg2.connect(**pg.dsn)
>>> pg.close()
Server stopped
Or use as a context:
>>> from pgtest.pgtest import PGTest
>>> import psycopg2
>>> with PGTest() as pg:
... # connect to db with psycopg/sqlalchemy etc
... psycopg2.connect(**pg.dsn)
... # Do other database actions here
>>> # When the context exits, the db cluster and service is deleted unless specified
Use with unittest in the setUp() and tearDown() methods:
import unittest
from pgtest.pgtest import PGTest
class TestThirdPartyDrivers(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.pg = pgtest.PGTest()
cls.base_dir = cls.pg._base_dir
@classmethod
def tearDownClass(cls):
cls.pg.close()
def test_something(self):
self.assertTrue(isinstance(self.pg, PGTest)
Metadata
Release files for pgtest 1.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pgtest-1.3.2.tar.gz | 9.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pgtest-1.3.2-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 18.4 kB
Release files / pgtest-1.3.2.tar.gz
| Download URL | pgtest-1.3.2.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
edbb5ed5f5c46ae6f6a58eeffcf9f2ef1467bfee4eb753f0bca4ab2cb302ee91
|
|
BLAKE2b-256 checksum How to use checksums |
5241ff29129bc427bbdc6cbe4559a4830a4f4d71739ce33c728b4fa610f5b12e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7
|
Release files / pgtest-1.3.2-py2.py3-none-any.whl
| Download URL | pgtest-1.3.2-py2.py3-none-any.whl |
|---|---|
| Size | 9.1 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
a80a5b6080c36a207cdbbc44c45c829f721b0e643dd9b821bd31b8f26849c36b
|
|
BLAKE2b-256 checksum How to use checksums |
d3477b58a3599232c80d1e87facaf24c67a826eed7342a12d5b6e7f8b7735163
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7
|
Security for pgtest 1.3.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.