Skip to content

Commit c4c0b96

Browse files
committed
update documentation
1 parent b56c7cb commit c4c0b96

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

README.md

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,38 @@ To install `testgres`, run:
1414
pip install testgres
1515
```
1616

17-
We encourage you to use `virtualenv` for your testing environment. Both Python 2.7 and 3.5 are supported.
17+
We encourage you to use `virtualenv` for your testing environment. Both Python 2.7 and 3.3+ are supported.
1818

1919

2020
## Usage
2121

22-
> Note: by default testgres runs `initdb`, `pg_ctl`, `psql` provided by `$PATH`. To specify a custom postgres installation, set the environment variable `$PG_CONFIG` pointing to the `pg_config` executable: `export PG_CONFIG=/path/to/pg_config`.
22+
> Note: by default testgres runs `initdb`, `pg_ctl`, `psql` provided by `PATH`. To specify a custom postgres installation, set the environment variable `PG_CONFIG` pointing to the `pg_config` executable: `export PG_CONFIG=/path/to/pg_config`.
2323
2424
Here is an example of what you can do with `testgres`:
2525

2626
```python
2727
import testgres
2828

29-
node = None
30-
try:
31-
node = testgres.get_new_node('test').init().start()
29+
with testgres.get_new_node('test') as node:
30+
node.init() # run initdb
31+
node.start() # start PostgreSQL
3232
print(node.execute('postgres', 'select 1'))
33-
except testgres.ClusterException as e:
34-
print(e)
35-
finally:
36-
if node is not None:
37-
node.cleanup()
33+
node.stop() # stop PostgreSQL
3834
```
3935

40-
Let's walk through the code. First you create new node:
36+
Let's walk through the code. First, you create a new node using:
4137

4238
```python
43-
node = testgres.get_new_node('master')
39+
with testgres.get_new_node('master') as node:
4440
```
4541

46-
or:
42+
or
4743

4844
```python
49-
node = testgres.get_new_node('master', '/path/to/base')
45+
with testgres.get_new_node('master', '/path/to/DB') as node:
5046
```
5147

52-
`master` is a node's name, not the DB's name. The name matters if you're testing something like replication. Function `get_new_node()` only creates directory structure in specified directory (or somewhere in '/tmp' if we did not specify base directory) for cluster. After that, we have to initialize the PostgreSQL cluster:
48+
where `master` is a node's name, not a DB's name. Name matters if you're testing something like replication. Function `get_new_node()` only creates directory structure in specified directory (or somewhere in '/tmp' if we did not specify base directory) for cluster. After that, we have to initialize the PostgreSQL cluster:
5349

5450
```python
5551
node.init()

testgres/testgres.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,12 @@
88
edit configuration files, start/stop cluster, execute queries. The
99
typical flow may look like:
1010
11-
try:
12-
node = get_new_node('test')
11+
with get_new_node('test') as node:
1312
node.init()
1413
node.start()
15-
stdout = node.psql('postgres', 'SELECT 1')
16-
print stdout
14+
result = node.psql('postgres', 'SELECT 1')
15+
print(result)
1716
node.stop()
18-
except ClusterException, e:
19-
node.cleanup()
2017
2118
Copyright (c) 2016, Postgres Professional
2219
"""

0 commit comments

Comments
 (0)