Skip to content

Commit 1410547

Browse files
committed
Data type converter: Exercise None conversion
1 parent b21c38e commit 1410547

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/crate/client/test_cursor.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_execute_with_converter(self):
5858
# Use the set of data type converters from `DefaultTypeConverter`
5959
# and add another custom converter.
6060
converter = Cursor.get_default_converter()
61-
converter.set(CrateDatatypeIdentifier.BIT, lambda value: int(value[2:-1], 2))
61+
converter.set(CrateDatatypeIdentifier.BIT, lambda value: value is not None and int(value[2:-1], 2) or None)
6262

6363
# Create a `Cursor` object with converter.
6464
c = conn.cursor(converter=converter)
@@ -68,18 +68,29 @@ def test_execute_with_converter(self):
6868
conn.client.set_next_response({
6969
"col_types": [4, 5, 11, 25],
7070
"cols": ["name", "address", "timestamp", "bitmask"],
71-
"rows": [["foo", "10.10.10.1", 1658167836758, "B'0110'"]],
71+
"rows": [
72+
["foo", "10.10.10.1", 1658167836758, "B'0110'"],
73+
[None, None, None, None],
74+
],
7275
"rowcount": 1,
7376
"duration": 123
7477
})
7578

7679
c.execute("")
77-
result = c.fetchone()
80+
result = c.fetchall()
7881
self.assertEqual(result, [
79-
'foo',
80-
IPv4Address('10.10.10.1'),
81-
datetime(2022, 7, 18, 18, 10, 36, 758000),
82-
6
82+
[
83+
'foo',
84+
IPv4Address('10.10.10.1'),
85+
datetime(2022, 7, 18, 18, 10, 36, 758000),
86+
6,
87+
],
88+
[
89+
None,
90+
None,
91+
None,
92+
None,
93+
],
8394
])
8495

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

0 commit comments

Comments
 (0)