diff --git a/src/cosl/grafana_dashboard.py b/src/cosl/grafana_dashboard.py index ca41e62..aab13ac 100644 --- a/src/cosl/grafana_dashboard.py +++ b/src/cosl/grafana_dashboard.py @@ -8,8 +8,8 @@ import json import logging import lzma -from typing import Any, Dict, Union import warnings +from typing import Any, Dict, Tuple, Union logger = logging.getLogger(__name__) @@ -23,11 +23,17 @@ class GrafanaDashboard(str): @staticmethod def _serialize(raw_json: Union[str, bytes]) -> "GrafanaDashboard": - warnings.warn("GrafanaDashboard._serialize is deprecated; use LZMABase64.compress(json.dumps(...)) instead.", category=DeprecationWarning) + warnings.warn( + "GrafanaDashboard._serialize is deprecated; use LZMABase64.compress(json.dumps(...)) instead.", + category=DeprecationWarning, + ) return GrafanaDashboard(LZMABase64.compress(raw_json)) def _deserialize(self) -> Dict[str, Any]: - warnings.warn("GrafanaDashboard._deserialize is deprecated; use json.loads(LZMABase64.decompress(...)) instead.", category=DeprecationWarning) + warnings.warn( + "GrafanaDashboard._deserialize is deprecated; use json.loads(LZMABase64.decompress(...)) instead.", + category=DeprecationWarning, + ) try: return json.loads(LZMABase64.decompress(self)) except json.decoder.JSONDecodeError as e: @@ -58,7 +64,7 @@ def decompress(cls, compressed: str) -> str: return lzma.decompress(base64.b64decode(compressed.encode("utf-8"))).decode() -def _hash(components: tuple, length: int) -> str: +def _hash(components: Tuple[str, ...], length: int) -> str: return hashlib.shake_256("-".join(components).encode("utf-8")).hexdigest(length) diff --git a/tests/test_grafana_dashboard.py b/tests/test_grafana_dashboard.py index 1f1029a..fcdfac3 100644 --- a/tests/test_grafana_dashboard.py +++ b/tests/test_grafana_dashboard.py @@ -31,7 +31,7 @@ class TestGenerateUID(unittest.TestCase): """Spec for the UID generation logic.""" def test_uid_length_is_40(self): - self.assertEqual(40, len(generate_dashboard_uid("whatever"))) + self.assertEqual(40, len(generate_dashboard_uid("my-charm", "my-dash.json"))) def test_collisions(self): """A very naive and primitive collision check that is meant to catch trivial errors.""" @@ -41,6 +41,6 @@ def test_collisions(self): ) self.assertNotEqual( - generate_dashboard_uid("some-charm"), generate_dashboard_uid("some-charm", "dashboard.json"), + generate_dashboard_uid("diff-charm", "dashboard.json"), )