Skip to content

Commit acfc3fa

Browse files
authored
Merge pull request #2 from stalkerg/master
PEP8 cleanups
2 parents a8ae5b6 + 76e21ff commit acfc3fa

File tree

2 files changed

+40
-24
lines changed

2 files changed

+40
-24
lines changed

testgres/testgres.py

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323

2424
import os
2525
import random
26-
import socket
26+
# import socket
2727
import subprocess
2828
import pwd
2929
import tempfile
3030
import shutil
3131
import time
3232
import six
3333

34-
# Try to use psycopg2 by default. If psycopg2 isn"t available then use
34+
# Try to use psycopg2 by default. If psycopg2 isn"t available then use
3535
# pg8000 which is slower but much more portable because uses only
3636
# pure-Python code
3737
try:
@@ -44,21 +44,28 @@
4444

4545

4646
registered_nodes = []
47-
last_assigned_port = int(random.random() * 16384) + 49152;
47+
last_assigned_port = int(random.random() * 16384) + 49152
4848
pg_config_data = {}
4949

5050

51-
"""
52-
Predefined exceptions
53-
"""
54-
class ClusterException(Exception): pass
55-
class QueryException(Exception): pass
51+
class ClusterException(Exception):
52+
"""
53+
Predefined exceptions
54+
"""
55+
pass
56+
57+
58+
class QueryException(Exception):
59+
"""
60+
Predefined exceptions
61+
"""
62+
pass
5663

5764

58-
"""
59-
Transaction wrapper returned by Node
60-
"""
6165
class NodeConnection(object):
66+
"""
67+
Transaction wrapper returned by Node
68+
"""
6269
def __init__(self, parent_node, dbname):
6370
self.parent_node = parent_node
6471

@@ -78,21 +85,22 @@ def __exit__(self, type, value, tb):
7885
self.connection.close()
7986

8087
def begin(self, isolation_level=0):
81-
levels = [ 'read uncommitted',
82-
'read committed',
83-
'repeatable read',
84-
'serializable' ]
88+
levels = ['read uncommitted',
89+
'read committed',
90+
'repeatable read',
91+
'serializable']
8592

93+
print(type(isolation_level))
8694
# Check if level is int [0..3]
87-
if isinstance(isolation_level, int) and \
88-
isolation_level in range(0, 4):
95+
if (isinstance(isolation_level, int) and
96+
isolation_level in range(0, 4)):
8997

9098
# Replace index with isolation level type
9199
isolation_level = levels[isolation_level]
92100

93101
# Or it might be a string
94-
elif isinstance(isolation_level, str) and \
95-
str.lower(isolation_level) in levels:
102+
elif (isinstance(isolation_level, six.text_type) and
103+
isolation_level.lower() in levels):
96104

97105
# Nothing to do here
98106
pass
@@ -148,13 +156,13 @@ def error_filename(self):
148156

149157
@property
150158
def connstr(self):
151-
return "port=%s" % self.port
159+
return "port=%s" % self.port
152160
# return "port=%s host=%s" % (self.port, self.host)
153161

154162
def get_bin_path(self, filename):
155163
""" Returns full path to an executable """
156164
pg_config = get_config()
157-
if not "BINDIR" in pg_config:
165+
if "BINDIR" not in pg_config:
158166
return filename
159167
else:
160168
return "%s/%s" % (pg_config.get("BINDIR"), filename)
@@ -403,6 +411,7 @@ def get_username():
403411
""" Returns current user name """
404412
return pwd.getpwuid(os.getuid())[0]
405413

414+
406415
def get_config():
407416
global pg_config_data
408417

@@ -422,19 +431,22 @@ def get_config():
422431

423432
return pg_config_data
424433

434+
425435
def version_to_num(version):
426436
"""Converts PostgreSQL version to number for easier comparison"""
427437
import re
428438

429439
if not version:
430440
return 0
431441
parts = version.split(".")
432-
while len(parts) < 3: parts.append("0")
442+
while len(parts) < 3:
443+
parts.append("0")
433444
num = 0
434445
for part in parts:
435446
num = num*100 + int(re.sub("[^\d]", "", part))
436447
return num
437448

449+
438450
def get_new_node(name):
439451
global registered_nodes
440452
global last_assigned_port
@@ -462,12 +474,14 @@ def get_new_node(name):
462474

463475
return node
464476

477+
465478
def clean_all():
466479
global registered_nodes
467480
for node in registered_nodes:
468481
node.cleanup()
469482
registered_nodes = []
470483

484+
471485
def stop_all():
472486
global registered_nodes
473487
for node in registered_nodes:

testgres/tests/test_simple.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import unittest
2-
import time
3-
from testgres import get_new_node, clean_all, stop_all
2+
# import time
3+
# from testgres import clean_all
4+
from testgres import get_new_node, stop_all
5+
46

57
class SimpleTest(unittest.TestCase):
68

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy