/usr/lib/python2.7/dist-packages/testing.common.database-2.0.0.egg-info/PKG-INFO is in python-testing.common.database 2.0.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | Metadata-Version: 1.1
Name: testing.common.database
Version: 2.0.0
Summary: utilities for testing.* packages
Home-page: https://github.com/tk0miya/testing.common.database
Author: Takeshi Komiya
Author-email: i.tkomiya at gmail.com
License: Apache License 2.0
Description: About
=====
``testing.common.database`` is utilities for testing.* package.
.. image:: https://travis-ci.org/tk0miya/testing.common.database.svg?branch=master
:target: https://travis-ci.org/tk0miya/testing.common.database
.. image:: https://codeclimate.com/github/tk0miya/testing.common.database/badges/gpa.svg
:target: https://codeclimate.com/github/tk0miya/testing.common.database
Install
=======
Use pip::
$ pip install testing.common.database
Helpers
=======
class Database(object):
``Database`` is a base class for database testing packages.
To create your database testing class, inherit this class and override methods below.
def initialize(self):
Handler for initialize database object.
def get_data_directory(self):
Path to data directory of your databse.
Example::
def get_data_directory(self):
return os.path.join(self.base_dir, 'data')
def initialize_database(self):
Handler to initialize your database.
Example::
def initialize_database(self):
if not os.path.exists(os.path.join(self.base_dir, 'data', 'PG_VERSION')):
args = ([self.initdb, '-D', os.path.join(self.base_dir, 'data'), '--lc-messages=C'] +
self.settings['initdb_args'].split())
try:
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, err = p.communicate()
if p.returncode != 0:
raise RuntimeError("initdb failed: %r" % err)
except OSError as exc:
raise RuntimeError("failed to spawn initdb: %s" % exc)
def get_server_commandline(self):
Command line to invoke your database server.
Example::
def get_server_commandline(self):
return (['postgres',
'-p', str(self.settings['port']),
'-D', os.path.join(self.base_dir, 'data'),
'-k', os.path.join(self.base_dir, 'tmp')] +
self.settings['postgres_args'].split())
def prestart(self):
Handler called before invoking your database server.
def poststart(self):
Hander called after invoking your database server.
def is_server_available(self):
Methods check your database server available.
The ``Database`` class uses this method to check the server boots up.
Example::
try:
with closing(pg8000.connect(**self.dsn(database='template1'))):
pass
except pg8000.Error:
return False
else:
return True
def is_alive(self):
Methods check the database server is alive.
@property
def server_pid(self):
Process ID of the database server.
class DatabaseFactory(object):
``DatabaseFactory`` is a factory class for the database class.
To create your database factory class, inherit this class and set ``target_class`` variable::
class PostgresqlFactory(DatabaseFactory):
target_class = Postgresql
The factory class should work like a ``target_class``::
# The factory class generates like a ``target_class``, in this case, generates ``Postgresql`` class
Postgresql = PostgresqlFactory()
# The generated class works same as ``target_class``
with Postgresql() as pgsql:
#
# do any tests using the database ...
#
It can bypass parameters to the ``target_class`` on every instantiation::
Postgresql = PostgresqlFactory(copy_data_from='/path/to/database')
with Postgresql() as pgsql:
#
# Test with ``copy_data_from`` parameter :-)
#
Also, it is able to cache the database generated at ``Database.initialize_database()``
with ``cache_initialized_db`` parameter.
It avoids running database initialization on every tests::
# Initialize database once
Postgresql = PostgresqlFactory(cache_initialized_db=True)
with Postgresql() as pgsql:
# copy cached database for this test.
If you want to fixtures to the database, use ``on_initialized`` parameter::
def handler(pgsql):
# inserting fixtures
# Initialize database once, and call ``on_initialized`` handler
Postgresql = PostgresqlFactory(cache_initialized_db=True,
on_initialized=handler)
class SkipIfNotInstalledDecorator(object):
Generates decorator that skips the testcase if database command not found.
To create decorator, inherit this class and set ``name`` variable and override ``search_server()`` method.
Example::
class PostgresqlSkipIfNotInstalledDecorator(SkipIfNotInstalledDecorator):
name = 'PostgreSQL'
def search_server(self):
find_program('postgres', ['bin']) # raise exception if not found
skipIfNotFound = skipIfNotInstalled = PostgresqlSkipIfNotInstalledDecorator()
@skipIfNotFound
def test():
# testcase
def get_unused_port():
Get free TCP port.
def get_path_of(name):
Searchs command from search paths. It works like ``which`` command.
Requirements
============
* Python 2.6, 2.7, 3.2, 3.3, 3.4, 3.5
License
=======
Apache License 2.0
History
=======
2.0.0 (2016-08-20)
-------------------
* Use subprocess.Popen() instead of fork & exec
* Support windows platform (experimental)
* #4: Add boot_timeout parameter
* Fix bugs:
- Fix syntax errors for Python3
- Show error messages if rescue from GC failed (ref: #1)
1.1.0 (2016-02-05)
-------------------
* Add Database#server_pid to get pid of the database server
* Add Database#is_alive() to check server is alive
* Define BOOT_TIMEOUT as constant
* Fix AttributeError if any exceptions are raised in bootstrap
1.0.0 (2016-02-01)
-------------------
* Initial release
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.2
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Topic :: Database
Classifier: Topic :: Software Development
Classifier: Topic :: Software Development :: Testing
|