Skip to content

Commit 89e516f

Browse files
authored
Make JS's inability to distinguish number types a feature flag (#632)
See also: * neo4j/neo4j-javascript-driver#1228
1 parent 3a507ac commit 89e516f

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

nutkit/protocol/feature.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ class Feature(Enum):
200200
# configuration as long as values match.
201201
DETAIL_DEFAULT_SECURITY_CONFIG_VALUE_EQUALITY = \
202202
"Detail:DefaultSecurityConfigValueEquality"
203+
# The driver cannot differentiate between integer and float numbers.
204+
# I.e., JavaScript :P
205+
DETAIL_NUMBER_IS_NUMBER = "Detail:NumberIsNumber"
203206

204207
# === CONFIGURATION HINTS (BOLT 4.3+) ===
205208
# The driver understands and follow the connection hint

tests/neo4j/datatypes/test_datatypes.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,29 @@ def test_should_echo_back(self):
5353

5454
self._create_driver_and_session()
5555
for val in vals:
56+
if self.driver_supports_features(
57+
types.Feature.DETAIL_NUMBER_IS_NUMBER
58+
):
59+
if (
60+
isinstance(val, types.CypherFloat)
61+
and float(val.value) % 1 == 0
62+
):
63+
continue
5664
# TODO: remove this block once all languages work
57-
if get_driver_name() in ["javascript", "dotnet"]:
65+
if get_driver_name() in ["dotnet"]:
5866
# Driver treats float as int
59-
if (isinstance(val, types.CypherFloat)
60-
and float(val.value) % 1 == 0):
67+
if (
68+
isinstance(val, types.CypherFloat)
69+
and float(val.value) % 1 == 0
70+
):
6171
continue
6272
# TODO: remove this block once all languages work
6373
if get_driver_name() in ["java", "javascript", "go", "dotnet"]:
6474
# driver backend does not implement special float values
65-
if (isinstance(val, types.CypherFloat)
66-
and isinstance(val.value, str)):
75+
if (
76+
isinstance(val, types.CypherFloat)
77+
and isinstance(val.value, str)
78+
):
6779
continue
6880
# TODO: remove this block once all languages work
6981
if get_driver_name() in ["java", "javascript", "go", "dotnet"]:

tests/neo4j/datatypes/test_spatial_types.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ def test_point_components(self):
3434
("longitude", "latitude", "height")
3535
),
3636
):
37+
if self.driver_supports_features(
38+
types.Feature.DETAIL_NUMBER_IS_NUMBER
39+
):
40+
coords = tuple(c if c % 1 != 0 else c + 0.23 for c in coords)
3741
with self.subTest(system=system, coords=coords, names=names):
3842
self._create_driver_and_session()
3943
point = types.CypherPoint(system, *coords)

0 commit comments

Comments
 (0)