Format python using black

This commit is contained in:
James Campbell 2025-05-15 02:04:50 -04:00
parent c872fc6b90
commit 8928bba337
Signed by: james
GPG Key ID: 2287C33A40DC906A

View File

@ -5,20 +5,22 @@ import requests
import yaml import yaml
import sys import sys
pg_versions=[9.2, 9.6, 10, 11, 12, 13, 14, 15, 16 17] pg_versions = [9.2, 9.6, 10, 11, 12, 13, 14, 15, 16, 17]
pgmon_port=93849 pgmon_port = 93849
tests = {} tests = {}
container = None container = None
def std_version(version): def std_version(version):
if version[0] == '9': if version[0] == "9":
return int(f"{version[0]}0{version[1]}00") return int(f"{version[0]}0{version[1]}00")
else else:
return int(f"{version}0000") return int(f"{version}0000")
def run_test(metric, params, status, check): def run_test(metric, params, status, check):
""" """
Validate the return code and restults of a query Validate the return code and restults of a query
@ -32,16 +34,19 @@ def run_test(metric, params, status, check):
result = requests.get(f"http://localhost:{pgmon_port}/{metric}", params=params) result = requests.get(f"http://localhost:{pgmon_port}/{metric}", params=params)
if result.status_code != status: if result.status_code != status:
print(f"FAIL: {metric}[{params}] returned wrong status code: {result.status_code}") print(
f"FAIL: {metric}[{params}] returned wrong status code: {result.status_code}"
)
return False return False
if re.match(check, result.text): if re.match(check, result.text):
print(f"SUCCESS: {metric}[{params}]") print(f"SUCCESS: {metric}[{params}]")
return True return True
else else:
print(f"FAIL: {metric}[{params}] result is invalid, got:\n {result.text}") print(f"FAIL: {metric}[{params}] result is invalid, got:\n {result.text}")
return False return False
def run_all_tests(version): def run_all_tests(version):
""" """
Run all defined tests against the current running instance Run all defined tests against the current running instance
@ -56,18 +61,18 @@ def run_all_tests(version):
# Loop through all of the metrics to test. # Loop through all of the metrics to test.
for metric in tests.keys(): for metric in tests.keys():
params = metric.get('params', {}) params = metric.get("params", {})
status = 200 status = 200
check = '' check = ""
# Find the correct version of the status and check parameters (assuming there are any). # Find the correct version of the status and check parameters (assuming there are any).
# If there are any check conditions, find the highest version that does not exceed the version we're currently testing against. # If there are any check conditions, find the highest version that does not exceed the version we're currently testing against.
# To do this, we order the keys (versions) in reverse, so we start with the highest. # To do this, we order the keys (versions) in reverse, so we start with the highest.
for v in reversed(sorted(metric.get('expect', {}).keys())): for v in reversed(sorted(metric.get("expect", {}).keys())):
# If we've reached a version <= the one we're testing use it. # If we've reached a version <= the one we're testing use it.
if int(v) <= version_num: if int(v) <= version_num:
status = metric['expect'][v]['status'] status = metric["expect"][v]["status"]
check = metric['expect'][v]['check'] check = metric["expect"][v]["check"]
break break
if not run_test(metric, metrics[metric].get(params, {}), status, check): if not run_test(metric, metrics[metric].get(params, {}), status, check):
@ -75,16 +80,15 @@ def run_all_tests(version):
return errors return errors
def start_test_db(version): def start_test_db(version):
#container = PostgresContainer() # container = PostgresContainer()
pass pass
# Read the test script # Read the test script
try: try:
with open("metric_tests.yml", 'r') as f: with open("metric_tests.yml", "r") as f:
tests = yaml.safe_load(f) tests = yaml.safe_load(f)
except yaml.parser.ParserError as e: except yaml.parser.ParserError as e:
sys.exit("Failed to parse metrics_test.yml: {e}") sys.exit("Failed to parse metrics_test.yml: {e}")
# Run