I'm also adding a test to check this. Without this patch and an invalid
key, __getitem__() throws `AttributeError` instead of the expected
`KeyError`.
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ie6258a2354ece8aee6c8530587c900ea08e45fe8
Reviewed-on: https://review.lttng.org/c/babeltrace/+/3349
Tested-by: jenkins <jenkins@lttng.org>
if common_context_field is not None and key in common_context_field:
return common_context_field[key]
- packet_context_field = self.packet.context_field
+ if self.packet:
+ packet_context_field = self.packet.context_field
- if packet_context_field is not None and key in packet_context_field:
- return packet_context_field[key]
+ if packet_context_field is not None and key in packet_context_field:
+ return packet_context_field[key]
raise KeyError(key)
with self.assertRaises(KeyError):
ev['yes']
+ def test_const_getitem_no_packet(self):
+ def event_fields_config(event):
+ event.payload_field['giraffe'] = 1
+ event.payload_field['gnu'] = 23
+ event.payload_field['mosquito'] = 42
+
+ msg = self._create_test_const_event_message(
+ event_fields_config=event_fields_config, with_ep=True,
+ )
+ ev = msg.event
+
+ with self.assertRaises(KeyError):
+ ev['yes']
+
def test_getitem(self):
msg = utils.get_event_message()
ev = msg.event