Skip to content

Commit 655211d

Browse files
authored
Refactor: use enum for ServerInfo.has_utc_patch (#515)
amends #513
1 parent a9ad97a commit 655211d

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

tests/neo4j/datatypes/test_temporal_types.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
)
1111
from tests.neo4j.datatypes._util import TZ_IDS
1212
from tests.neo4j.shared import get_server_info
13-
from tests.shared import get_driver_name
13+
from tests.shared import (
14+
get_driver_name,
15+
Potential,
16+
)
1417

1518

1619
class TestDataTypes(_TestTypesBase):
@@ -212,15 +215,15 @@ def work(tx):
212215
cypher_dt = types.CypherDateTime(
213216
y, mo, d, h, m, s, ns, offset, tz_id
214217
)
215-
if server_supports_utc == 1:
218+
if server_supports_utc == Potential.YES:
216219
# 5.0+ protocol sends date times in UTC
217220
# => UTC times must be equal
218221
assert_utc_equal(dt, cypher_dt)
219-
elif server_supports_utc == 0:
222+
elif server_supports_utc == Potential.NO:
220223
# 4.2- protocol sends date times in wall clock time
221224
# => Wall clock times must be equal
222225
assert_wall_time_equal(dt, cypher_dt)
223-
else:
226+
else: # Potential.MAYBE
224227
# 4.4 and 4.3 protocol sends date times in
225228
# wall clock time or UTC depending on server version,
226229
# driver version and their handshake.

tests/neo4j/shared.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
Neo4j server, default "enterprise"
1515
TEST_NEO4J_CLUSTER Whether the Neo4j server is a cluster, default "False"
1616
"""
17+
18+
1719
from functools import wraps
1820
import os
1921
import re
@@ -24,6 +26,7 @@
2426
from nutkit.protocol import AuthorizationToken
2527
from tests.shared import (
2628
dns_resolve_single,
29+
Potential,
2730
TestkitTestCase,
2831
)
2932

@@ -128,10 +131,10 @@ def max_protocol_version(self):
128131
@property
129132
def has_utc_patch(self):
130133
if self.version >= "5":
131-
return 1
134+
return Potential.YES
132135
if self.version >= "4.3":
133-
return 0.5 # maybe
134-
return 0
136+
return Potential.MAYBE
137+
return Potential.NO
135138

136139

137140
def get_server_info():

tests/shared.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212

1313
from contextlib import contextmanager
14+
import enum
1415
import functools
1516
import inspect
1617
import os
@@ -247,3 +248,10 @@ def subTest(self, **params): # noqa: N802
247248
raise Exception("Should be SkipTest, or RunTest, "
248249
"received {}: {}".format(type(response),
249250
response))
251+
252+
253+
class Potential(enum.Enum):
254+
YES = 1.0
255+
NO = 0.0
256+
MAYBE = 0.5
257+
# CAN_YOU_REPEAT_THE_QUESTION = "?"

0 commit comments

Comments
 (0)