From 2fd5f1b5124552616876a40961a0ab12e52297a2 Mon Sep 17 00:00:00 2001 From: pompolic <pompolic@special-circumstanc.es> Date: Wed, 6 Jul 2022 20:45:24 +0200 Subject: [PATCH] Finish test for make_HParsedToken() --- gdb-port/tests/unit/ast.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/gdb-port/tests/unit/ast.py b/gdb-port/tests/unit/ast.py index 8820f56..b407228 100644 --- a/gdb-port/tests/unit/ast.py +++ b/gdb-port/tests/unit/ast.py @@ -28,21 +28,21 @@ class HParseResultCreation(unittest.TestCase): gdbv_patcher = unittest.mock.patch('gdb.Value', autospec=True) hpt_patcher = unittest.mock.patch('__main__.HParsedToken', autospec=True) hpr_patcher = unittest.mock.patch.object(HParseResult, 'read_AST_not_null', return_value=True) - #hpr_read_member_patcher = unittest.mock.patch.object(HParseResult, 'read_member', return_value=unittest.mock.DEFAULT) # TODO: return mock GDB value with 'ast' offset applied + rm_patcher = unittest.mock.patch.object(HParseResult, 'read_member', return_value=0xdeadfff0) gdbv_mock_object = gdbv_patcher.start() hpt_mock_object = hpt_patcher.start() hpr_patcher.start() + rm_mock_object = rm_patcher.start() hpr = HParseResult(0xdeadbeef) tok = hpr.make_HParsedToken() - - print(gdbv_mock_object.call_args) - print(hpt_mock_object.call_args) + rm_patcher.stop() hpr_patcher.stop() hpt_patcher.stop() gdbv_patcher.stop() - #TODO: what are the invariants we need to test here? - # e.g.: tok.address == hpt.ast.value - # mocking out gdb.Value makes it difficult to check the arguments passed to HParsedToken() + # Check that read_member('ast') is called + self.assertEqual(rm_mock_object.call_args, unittest.mock.call('ast')) + # Check that HParsedToken() is called with the value returned by read_member() + self.assertEqual(hpt_mock_object.call_args, unittest.mock.call(0xdeadfff0)) def test_make_HParsedToken_if_no_ast(self): gdbv_patcher = unittest.mock.patch('gdb.Value', autospec=True) -- GitLab