From 7962d4436a6060a4ab00c02ace549daeeb4bcb55 Mon Sep 17 00:00:00 2001 From: Luis Helder Date: Tue, 17 Oct 2023 15:53:59 -0300 Subject: [PATCH] style: use single quotation marks in the code --- hathor/healthcheck/models.py | 42 +++++++++---------- hathor/healthcheck/resources/healthcheck.py | 6 +-- .../resources/healthcheck/test_healthcheck.py | 10 ++--- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/hathor/healthcheck/models.py b/hathor/healthcheck/models.py index 5ad252292..c75457720 100644 --- a/hathor/healthcheck/models.py +++ b/hathor/healthcheck/models.py @@ -8,17 +8,17 @@ class ComponentType(str, Enum): """Enum used to store the component types that can be used in the HealthCheckComponentStatus class.""" - DATASTORE = "datastore" - INTERNAL = "internal" - FULLNODE = "fullnode" + DATASTORE = 'datastore' + INTERNAL = 'internal' + FULLNODE = 'fullnode' class HealthCheckStatus(str, Enum): """Enum used to store the component status that can be used in the HealthCheckComponentStatus class.""" - PASS = "pass" - WARN = "warn" - FAIL = "fail" + PASS = 'pass' + WARN = 'warn' + FAIL = 'fail' @dataclass @@ -35,29 +35,29 @@ class ComponentHealthCheck: observed_unit: Optional[str] = None def __post_init__(self) -> None: - self.time = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ") + self.time = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ') def to_json(self) -> dict[str, str]: """Return a dict representation of the object. All field names are converted to camel case.""" json = { - "componentType": self.component_type.value, - "status": self.status.value, - "output": self.output, + 'componentType': self.component_type.value, + 'status': self.status.value, + 'output': self.output, } if self.time: - json["time"] = self.time + json['time'] = self.time if self.component_id: - json["componentId"] = self.component_id + json['componentId'] = self.component_id if self.observed_value: assert ( self.observed_unit is not None - ), "observed_unit must be set if observed_value is set" + ), 'observed_unit must be set if observed_value is set' - json["observedValue"] = self.observed_value - json["observedUnit"] = self.observed_unit + json['observedValue'] = self.observed_value + json['observedUnit'] = self.observed_unit return json @@ -71,7 +71,7 @@ class ServiceHealthCheck: @property def status(self) -> HealthCheckStatus: - "Return the status of the health check based on the status of the components." + """Return the status of the health check based on the status of the components.""" status = HealthCheckStatus.PASS for component_checks in self.checks.values(): @@ -87,7 +87,7 @@ def __post_init__(self) -> None: """Perform some validations after the object is initialized.""" # Make sure the checks dict is not empty if not self.checks: - raise ValueError("checks dict cannot be empty") + raise ValueError('checks dict cannot be empty') def get_http_status_code(self) -> int: """Return the HTTP status code for the status.""" @@ -96,14 +96,14 @@ def get_http_status_code(self) -> int: elif self.status in [HealthCheckStatus.WARN, HealthCheckStatus.FAIL]: return 503 else: - raise ValueError(f"Missing treatment for status {self.status}") + raise ValueError(f'Missing treatment for status {self.status}') def to_json(self) -> dict[str, Any]: """Return a dict representation of the object. All field names are converted to camel case.""" return { - "status": self.status.value, - "description": self.description, - "checks": {k: [c.to_json() for c in v] for k, v in self.checks.items()}, + 'status': self.status.value, + 'description': self.description, + 'checks': {k: [c.to_json() for c in v] for k, v in self.checks.items()}, } diff --git a/hathor/healthcheck/resources/healthcheck.py b/hathor/healthcheck/resources/healthcheck.py index 22545cd00..2cdc29cd9 100644 --- a/hathor/healthcheck/resources/healthcheck.py +++ b/hathor/healthcheck/resources/healthcheck.py @@ -11,10 +11,10 @@ def build_sync_health_status(manager: HathorManager) -> ComponentHealthCheck: healthy, reason = manager.is_sync_healthy() return ComponentHealthCheck( - component_name="sync", + component_name='sync', component_type=ComponentType.INTERNAL, status=HealthCheckStatus.PASS if healthy else HealthCheckStatus.FAIL, - output=reason or "Healthy", + output=reason or 'Healthy', ) @@ -43,7 +43,7 @@ def render_GET(self, request): ] health_check = ServiceHealthCheck( - description=f"Hathor-core {hathor.__version__}", + description=f'Hathor-core {hathor.__version__}', checks={c.component_name: [c] for c in components_health_checks}, ) diff --git a/tests/resources/healthcheck/test_healthcheck.py b/tests/resources/healthcheck/test_healthcheck.py index bbc24d180..888aac2af 100644 --- a/tests/resources/healthcheck/test_healthcheck.py +++ b/tests/resources/healthcheck/test_healthcheck.py @@ -21,7 +21,7 @@ def setUp(self): def test_get_no_recent_activity(self): """Scenario where the node doesn't have a recent block """ - response = yield self.web.get("/health") + response = yield self.web.get('/health') data = response.json_value() self.assertEqual(response.responseCode, 503) @@ -43,7 +43,7 @@ def test_strict_status_code(self): """Make sure the 'strict_status_code' parameter is working. The node should return 200 even if it's not ready. """ - response = yield self.web.get("/health", {b'strict_status_code': b'1'}) + response = yield self.web.get('/health', {b'strict_status_code': b'1'}) data = response.json_value() self.assertEqual(response.responseCode, 200) @@ -69,7 +69,7 @@ def test_get_no_connected_peer(self): self.assertEqual(self.manager.has_recent_activity(), True) - response = yield self.web.get("/health") + response = yield self.web.get('/health') data = response.json_value() self.assertEqual(response.responseCode, 503) @@ -101,7 +101,7 @@ def test_get_peer_out_of_sync(self): self.assertEqual(self.manager2.state, self.manager2.NodeState.READY) - response = yield self.web.get("/health") + response = yield self.web.get('/health') data = response.json_value() self.assertEqual(response.responseCode, 503) @@ -133,7 +133,7 @@ def test_get_ready(self): self.conn1.run_one_step(debug=True) self.clock.advance(0.1) - response = yield self.web.get("/health") + response = yield self.web.get('/health') data = response.json_value() self.assertEqual(response.responseCode, 200)