From 043089be8629ed1d1acc80cf37e1edc0c05efa99 Mon Sep 17 00:00:00 2001 From: Rouven Bauer Date: Fri, 2 Sep 2022 16:03:30 +0200 Subject: [PATCH] Refactor: use enum for `ServerInfo.has_utc_patch` amends https://github.com/neo4j-drivers/testkit/pull/513 --- tests/neo4j/datatypes/test_temporal_types.py | 11 +++++++---- tests/neo4j/shared.py | 9 ++++++--- tests/shared.py | 8 ++++++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/tests/neo4j/datatypes/test_temporal_types.py b/tests/neo4j/datatypes/test_temporal_types.py index ed5d0a1e1..fbbaf1e7e 100644 --- a/tests/neo4j/datatypes/test_temporal_types.py +++ b/tests/neo4j/datatypes/test_temporal_types.py @@ -11,7 +11,10 @@ ) from tests.neo4j.datatypes._util import TZ_IDS from tests.neo4j.shared import get_server_info -from tests.shared import get_driver_name +from tests.shared import ( + get_driver_name, + Potential, +) class TestDataTypes(_TestTypesBase): @@ -235,15 +238,15 @@ def work(tx): cypher_dt = types.CypherDateTime( y, mo, d, h, m, s, ns, offset, tz_id ) - if server_supports_utc == 1: + if server_supports_utc == Potential.YES: # 5.0+ protocol sends date times in UTC # => UTC times must be equal assert_utc_equal(dt, cypher_dt) - elif server_supports_utc == 0: + elif server_supports_utc == Potential.NO: # 4.2- protocol sends date times in wall clock time # => Wall clock times must be equal assert_wall_time_equal(dt, cypher_dt) - else: + else: # Potential.MAYBE # 4.4 and 4.3 protocol sends date times in # wall clock time or UTC depending on server version, # driver version and their handshake. diff --git a/tests/neo4j/shared.py b/tests/neo4j/shared.py index f466398df..245ee3161 100644 --- a/tests/neo4j/shared.py +++ b/tests/neo4j/shared.py @@ -14,6 +14,8 @@ Neo4j server, default "enterprise" TEST_NEO4J_CLUSTER Whether the Neo4j server is a cluster, default "False" """ + + from functools import wraps import os import re @@ -24,6 +26,7 @@ from nutkit.protocol import AuthorizationToken from tests.shared import ( dns_resolve_single, + Potential, TestkitTestCase, ) @@ -112,10 +115,10 @@ def max_protocol_version(self): @property def has_utc_patch(self): if self.version >= "5": - return 1 + return Potential.YES if self.version >= "4.3": - return 0.5 # maybe - return 0 + return Potential.MAYBE + return Potential.NO def get_server_info(): diff --git a/tests/shared.py b/tests/shared.py index bc8071b23..3e82f0761 100644 --- a/tests/shared.py +++ b/tests/shared.py @@ -11,6 +11,7 @@ from contextlib import contextmanager +import enum import functools import inspect import os @@ -247,3 +248,10 @@ def subTest(self, **params): # noqa: N802 raise Exception("Should be SkipTest, or RunTest, " "received {}: {}".format(type(response), response)) + + +class Potential(enum.Enum): + YES = 1.0 + NO = 0.0 + MAYBE = 0.5 + # CAN_YOU_REPEAT_THE_QUESTION = "?"