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

Simplified enums#33

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
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
simplified enums NodeStatus and IsolationLevel
  • Loading branch information
@Valeria1235
Valeria1235 committedFeb 6, 2018
commitcf03ee25ee0638c5755dc21df409fafe9326697b
35 changes: 10 additions & 25 deletionstestgres/connection.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,7 +27,10 @@ class IsolationLevel(Enum):
Transaction isolation level for NodeConnection
"""

ReadUncommitted, ReadCommitted, RepeatableRead, Serializable = range(4)
ReadUncommitted = 'read uncommitted'
ReadCommitted = 'read committed'
RepeatableRead = 'repeatable read'
Serializable = 'serializable'


class NodeConnection(object):
Expand DownExpand Up@@ -71,39 +74,21 @@ def __exit__(self, type, value, traceback):
self.close()

def begin(self, isolation_level=IsolationLevel.ReadCommitted):
# yapf: disable
levels = [
'read uncommitted',
'read committed',
'repeatable read',
'serializable'
]

# Check if level is an IsolationLevel
if (isinstance(isolation_level, IsolationLevel)):

# Get index of isolation level
level_idx = isolation_level.value
assert level_idx in range(4)

# Replace isolation level with its name
isolation_level = levels[level_idx]

else:
# Check if level isn't an IsolationLevel
if not isinstance(isolation_level, IsolationLevel):
# Get name of isolation level
level_str = str(isolation_level).lower()

# Validate level string
if level_str not in levels:
try:
isolation_level = IsolationLevel(level_str)
except ValueError:
error = 'Invalid isolation level "{}"'
raise QueryException(error.format(level_str))

# Replace isolation level with its name
isolation_level = level_str

# Set isolation level
cmd = 'SET TRANSACTION ISOLATION LEVEL {}'
self.cursor.execute(cmd.format(isolation_level))
self.cursor.execute(cmd.format(isolation_level.value))

return self

Expand Down
6 changes: 3 additions & 3 deletionstestgres/node.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,7 +8,7 @@
import tempfile
import time

from enum importEnum
from enum importIntEnum
from six import raise_from

from .cache import cached_initdb
Expand DownExpand Up@@ -53,7 +53,7 @@
positional_args_hack


class NodeStatus(Enum):
class NodeStatus(IntEnum):
"""
Status of a PostgresNode
"""
Expand All@@ -62,7 +62,7 @@ class NodeStatus(Enum):

# for Python 3.x
def __bool__(self):
return self.value == NodeStatus.Running.value
return self == NodeStatus.Running

# for Python 2.x
__nonzero__ = __bool__
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp