Run code through black
This commit is contained in:
parent
60589c2058
commit
29bfd07dad
13
src/pgmon.py
13
src/pgmon.py
@ -400,7 +400,7 @@ def json_encode_special(obj):
|
|||||||
"""
|
"""
|
||||||
if isinstance(obj, Decimal):
|
if isinstance(obj, Decimal):
|
||||||
return float(obj)
|
return float(obj)
|
||||||
raise TypeError(f'Cannot serialize object of {type(obj)}')
|
raise TypeError(f"Cannot serialize object of {type(obj)}")
|
||||||
|
|
||||||
|
|
||||||
def run_query_no_retry(pool, return_type, query, args):
|
def run_query_no_retry(pool, return_type, query, args):
|
||||||
@ -424,7 +424,9 @@ def run_query_no_retry(pool, return_type, query, args):
|
|||||||
elif return_type == "column":
|
elif return_type == "column":
|
||||||
if len(res) == 0:
|
if len(res) == 0:
|
||||||
return "[]"
|
return "[]"
|
||||||
return json.dumps([list(r.values())[0] for r in res], default=json_encode_special)
|
return json.dumps(
|
||||||
|
[list(r.values())[0] for r in res], default=json_encode_special
|
||||||
|
)
|
||||||
elif return_type == "set":
|
elif return_type == "set":
|
||||||
return json.dumps(res, default=json_encode_special)
|
return json.dumps(res, default=json_encode_special)
|
||||||
except:
|
except:
|
||||||
@ -667,7 +669,12 @@ def test_queries():
|
|||||||
for name, metric in config["metrics"].items():
|
for name, metric in config["metrics"].items():
|
||||||
# If the metric has arguments to use while testing, grab those
|
# If the metric has arguments to use while testing, grab those
|
||||||
args = metric.get("test_args", {})
|
args = metric.get("test_args", {})
|
||||||
print("Testing {} [{}]".format(name, ", ".join(["{}={}".format(key, value) for key, value in args.items()])))
|
print(
|
||||||
|
"Testing {} [{}]".format(
|
||||||
|
name,
|
||||||
|
", ".join(["{}={}".format(key, value) for key, value in args.items()]),
|
||||||
|
)
|
||||||
|
)
|
||||||
# When testing against a docker container, we may end up connecting
|
# When testing against a docker container, we may end up connecting
|
||||||
# before the service is truly up (it restarts during the initialization
|
# before the service is truly up (it restarts during the initialization
|
||||||
# phase). To cope with this, we'll allow a few connection failures.
|
# phase). To cope with this, we'll allow a few connection failures.
|
||||||
|
|||||||
@ -795,17 +795,17 @@ metrics:
|
|||||||
|
|
||||||
def test_json_encode_special(self):
|
def test_json_encode_special(self):
|
||||||
# Confirm that we're getting the right type
|
# Confirm that we're getting the right type
|
||||||
self.assertFalse(isinstance(Decimal('0.5'), float))
|
self.assertFalse(isinstance(Decimal("0.5"), float))
|
||||||
self.assertTrue(isinstance(pgmon.json_encode_special(Decimal('0.5')), float))
|
self.assertTrue(isinstance(pgmon.json_encode_special(Decimal("0.5")), float))
|
||||||
|
|
||||||
# Make sure we get sane values
|
# Make sure we get sane values
|
||||||
self.assertEqual(pgmon.json_encode_special(Decimal('0.5')), 0.5)
|
self.assertEqual(pgmon.json_encode_special(Decimal("0.5")), 0.5)
|
||||||
self.assertEqual(pgmon.json_encode_special(Decimal('12')), 12.0)
|
self.assertEqual(pgmon.json_encode_special(Decimal("12")), 12.0)
|
||||||
|
|
||||||
# Make sure we can still fail for other types
|
# Make sure we can still fail for other types
|
||||||
self.assertRaises(
|
self.assertRaises(TypeError, pgmon.json_encode_special, object)
|
||||||
TypeError, pgmon.json_encode_special, object
|
|
||||||
)
|
|
||||||
|
|
||||||
# Make sure we can actually serialize a Decimal
|
# Make sure we can actually serialize a Decimal
|
||||||
self.assertEqual(json.dumps(Decimal('2.5'), default=pgmon.json_encode_special), '2.5')
|
self.assertEqual(
|
||||||
|
json.dumps(Decimal("2.5"), default=pgmon.json_encode_special), "2.5"
|
||||||
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user