Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Testing framework for PostgreSQL and its extensions

License

NotificationsYou must be signed in to change notification settings

postgrespro/testgres

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Postgres testing utility

Installation

To installtestgres run:

pip install testgres

At current state it only works with Python 2.*

Usage

Node: by default testgres runsinitdb,pg_ctl,psql commands from the$PATH. To specify custom postgres installation set environment variable$PG_CONFIG and point it to pg_config executable:export PG_CONFIG=/path/to/pg_config

Here is an example of how you can usetestgres.

fromtestgresimportget_new_nodetry:node=get_new_node('master')node.init()node.start()stdout=node.safe_psql('postgres','SELECT 1')printstdoutnode.stop()exceptClusterException,e:node.cleanup()

Let's walk through the code. First you create new node:

node=get_new_node('master')

master here is a node's name, not the database's name. The name matters if you're testing replication. Functionget_new_node() only creates directory structure in/tmp for cluster. Next line:

node.init()

initializes cluster. On low level it runsinitdb command and adds some basic configuration topostgresql.conf andpg_hba.conf files. Functioninit() accepts optional parameterallows_streaming which configures cluster for streaming replication (default isFalse).Now we are ready to start:

node.start()

After this you are able to run queries over the cluster. There are three functions to do that:

  • node.psql(database, query) - runs query viapsql command and returns tuple (error code, stdout, stderr)
  • node.safe_psql(database, query) - the same aspsql() except that it returns onlystdout. If error occures during the execution then it will throw an exception;
  • node.execute(database, query) - connects with postgresql server usingpsycopg2 orpg8000 library (depends on which is installed in your system) and returns two-dimensional array with data.

To stop server run:

node.stop()

Please seetestgres/tests directory for replication configuration example.

About

Testing framework for PostgreSQL and its extensions

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors32


[8]ページ先頭

©2009-2025 Movatter.jp