The NonexistentClockSnapshot exception type is used when trying to get a
clock snapshot from an object that doesn't have clock snapshots (because
of the way it's configured). It does not have much value over using a
standard exception type. Replace it with ValueError.
In the test add some validation about the error message, because it
would be possible for the test to be a false positive if some ValueError
is raised for another reason (a programming error on our part, for
example).
Change-Id: Iebf86bc53e578407bb60f2145246dbd110cafaac
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1753
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
-class NonexistentClockSnapshot(Exception):
- pass
-
-
class _LoadingError(_Error):
pass
class _LoadingError(_Error):
pass
@staticmethod
def _check_has_default_clock_class(clock_class):
if clock_class is None:
@staticmethod
def _check_has_default_clock_class(clock_class):
if clock_class is None:
- raise bt2.NonexistentClockSnapshot(
'cannot get default clock snapshot: stream class has no default clock class'
)
'cannot get default clock snapshot: stream class has no default clock class'
)
def _check_has_default_clock_snapshots(self):
if not self._has_default_clock_snapshots:
def _check_has_default_clock_snapshots(self):
if not self._has_default_clock_snapshots:
- raise bt2.NonexistentClockSnapshot(
'cannot get default clock snapshot: such a message has no clock snapshots for this stream class'
)
'cannot get default clock snapshot: such a message has no clock snapshots for this stream class'
)
def test_no_clock_value(self):
msg = self._create_test_event_message(with_clockclass=False)
def test_no_clock_value(self):
msg = self._create_test_event_message(with_clockclass=False)
- with self.assertRaises(bt2.NonexistentClockSnapshot):
+ with self.assertRaisesRegex(
+ ValueError, 'stream class has no default clock class'
+ ):
msg.default_clock_snapshot
def test_stream(self):
msg.default_clock_snapshot
def test_stream(self):
if i == 0:
self.assertIsInstance(msg, bt2.message._StreamBeginningMessage)
self.assertEqual(msg.stream.addr, self._stream.addr)
if i == 0:
self.assertIsInstance(msg, bt2.message._StreamBeginningMessage)
self.assertEqual(msg.stream.addr, self._stream.addr)
- with self.assertRaises(bt2.NonexistentClockSnapshot):
+ with self.assertRaisesRegex(
+ ValueError, 'stream class has no default clock class'
+ ):
msg.default_clock_snapshot
elif i == 1:
self.assertIsInstance(msg, bt2.message._PacketBeginningMessage)
msg.default_clock_snapshot
elif i == 1:
self.assertIsInstance(msg, bt2.message._PacketBeginningMessage)
elif i == 2:
self.assertIsInstance(msg, bt2.message._EventMessage)
self.assertEqual(msg.event.cls.addr, self._event_class.addr)
elif i == 2:
self.assertIsInstance(msg, bt2.message._EventMessage)
self.assertEqual(msg.event.cls.addr, self._event_class.addr)
- with self.assertRaises(bt2.NonexistentClockSnapshot):
+ with self.assertRaisesRegex(
+ ValueError, 'stream class has no default clock class'
+ ):
msg.default_clock_snapshot
elif i == 3:
self.assertIsInstance(msg, bt2.message._DiscardedEventsMessage)
self.assertEqual(msg.stream.addr, self._stream.addr)
self.assertEqual(msg.count, 890)
self.assertIsNone(msg.stream.cls.default_clock_class)
msg.default_clock_snapshot
elif i == 3:
self.assertIsInstance(msg, bt2.message._DiscardedEventsMessage)
self.assertEqual(msg.stream.addr, self._stream.addr)
self.assertEqual(msg.count, 890)
self.assertIsNone(msg.stream.cls.default_clock_class)
- with self.assertRaises(bt2.NonexistentClockSnapshot):
+ with self.assertRaisesRegex(
+ ValueError,
+ 'such a message has no clock snapshots for this stream class',
+ ):
msg.beginning_default_clock_snapshot
msg.beginning_default_clock_snapshot
- with self.assertRaises(bt2.NonexistentClockSnapshot):
+ with self.assertRaisesRegex(
+ ValueError,
+ 'such a message has no clock snapshots for this stream class',
+ ):
msg.end_default_clock_snapshot
elif i == 4:
self.assertIsInstance(msg, bt2.message._PacketEndMessage)
msg.end_default_clock_snapshot
elif i == 4:
self.assertIsInstance(msg, bt2.message._PacketEndMessage)
self.assertEqual(msg.stream.addr, self._stream.addr)
self.assertEqual(msg.count, 678)
self.assertIsNone(msg.stream.cls.default_clock_class)
self.assertEqual(msg.stream.addr, self._stream.addr)
self.assertEqual(msg.count, 678)
self.assertIsNone(msg.stream.cls.default_clock_class)
- with self.assertRaises(bt2.NonexistentClockSnapshot):
+ with self.assertRaisesRegex(
+ ValueError,
+ 'such a message has no clock snapshots for this stream class',
+ ):
msg.beginning_default_clock_snapshot
msg.beginning_default_clock_snapshot
- with self.assertRaises(bt2.NonexistentClockSnapshot):
+ with self.assertRaisesRegex(
+ ValueError,
+ 'such a message has no clock snapshots for this stream class',
+ ):
msg.end_default_clock_snapshot
elif i == 6:
self.assertIsInstance(msg, bt2.message._StreamEndMessage)
self.assertEqual(msg.stream.addr, self._stream.addr)
msg.end_default_clock_snapshot
elif i == 6:
self.assertIsInstance(msg, bt2.message._StreamEndMessage)
self.assertEqual(msg.stream.addr, self._stream.addr)
- with self.assertRaises(bt2.NonexistentClockSnapshot):
+ with self.assertRaisesRegex(
+ ValueError, 'stream class has no default clock class'
+ ):
msg.default_clock_snapshot
else:
raise Exception
msg.default_clock_snapshot
else:
raise Exception