From 7f0c21bb99a20d28739bee293fa4066989b2f3d6 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Mon, 9 Sep 2019 14:04:19 -0400 Subject: [PATCH] bt2: test_message_iterator: use assertIs instead of assertTrue/assertFalse in can seek tests In these tests, we want to specifically check that the return values are True or False, not any value that evaluates to True or False. For example, we initialize can_seek_beginning to None, run graph.run_once(), then do assertFalse(can_seek_beginning). If, for some reason, can_seek_beginning is still None, the test will wrongfully pass. The same could happen if can_seek_beginning gets assigned some value that evaluates to True (other than True itself) and we use assertTrue(can_seek_beginning). Instead, use assertIs, which checks that the value is specifically the one and only True or the one and only False. Change-Id: Idf94d350ecc06cdb6a38ca31b2d77804fbf57df7 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/2019 Tested-by: jenkins Reviewed-by: Francis Deslauriers Reviewed-by: Philippe Proulx --- tests/bindings/python/bt2/test_message_iterator.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/bindings/python/bt2/test_message_iterator.py b/tests/bindings/python/bt2/test_message_iterator.py index 752682bc..ce968ea8 100644 --- a/tests/bindings/python/bt2/test_message_iterator.py +++ b/tests/bindings/python/bt2/test_message_iterator.py @@ -403,12 +403,12 @@ class UserMessageIteratorSeekBeginningTestCase(unittest.TestCase): input_port_iter_can_seek_beginning = True can_seek_beginning = None graph.run_once() - self.assertTrue(can_seek_beginning) + self.assertIs(can_seek_beginning, True) input_port_iter_can_seek_beginning = False can_seek_beginning = None graph.run_once() - self.assertFalse(can_seek_beginning) + self.assertIs(can_seek_beginning, False) def test_no_can_seek_beginning_with_seek_beginning(self): # Test an iterator without a _user_can_seek_beginning method, but with @@ -432,7 +432,7 @@ class UserMessageIteratorSeekBeginningTestCase(unittest.TestCase): graph = _setup_seek_test(MySink, user_seek_beginning=_user_seek_beginning) can_seek_beginning = None graph.run_once() - self.assertTrue(can_seek_beginning) + self.assertIs(can_seek_beginning, True) def test_no_can_seek_beginning(self): # Test an iterator without a _user_can_seek_beginning method, without @@ -453,7 +453,7 @@ class UserMessageIteratorSeekBeginningTestCase(unittest.TestCase): graph = _setup_seek_test(MySink) can_seek_beginning = None graph.run_once() - self.assertFalse(can_seek_beginning) + self.assertIs(can_seek_beginning, False) def test_can_seek_beginning_user_error(self): class MySink(bt2._UserSinkComponent): -- 2.34.1