Fix a regression framework issue with Python 2.6.

This commit is contained in:
Navnath Gadakh 2017-04-10 11:28:10 +01:00 committed by Dave Page
parent 024b97479d
commit 79e81478e3
2 changed files with 31 additions and 24 deletions

View File

@ -120,7 +120,8 @@ def create_database(server, db_name):
old_isolation_level = connection.isolation_level
connection.set_isolation_level(0)
pg_cursor = connection.cursor()
pg_cursor.execute('''CREATE DATABASE "%s" TEMPLATE template0''' % db_name)
pg_cursor.execute(
'''CREATE DATABASE "%s" TEMPLATE template0''' % db_name)
connection.set_isolation_level(old_isolation_level)
connection.commit()
@ -147,8 +148,10 @@ def create_table(server, db_name, table_name):
old_isolation_level = connection.isolation_level
connection.set_isolation_level(0)
pg_cursor = connection.cursor()
pg_cursor.execute('''CREATE TABLE "%s" (some_column VARCHAR, value NUMERIC)''' % table_name)
pg_cursor.execute('''INSERT INTO "%s" VALUES ('Some-Name', 6)''' % table_name)
pg_cursor.execute(
'''CREATE TABLE "%s" (some_column VARCHAR, value NUMERIC)''' % table_name)
pg_cursor.execute(
'''INSERT INTO "%s" VALUES ('Some-Name', 6)''' % table_name)
connection.set_isolation_level(old_isolation_level)
connection.commit()
@ -164,7 +167,7 @@ def drop_database(connection, database_name):
pg_cursor.execute(
"SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity "
"WHERE pg_stat_activity.datname ='%s' AND pid <> pg_backend_pid();" % database_name
)
)
else:
pg_cursor.execute(
"SELECT pg_terminate_backend(procpid) FROM pg_stat_activity " \
@ -440,18 +443,18 @@ def get_scenario_name(cases):
result = {class_name: []}
for case_name_dict in test_case_list:
key, value = list(case_name_dict.items())[0]
if key not in {c_name for scenario in result[class_name] for
c_name in
scenario.keys()}:
class_names_dict = dict(
(c_name, "") for scenario in result[class_name] for
c_name in scenario.keys())
if key not in class_names_dict:
result[class_name].append(case_name_dict)
test_cases_dict_json.update(result)
test_cases_dict.update({class_name: list({case for test_case in
test_case_list
for case in test_case})})
test_cases_list = list(dict((case, "") for test_case in test_case_list
for case in test_case))
test_cases_dict.update({class_name: test_cases_list})
return test_cases_dict, test_cases_dict_json
class Database:
"""
Temporarily create and connect to a database, tear it down at exit
@ -462,6 +465,7 @@ class Database:
connection.cursor().execute(...)
"""
def __init__(self, server):
self.name = None
self.server = server
@ -471,8 +475,10 @@ class Database:
def __enter__(self):
self.name = "test_db_{0}".format(str(uuid.uuid4())[0:7])
self.maintenance_connection = get_db_connection(self.server['db'],
self.server['username'],
self.server['db_password'],
self.server[
'username'],
self.server[
'db_password'],
self.server['host'],
self.server['port'])
create_database(self.server, self.name)

View File

@ -73,7 +73,7 @@ if pgadmin_credentials:
'login_password']
# Execute the setup file
exec(open("setup.py").read())
exec (open("setup.py").read())
# Get the config database schema version. We store this in pgadmin.model
# as it turns out that putting it in the config files isn't a great idea
@ -351,13 +351,14 @@ if __name__ == '__main__':
failed_cases = test_result[server_res][1]
skipped_cases = test_result[server_res][2]
skipped_cases, skipped_cases_json = test_utils.get_scenario_name(
skipped_cases)
skipped_cases)
failed_cases, failed_cases_json = test_utils.get_scenario_name(
failed_cases)
total_failed = sum({key: len(value) for key, value in
failed_cases.items()}.values())
total_skipped = sum({key: len(value) for key, value in
skipped_cases.items()}.values())
failed_cases)
total_failed = len(dict((key, value) for key, value in
failed_cases.items()).values())
total_skipped = len(dict((key, value) for key, value in
skipped_cases.items()).values())
total_passed_cases = int(
test_result[server_res][0]) - total_failed - total_skipped
@ -368,12 +369,12 @@ if __name__ == '__main__':
(total_passed_cases != 1 and "s" or ""),
total_failed, (total_failed != 1 and "s" or ""),
(total_failed != 0 and ":\n\t\t" or ""),
"\n\t\t".join("{} ({})".format(k, ",\n\t\t\t\t\t".join(
map(str, v))) for k, v in failed_cases.items()),
"\n\t\t".join("{0} ({1})".format(key, ",\n\t\t\t\t\t".join(
map(str, value))) for key, value in failed_cases.items()),
total_skipped, (total_skipped != 1 and "s" or ""),
(total_skipped != 0 and ":\n\t\t" or ""),
"\n\t\t".join("{} ({})".format(k, ",\n\t\t\t\t\t".join(
map(str, v))) for k, v in skipped_cases.items())),
"\n\t\t".join("{0} ({1})".format(key, ",\n\t\t\t\t\t".join(
map(str, value))) for key, value in skipped_cases.items())),
file=sys.stderr)
temp_dict_for_server = {