bt2: remove NonexistentClockSnapshot exception type
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 24 Jul 2019 02:38:20 +0000 (22:38 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 24 Jul 2019 04:18:54 +0000 (00:18 -0400)
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>
src/bindings/python/bt2/bt2/__init__.py.in
src/bindings/python/bt2/bt2/message.py
tests/bindings/python/bt2/test_event.py
tests/bindings/python/bt2/test_message.py

index 8de6ba80d408b346d02697bc80ff76f801ff4859..4ceb37d1c671f0a74bbd8ee85c1d0dddb8b9ef9a 100644 (file)
@@ -105,10 +105,6 @@ class Canceled(Exception):
     pass
 
 
-class NonexistentClockSnapshot(Exception):
-    pass
-
-
 class _LoadingError(_Error):
     pass
 
index aeb9ebd8d8a2c1b9f0b97ff9471d917daff0d7d7..5a1ca32dea78900b45c61b71e56941dab810c2ae 100644 (file)
@@ -40,7 +40,7 @@ class _Message(object._SharedObject):
     @staticmethod
     def _check_has_default_clock_class(clock_class):
         if clock_class is None:
-            raise bt2.NonexistentClockSnapshot(
+            raise ValueError(
                 'cannot get default clock snapshot: stream class has no default clock class'
             )
 
@@ -180,7 +180,7 @@ class _DiscardedMessage(_Message, _MessageWithDefaultClockSnapshot):
 
     def _check_has_default_clock_snapshots(self):
         if not self._has_default_clock_snapshots:
-            raise bt2.NonexistentClockSnapshot(
+            raise ValueError(
                 'cannot get default clock snapshot: such a message has no clock snapshots for this stream class'
             )
 
index 74fe7cff1e374d4e044fda296b5748f3dedfdbf7..ab65e0fa4c270e97be9632e08ce8a30186e106ff 100644 (file)
@@ -229,7 +229,9 @@ class EventTestCase(unittest.TestCase):
 
     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):
index 5b513361ded29b500cf1591e625380e1aa536170..3b89337af826d0e85cb7342f6a487ebacc488c34 100644 (file)
@@ -214,7 +214,9 @@ class AllMessagesTestCase(unittest.TestCase):
             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)
@@ -222,16 +224,24 @@ class AllMessagesTestCase(unittest.TestCase):
             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)
-                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
-                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)
@@ -241,14 +251,22 @@ class AllMessagesTestCase(unittest.TestCase):
                 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
-                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)
-                with self.assertRaises(bt2.NonexistentClockSnapshot):
+                with self.assertRaisesRegex(
+                    ValueError, 'stream class has no default clock class'
+                ):
                     msg.default_clock_snapshot
             else:
                 raise Exception
This page took 0.027437 seconds and 4 git commands to generate.