From 29bfd07dad9a4d4b90bd0838a3146dd054b119a3 Mon Sep 17 00:00:00 2001 From: James Campbell Date: Mon, 14 Jul 2025 01:58:08 -0400 Subject: [PATCH] Run code through black --- src/pgmon.py | 13 ++++++++++--- src/test_pgmon.py | 16 ++++++++-------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/pgmon.py b/src/pgmon.py index 2b72169..e5bd3fb 100755 --- a/src/pgmon.py +++ b/src/pgmon.py @@ -400,7 +400,7 @@ def json_encode_special(obj): """ if isinstance(obj, Decimal): 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): @@ -424,7 +424,9 @@ def run_query_no_retry(pool, return_type, query, args): elif return_type == "column": if len(res) == 0: 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": return json.dumps(res, default=json_encode_special) except: @@ -667,7 +669,12 @@ def test_queries(): for name, metric in config["metrics"].items(): # If the metric has arguments to use while testing, grab those 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 # before the service is truly up (it restarts during the initialization # phase). To cope with this, we'll allow a few connection failures. diff --git a/src/test_pgmon.py b/src/test_pgmon.py index 1a86492..534f8ba 100644 --- a/src/test_pgmon.py +++ b/src/test_pgmon.py @@ -795,17 +795,17 @@ metrics: def test_json_encode_special(self): # Confirm that we're getting the right type - self.assertFalse(isinstance(Decimal('0.5'), float)) - self.assertTrue(isinstance(pgmon.json_encode_special(Decimal('0.5')), float)) + self.assertFalse(isinstance(Decimal("0.5"), float)) + self.assertTrue(isinstance(pgmon.json_encode_special(Decimal("0.5")), float)) # Make sure we get sane values - 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("0.5")), 0.5) + self.assertEqual(pgmon.json_encode_special(Decimal("12")), 12.0) # Make sure we can still fail for other types - self.assertRaises( - TypeError, pgmon.json_encode_special, object - ) + self.assertRaises(TypeError, pgmon.json_encode_special, object) # 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" + )