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

Add PostgresNode.__repr__() method#44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
funbringer merged 3 commits intopostgrespro:masterfromzilder:node_repr
Mar 22, 2018
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
Added PostgresNode.__repr__() method and fix doctests
  • Loading branch information
@zilder
zilder committedMar 21, 2018
commit57eaea1178b2d95f9952f38f09d0a2002becde72
12 changes: 6 additions & 6 deletionstestgres/api.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,27 +7,27 @@
edit configuration files, start/stop cluster, execute queries. The
typical flow may look like:
>>> with get_new_node() as node:
>>> with get_new_node('test') as node:
Copy link
Collaborator

@funbringerfunbringerMar 21, 2018
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

IMHO it's better to have at least one example with no args at all. It would show user that literally every arg ofget_new_node() has a decent default.

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Fair enough

... node.init().start()
... result = node.safe_psql('postgres', 'select 1')
... print(result.decode('utf-8').strip())
... node.stop()
<testgres.node.PostgresNode object at 0x...>
PostgresNode('test', port=..., base_dir=...)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I believe that'test' should be prefixed byname=.

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I personally disagree as it makes the whole output 5 symbols larger, but I can make my peace with that : )

1
<testgres.node.PostgresNode object at 0x...>
PostgresNode('test', port=..., base_dir=...)
Or:
>>> with get_new_node() as master:
>>> with get_new_node('master') as master:
... master.init().start()
... with master.backup() as backup:
... with backup.spawn_replica() as replica:
... with backup.spawn_replica('replica') as replica:
... replica = replica.start()
... master.execute('postgres', 'create table test (val int4)')
... master.execute('postgres', 'insert into test values (0), (1), (2)')
... replica.catchup() # wait until changes are visible
... print(replica.execute('postgres', 'select count(*) from test'))
<testgres.node.PostgresNode object at 0x...>
PostgresNode('master', port=..., base_dir=...)
[(3,)]
Copyright (c) 2016, Postgres Professional
Expand Down
2 changes: 2 additions & 0 deletionstestgres/config.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -152,9 +152,11 @@ def scoped_config(**options):
Temporarily set custom GlobalConfig options for this context.

Example:
>>> from .api import get_new_node
>>> with scoped_config(cache_initdb=False):
... with get_new_node().init().start() as node:
... print(node.execute('select 1'))
[(1,)]
"""

try:
Expand Down
4 changes: 4 additions & 0 deletionstestgres/node.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -135,6 +135,10 @@ def __exit__(self, type, value, traceback):
else:
self._try_shutdown(attempts)

def __repr__(self):
return "PostgresNode('{}', port={}, base_dir={})".format(
self.name, self.port, self.base_dir)

@property
def pid(self):
"""
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp