Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7d724ac

Browse files
authored
Merge pull request #44 from zilder/node_repr
Add PostgresNode.__repr__() method
2 parents b4051cf + 749de80 commit 7d724ac

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

testgres/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
... result = node.safe_psql('postgres', 'select 1')
1313
... print(result.decode('utf-8').strip())
1414
... node.stop()
15-
<testgres.node.PostgresNode object at 0x...>
15+
PostgresNode(name='...', port=..., base_dir='...')
1616
1
17-
<testgres.node.PostgresNode object at 0x...>
17+
PostgresNode(name='...', port=..., base_dir='...')
1818
1919
Or:
2020
@@ -27,7 +27,7 @@
2727
... master.execute('postgres', 'insert into test values (0), (1), (2)')
2828
... replica.catchup() # wait until changes are visible
2929
... print(replica.execute('postgres', 'select count(*) from test'))
30-
<testgres.node.PostgresNode object at 0x...>
30+
PostgresNode(name='...', port=..., base_dir='...')
3131
[(3,)]
3232
3333
Copyright (c) 2016, Postgres Professional

testgres/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,11 @@ def scoped_config(**options):
152152
Temporarily set custom GlobalConfig options for this context.
153153
154154
Example:
155+
>>> from .api import get_new_node
155156
>>> with scoped_config(cache_initdb=False):
156157
... with get_new_node().init().start() as node:
157158
... print(node.execute('select 1'))
159+
[(1,)]
158160
"""
159161

160162
try:

testgres/node.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ def __exit__(self, type, value, traceback):
136136
else:
137137
self._try_shutdown(attempts)
138138

139+
def __repr__(self):
140+
return "{}(name='{}', port={}, base_dir='{}')".format(
141+
self.__class__.__name__, self.name, self.port, self.base_dir)
142+
139143
@property
140144
def pid(self):
141145
"""

tests/test_simple.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# coding: utf-8
33

44
import os
5+
import re
56
import subprocess
67
import tempfile
78
import testgres
@@ -70,6 +71,11 @@ def removing(f):
7071

7172

7273
class TestgresTests(unittest.TestCase):
74+
def test_node_repr(self):
75+
with get_new_node() as node:
76+
pattern = 'PostgresNode\(name=\'.+\', port=.+, base_dir=\'.+\'\)'
77+
self.assertIsNotNone(re.match(pattern, str(node)))
78+
7379
def test_custom_init(self):
7480
with get_new_node() as node:
7581
# enable page checksums

0 commit comments

Comments
 (0)