The majority of Pyrseas’ capabilities are exercised and verified via unit tests written using pytest. The tests can be run from the command line by most users, e.g.,
py.test tests/dbobject/test_table.py py.test tests/dbobject/test_trigger.py -k test_create_trigger py.test tests/functional
python command above runs all tests related to tables,
mapping, creating, dropping, etc. The second one executes a single
test to generate SQL to create a trigger. The third runs all the
functional tests. Please review the pytest documentation for further options.
By default, the tests use a PostgreSQL database named
pyrseas_testdb which is created if it doesn’t already exist. The
tests are run as the logged in user, using the
environment variable (or
USERNAME under Windows). They access
PostgreSQL on the local host using the default port number (5432).
The following four environment variables can be used to change the defaults described above:
Unless the test database exists and the user running the tests has access to it, the user role will need CREATEDB privilege.
Most tests do not require special privileges. However, tests that
define dynamically loaded functions (e.g.,
require SUPERUSER privilege. Such tests will be skipped if the user
lacks the privilege.
Most tests do not require installation of supporting PostgreSQL packages. However, tests that define dynamically loaded functions (see above) require that the contrib/spi module be installed.
On Windows, it is necessary to install Perl in order to run some of
the tests. A suitable choice is Strawberry Perl which can be
downloaded from http://strawberryperl.com/releases.html. However, the
default installation is placed in
C:\strawberry and can hold a
single Perl version. Furthermore, some PostgreSQL versions may be
linked with non-current Perl versions. It is recommended that the
latest Perl version be installed as this will usually give the fewest
test failures. See this blog post
for more details.
The COLLATION tests, run under PostgreSQL 9.3 and later, require the
fr_FR.utf8 locale (or
French.France.1252 language on Windows)
to be installed.
The following is a summary list of steps needed to test Pyrseas on a
new machine. Refer to Development for details on how to
accomplish a given installation task. “Package manager” refers to the
platform’s package management system utility such as
yum. Installation from PyPI can be done with either
easy_install. Some operations require administrative or superuser
privileges, at either the operating system or PostgreSQL level.
Install Git using package manager or from http://git-scm.com/download (on Windows, prefer Git Bash)
git clone git://github.com/perseas/Pyrseas.git
Install Python 2.7 and 3.6 or 3.5, using package manager or from installers at http://www.python.org/download/.
Install PostgreSQL 10, 9.6, 9.5, 9.4 and 9.3, using package manager or binary installers at http://www.postgresql.org/download/
On Linux, make sure you install the contrib and plperl packages, e.g., on Debian, postgresql-contrib-n.n and postgresql-plperl-n.n (where n.n is the PostgreSQL version number)
Install Tox, from PyPI (http://pypi.python.org/pypi/tox)
Psycopg2, PyYAML and Tox all have to be installed twice, i.e., once under Python 2.7 and another under 3.6 or 3.5.
On Windows, install Perl (see discussion above under “Restrictions”). On Linux, usually Perl is already available.
As postgres user, using psql or pgAdmin, create a test user, e.g., your name. The user running tests must have at a minimum createdb privilege, in order to create the test database. To run all the tests, the user also needs superuser privilege.
Create a PostgreSQL password file, e.g., on Linux:
~/.pgpass, on Windows:
Create directories to hold tablespaces, e.g.,
C:\\extra\\pg\\9.5\\ts1on Windows. The directories need to be owned by the postgres user. This may be tricky on older Windows versions, but the command
cacls <dir> /E /G postgres:Fshould suffice. Using psql or pgAdmin, create tablespaces ts1 and ts2, e.g.,
CREATE TABLESPACE ts1 LOCATION '<directory>'(on Windows, you’ll have to use, e.g.,
E'C:\\dir\\ts1', to specify the directory).
- On Windows, for PostgreSQL 9.2, the default installation is owned by the Network Service account, so the
caclscommand should be
cacls <dir> /E /G networkservices:F.
The creation of users/roles and tablespaces has to be repeated for each PostgreSQL version.
Install the locale
fr_FR.utf8on Linux/Unix or the language
On Debian and derivatives, this can be done with the command:sudo dpkg-reconfigure locales
On Windows, open the Control Panel, select Date, Time, Language, and Regional Options, then Regional and Language Options (or Add other languages), click on the Advanced tab in the dialog and then choose “French (France)” from the dropdown. Finally, click OK and respond to any subsequent prompts to install the locale, including rebooting the machine.
Change to the Pyrseas source directory (created by the second step above).
- Define the
PYTHONPATHenvironment variable to the Pyrseas source directory, e.g., on Linux,
export PYTHONPATH=$PWD, on Windows,
- Define the environment variables
PG95_PORTto point to the corresponding PostgreSQL ports.
tox. This will create two virtualenvs in a
.toxsubdirectory–one for Python 2.7 and another for 3.6 or 3.5, install Pyrseas and its prerequisites (Psycopg2 and PyYAML) into each virtualenv and run the unit tests for each combination of PostgreSQL and Python.