From fa110f714eaf52a3e56d3b4555ba3475dd00049c Mon Sep 17 00:00:00 2001 From: CoprDistGit Date: Mon, 15 May 2023 08:48:36 +0000 Subject: automatic import of python-testgres --- .gitignore | 1 + python-testgres.spec | 629 +++++++++++++++++++++++++++++++++++++++++++++++++++ sources | 1 + 3 files changed, 631 insertions(+) create mode 100644 python-testgres.spec create mode 100644 sources diff --git a/.gitignore b/.gitignore index e69de29..6ebd3be 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +/testgres-1.8.7.tar.gz diff --git a/python-testgres.spec b/python-testgres.spec new file mode 100644 index 0000000..9208627 --- /dev/null +++ b/python-testgres.spec @@ -0,0 +1,629 @@ +%global _empty_manifest_terminate_build 0 +Name: python-testgres +Version: 1.8.7 +Release: 1 +Summary: Testing utility for PostgreSQL and its extensions +License: PostgreSQL +URL: https://github.com/postgrespro/testgres +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/a5/1c/e2b266ccba314e31650e2fbc789abc5f416502d7a9604163864846c01735/testgres-1.8.7.tar.gz +BuildArch: noarch + +Requires: python3-packaging +Requires: python3-pg8000 +Requires: python3-port-for +Requires: python3-psutil +Requires: python3-six + +%description +[![Build Status](https://travis-ci.com/postgrespro/testgres.svg?branch=master)](https://app.travis-ci.com/github/postgrespro/testgres/branches) +[![codecov](https://codecov.io/gh/postgrespro/testgres/branch/master/graph/badge.svg)](https://codecov.io/gh/postgrespro/testgres) +[![PyPI version](https://badge.fury.io/py/testgres.svg)](https://badge.fury.io/py/testgres) + +[Documentation](https://postgrespro.github.io/testgres/) + +# testgres + +PostgreSQL testing utility. Both Python 2.7 and 3.3+ are supported. + + +## Installation + +To install `testgres`, run: + +``` +pip install testgres +``` + +We encourage you to use `virtualenv` for your testing environment. + + +## Usage + +### Environment + +> Note: by default testgres runs `initdb`, `pg_ctl`, `psql` provided by `PATH`. + +There are several ways to specify a custom postgres installation: + +* export `PG_CONFIG` environment variable pointing to the `pg_config` executable; +* export `PG_BIN` environment variable pointing to the directory with executable files. + +Example: + +```bash +export PG_BIN=$HOME/pg_10/bin +python my_tests.py +``` + + +### Examples + +Here is an example of what you can do with `testgres`: + +```python +# create a node with random name, port, etc +with testgres.get_new_node() as node: + + # run inidb + node.init() + + # start PostgreSQL + node.start() + + # execute a query in a default DB + print(node.execute('select 1')) + +# ... node stops and its files are about to be removed +``` + +There are four API methods for runnig queries: + +| Command | Description | +|----------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------| +| `node.psql(query, ...)` | Runs query via `psql` command and returns tuple `(error code, stdout, stderr)`. | +| `node.safe_psql(query, ...)` | Same as `psql()` except that it returns only `stdout`. If an error occures during the execution, an exception will be thrown. | +| `node.execute(query, ...)` | Connects to PostgreSQL using `psycopg2` or `pg8000` (depends on which one is installed in your system) and returns two-dimensional array with data. | +| `node.connect(dbname, ...)` | Returns connection wrapper (`NodeConnection`) capable of running several queries within a single transaction. | + +The last one is the most powerful: you can use `begin(isolation_level)`, `commit()` and `rollback()`: +```python +with node.connect() as con: + con.begin('serializable') + print(con.execute('select %s', 1)) + con.rollback() +``` + + +### Logging + +By default, `cleanup()` removes all temporary files (DB files, logs etc) that were created by testgres' API methods. +If you'd like to keep logs, execute `configure_testgres(node_cleanup_full=False)` before running any tests. + +> Note: context managers (aka `with`) call `stop()` and `cleanup()` automatically. + +`testgres` supports [python logging](https://docs.python.org/3.6/library/logging.html), +which means that you can aggregate logs from several nodes into one file: + +```python +import logging + +# write everything to /tmp/testgres.log +logging.basicConfig(filename='/tmp/testgres.log') + +# enable logging, and create two different nodes +testgres.configure_testgres(use_python_logging=True) +node1 = testgres.get_new_node().init().start() +node2 = testgres.get_new_node().init().start() + +# execute a few queries +node1.execute('select 1') +node2.execute('select 2') + +# disable logging +testgres.configure_testgres(use_python_logging=False) +``` + +Look at `tests/test_simple.py` file for a complete example of the logging +configuration. + + +### Backup & replication + +It's quite easy to create a backup and start a new replica: + +```python +with testgres.get_new_node('master') as master: + master.init().start() + + # create a backup + with master.backup() as backup: + + # create and start a new replica + replica = backup.spawn_replica('replica').start() + + # catch up with master node + replica.catchup() + + # execute a dummy query + print(replica.execute('postgres', 'select 1')) +``` + +### Benchmarks + +`testgres` is also capable of running benchmarks using `pgbench`: + +```python +with testgres.get_new_node('master') as master: + # start a new node + master.init().start() + + # initialize default DB and run bench for 10 seconds + res = master.pgbench_init(scale=2).pgbench_run(time=10) + print(res) +``` + + +### Custom configuration + +It's often useful to extend default configuration provided by `testgres`. + +`testgres` has `default_conf()` function that helps control some basic +options. The `append_conf()` function can be used to add custom +lines to configuration lines: + +```python +ext_conf = "shared_preload_libraries = 'postgres_fdw'" + +# initialize a new node +with testgres.get_new_node().init() as master: + + # ... do something ... + + # reset main config file + master.default_conf(fsync=True, + allow_streaming=True) + + # add a new config line + master.append_conf('postgresql.conf', ext_conf) +``` + +Note that `default_conf()` is called by `init()` function; both of them overwrite +the configuration file, which means that they should be called before `append_conf()`. + + +## Authors + +[Ildar Musin](https://github.com/zilder) +[Dmitry Ivanov](https://github.com/funbringer) +[Ildus Kurbangaliev](https://github.com/ildus) +[Yury Zhuravlev](https://github.com/stalkerg) + + + + +%package -n python3-testgres +Summary: Testing utility for PostgreSQL and its extensions +Provides: python-testgres +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-testgres +[![Build Status](https://travis-ci.com/postgrespro/testgres.svg?branch=master)](https://app.travis-ci.com/github/postgrespro/testgres/branches) +[![codecov](https://codecov.io/gh/postgrespro/testgres/branch/master/graph/badge.svg)](https://codecov.io/gh/postgrespro/testgres) +[![PyPI version](https://badge.fury.io/py/testgres.svg)](https://badge.fury.io/py/testgres) + +[Documentation](https://postgrespro.github.io/testgres/) + +# testgres + +PostgreSQL testing utility. Both Python 2.7 and 3.3+ are supported. + + +## Installation + +To install `testgres`, run: + +``` +pip install testgres +``` + +We encourage you to use `virtualenv` for your testing environment. + + +## Usage + +### Environment + +> Note: by default testgres runs `initdb`, `pg_ctl`, `psql` provided by `PATH`. + +There are several ways to specify a custom postgres installation: + +* export `PG_CONFIG` environment variable pointing to the `pg_config` executable; +* export `PG_BIN` environment variable pointing to the directory with executable files. + +Example: + +```bash +export PG_BIN=$HOME/pg_10/bin +python my_tests.py +``` + + +### Examples + +Here is an example of what you can do with `testgres`: + +```python +# create a node with random name, port, etc +with testgres.get_new_node() as node: + + # run inidb + node.init() + + # start PostgreSQL + node.start() + + # execute a query in a default DB + print(node.execute('select 1')) + +# ... node stops and its files are about to be removed +``` + +There are four API methods for runnig queries: + +| Command | Description | +|----------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------| +| `node.psql(query, ...)` | Runs query via `psql` command and returns tuple `(error code, stdout, stderr)`. | +| `node.safe_psql(query, ...)` | Same as `psql()` except that it returns only `stdout`. If an error occures during the execution, an exception will be thrown. | +| `node.execute(query, ...)` | Connects to PostgreSQL using `psycopg2` or `pg8000` (depends on which one is installed in your system) and returns two-dimensional array with data. | +| `node.connect(dbname, ...)` | Returns connection wrapper (`NodeConnection`) capable of running several queries within a single transaction. | + +The last one is the most powerful: you can use `begin(isolation_level)`, `commit()` and `rollback()`: +```python +with node.connect() as con: + con.begin('serializable') + print(con.execute('select %s', 1)) + con.rollback() +``` + + +### Logging + +By default, `cleanup()` removes all temporary files (DB files, logs etc) that were created by testgres' API methods. +If you'd like to keep logs, execute `configure_testgres(node_cleanup_full=False)` before running any tests. + +> Note: context managers (aka `with`) call `stop()` and `cleanup()` automatically. + +`testgres` supports [python logging](https://docs.python.org/3.6/library/logging.html), +which means that you can aggregate logs from several nodes into one file: + +```python +import logging + +# write everything to /tmp/testgres.log +logging.basicConfig(filename='/tmp/testgres.log') + +# enable logging, and create two different nodes +testgres.configure_testgres(use_python_logging=True) +node1 = testgres.get_new_node().init().start() +node2 = testgres.get_new_node().init().start() + +# execute a few queries +node1.execute('select 1') +node2.execute('select 2') + +# disable logging +testgres.configure_testgres(use_python_logging=False) +``` + +Look at `tests/test_simple.py` file for a complete example of the logging +configuration. + + +### Backup & replication + +It's quite easy to create a backup and start a new replica: + +```python +with testgres.get_new_node('master') as master: + master.init().start() + + # create a backup + with master.backup() as backup: + + # create and start a new replica + replica = backup.spawn_replica('replica').start() + + # catch up with master node + replica.catchup() + + # execute a dummy query + print(replica.execute('postgres', 'select 1')) +``` + +### Benchmarks + +`testgres` is also capable of running benchmarks using `pgbench`: + +```python +with testgres.get_new_node('master') as master: + # start a new node + master.init().start() + + # initialize default DB and run bench for 10 seconds + res = master.pgbench_init(scale=2).pgbench_run(time=10) + print(res) +``` + + +### Custom configuration + +It's often useful to extend default configuration provided by `testgres`. + +`testgres` has `default_conf()` function that helps control some basic +options. The `append_conf()` function can be used to add custom +lines to configuration lines: + +```python +ext_conf = "shared_preload_libraries = 'postgres_fdw'" + +# initialize a new node +with testgres.get_new_node().init() as master: + + # ... do something ... + + # reset main config file + master.default_conf(fsync=True, + allow_streaming=True) + + # add a new config line + master.append_conf('postgresql.conf', ext_conf) +``` + +Note that `default_conf()` is called by `init()` function; both of them overwrite +the configuration file, which means that they should be called before `append_conf()`. + + +## Authors + +[Ildar Musin](https://github.com/zilder) +[Dmitry Ivanov](https://github.com/funbringer) +[Ildus Kurbangaliev](https://github.com/ildus) +[Yury Zhuravlev](https://github.com/stalkerg) + + + + +%package help +Summary: Development documents and examples for testgres +Provides: python3-testgres-doc +%description help +[![Build Status](https://travis-ci.com/postgrespro/testgres.svg?branch=master)](https://app.travis-ci.com/github/postgrespro/testgres/branches) +[![codecov](https://codecov.io/gh/postgrespro/testgres/branch/master/graph/badge.svg)](https://codecov.io/gh/postgrespro/testgres) +[![PyPI version](https://badge.fury.io/py/testgres.svg)](https://badge.fury.io/py/testgres) + +[Documentation](https://postgrespro.github.io/testgres/) + +# testgres + +PostgreSQL testing utility. Both Python 2.7 and 3.3+ are supported. + + +## Installation + +To install `testgres`, run: + +``` +pip install testgres +``` + +We encourage you to use `virtualenv` for your testing environment. + + +## Usage + +### Environment + +> Note: by default testgres runs `initdb`, `pg_ctl`, `psql` provided by `PATH`. + +There are several ways to specify a custom postgres installation: + +* export `PG_CONFIG` environment variable pointing to the `pg_config` executable; +* export `PG_BIN` environment variable pointing to the directory with executable files. + +Example: + +```bash +export PG_BIN=$HOME/pg_10/bin +python my_tests.py +``` + + +### Examples + +Here is an example of what you can do with `testgres`: + +```python +# create a node with random name, port, etc +with testgres.get_new_node() as node: + + # run inidb + node.init() + + # start PostgreSQL + node.start() + + # execute a query in a default DB + print(node.execute('select 1')) + +# ... node stops and its files are about to be removed +``` + +There are four API methods for runnig queries: + +| Command | Description | +|----------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------| +| `node.psql(query, ...)` | Runs query via `psql` command and returns tuple `(error code, stdout, stderr)`. | +| `node.safe_psql(query, ...)` | Same as `psql()` except that it returns only `stdout`. If an error occures during the execution, an exception will be thrown. | +| `node.execute(query, ...)` | Connects to PostgreSQL using `psycopg2` or `pg8000` (depends on which one is installed in your system) and returns two-dimensional array with data. | +| `node.connect(dbname, ...)` | Returns connection wrapper (`NodeConnection`) capable of running several queries within a single transaction. | + +The last one is the most powerful: you can use `begin(isolation_level)`, `commit()` and `rollback()`: +```python +with node.connect() as con: + con.begin('serializable') + print(con.execute('select %s', 1)) + con.rollback() +``` + + +### Logging + +By default, `cleanup()` removes all temporary files (DB files, logs etc) that were created by testgres' API methods. +If you'd like to keep logs, execute `configure_testgres(node_cleanup_full=False)` before running any tests. + +> Note: context managers (aka `with`) call `stop()` and `cleanup()` automatically. + +`testgres` supports [python logging](https://docs.python.org/3.6/library/logging.html), +which means that you can aggregate logs from several nodes into one file: + +```python +import logging + +# write everything to /tmp/testgres.log +logging.basicConfig(filename='/tmp/testgres.log') + +# enable logging, and create two different nodes +testgres.configure_testgres(use_python_logging=True) +node1 = testgres.get_new_node().init().start() +node2 = testgres.get_new_node().init().start() + +# execute a few queries +node1.execute('select 1') +node2.execute('select 2') + +# disable logging +testgres.configure_testgres(use_python_logging=False) +``` + +Look at `tests/test_simple.py` file for a complete example of the logging +configuration. + + +### Backup & replication + +It's quite easy to create a backup and start a new replica: + +```python +with testgres.get_new_node('master') as master: + master.init().start() + + # create a backup + with master.backup() as backup: + + # create and start a new replica + replica = backup.spawn_replica('replica').start() + + # catch up with master node + replica.catchup() + + # execute a dummy query + print(replica.execute('postgres', 'select 1')) +``` + +### Benchmarks + +`testgres` is also capable of running benchmarks using `pgbench`: + +```python +with testgres.get_new_node('master') as master: + # start a new node + master.init().start() + + # initialize default DB and run bench for 10 seconds + res = master.pgbench_init(scale=2).pgbench_run(time=10) + print(res) +``` + + +### Custom configuration + +It's often useful to extend default configuration provided by `testgres`. + +`testgres` has `default_conf()` function that helps control some basic +options. The `append_conf()` function can be used to add custom +lines to configuration lines: + +```python +ext_conf = "shared_preload_libraries = 'postgres_fdw'" + +# initialize a new node +with testgres.get_new_node().init() as master: + + # ... do something ... + + # reset main config file + master.default_conf(fsync=True, + allow_streaming=True) + + # add a new config line + master.append_conf('postgresql.conf', ext_conf) +``` + +Note that `default_conf()` is called by `init()` function; both of them overwrite +the configuration file, which means that they should be called before `append_conf()`. + + +## Authors + +[Ildar Musin](https://github.com/zilder) +[Dmitry Ivanov](https://github.com/funbringer) +[Ildus Kurbangaliev](https://github.com/ildus) +[Yury Zhuravlev](https://github.com/stalkerg) + + + + +%prep +%autosetup -n testgres-1.8.7 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-testgres -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Mon May 15 2023 Python_Bot - 1.8.7-1 +- Package Spec generated diff --git a/sources b/sources new file mode 100644 index 0000000..a2be701 --- /dev/null +++ b/sources @@ -0,0 +1 @@ +3bcd16bfa514502da76993a79c795cb4 testgres-1.8.7.tar.gz -- cgit v1.2.3