diff --git a/testgres/testgres.py b/testgres/testgres.py index d40d51fa..2bcbbd4f 100644 --- a/testgres/testgres.py +++ b/testgres/testgres.py @@ -23,7 +23,7 @@ import os import random -import socket +# import socket import subprocess import pwd import tempfile @@ -31,7 +31,7 @@ import time import six -# Try to use psycopg2 by default. If psycopg2 isn"t available then use +# Try to use psycopg2 by default. If psycopg2 isn"t available then use # pg8000 which is slower but much more portable because uses only # pure-Python code try: @@ -44,21 +44,28 @@ registered_nodes = [] -last_assigned_port = int(random.random() * 16384) + 49152; +last_assigned_port = int(random.random() * 16384) + 49152 pg_config_data = {} -""" -Predefined exceptions -""" -class ClusterException(Exception): pass -class QueryException(Exception): pass +class ClusterException(Exception): + """ + Predefined exceptions + """ + pass + + +class QueryException(Exception): + """ + Predefined exceptions + """ + pass -""" -Transaction wrapper returned by Node -""" class NodeConnection(object): + """ + Transaction wrapper returned by Node + """ def __init__(self, parent_node, dbname): self.parent_node = parent_node @@ -78,21 +85,22 @@ def __exit__(self, type, value, tb): self.connection.close() def begin(self, isolation_level=0): - levels = [ 'read uncommitted', - 'read committed', - 'repeatable read', - 'serializable' ] + levels = ['read uncommitted', + 'read committed', + 'repeatable read', + 'serializable'] + print(type(isolation_level)) # Check if level is int [0..3] - if isinstance(isolation_level, int) and \ - isolation_level in range(0, 4): + if (isinstance(isolation_level, int) and + isolation_level in range(0, 4)): # Replace index with isolation level type isolation_level = levels[isolation_level] # Or it might be a string - elif isinstance(isolation_level, str) and \ - str.lower(isolation_level) in levels: + elif (isinstance(isolation_level, six.text_type) and + isolation_level.lower() in levels): # Nothing to do here pass @@ -148,13 +156,13 @@ def error_filename(self): @property def connstr(self): - return "port=%s" % self.port + return "port=%s" % self.port # return "port=%s host=%s" % (self.port, self.host) def get_bin_path(self, filename): """ Returns full path to an executable """ pg_config = get_config() - if not "BINDIR" in pg_config: + if "BINDIR" not in pg_config: return filename else: return "%s/%s" % (pg_config.get("BINDIR"), filename) @@ -403,6 +411,7 @@ def get_username(): """ Returns current user name """ return pwd.getpwuid(os.getuid())[0] + def get_config(): global pg_config_data @@ -422,6 +431,7 @@ def get_config(): return pg_config_data + def version_to_num(version): """Converts PostgreSQL version to number for easier comparison""" import re @@ -429,12 +439,14 @@ def version_to_num(version): if not version: return 0 parts = version.split(".") - while len(parts) < 3: parts.append("0") + while len(parts) < 3: + parts.append("0") num = 0 for part in parts: num = num*100 + int(re.sub("[^\d]", "", part)) return num + def get_new_node(name): global registered_nodes global last_assigned_port @@ -462,12 +474,14 @@ def get_new_node(name): return node + def clean_all(): global registered_nodes for node in registered_nodes: node.cleanup() registered_nodes = [] + def stop_all(): global registered_nodes for node in registered_nodes: diff --git a/testgres/tests/test_simple.py b/testgres/tests/test_simple.py index 76838886..e59be4be 100644 --- a/testgres/tests/test_simple.py +++ b/testgres/tests/test_simple.py @@ -1,6 +1,8 @@ import unittest -import time -from testgres import get_new_node, clean_all, stop_all +# import time +# from testgres import clean_all +from testgres import get_new_node, stop_all + class SimpleTest(unittest.TestCase):