Skip to content

Commit

Permalink
Data type converter: Exercise None conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Sep 7, 2022
1 parent b21c38e commit 1410547
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/crate/client/test_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_execute_with_converter(self):
# Use the set of data type converters from `DefaultTypeConverter`
# and add another custom converter.
converter = Cursor.get_default_converter()
converter.set(CrateDatatypeIdentifier.BIT, lambda value: int(value[2:-1], 2))
converter.set(CrateDatatypeIdentifier.BIT, lambda value: value is not None and int(value[2:-1], 2) or None)

# Create a `Cursor` object with converter.
c = conn.cursor(converter=converter)
Expand All @@ -68,18 +68,29 @@ def test_execute_with_converter(self):
conn.client.set_next_response({
"col_types": [4, 5, 11, 25],
"cols": ["name", "address", "timestamp", "bitmask"],
"rows": [["foo", "10.10.10.1", 1658167836758, "B'0110'"]],
"rows": [
["foo", "10.10.10.1", 1658167836758, "B'0110'"],
[None, None, None, None],
],
"rowcount": 1,
"duration": 123
})

c.execute("")
result = c.fetchone()
result = c.fetchall()
self.assertEqual(result, [
'foo',
IPv4Address('10.10.10.1'),
datetime(2022, 7, 18, 18, 10, 36, 758000),
6
[
'foo',
IPv4Address('10.10.10.1'),
datetime(2022, 7, 18, 18, 10, 36, 758000),
6,
],
[
None,
None,
None,
None,
],
])

# When removing the converters, all values are forwarded 1:1.
Expand Down

0 comments on commit 1410547

Please sign in to comment.