From cd27b1c0087cf1158623ead2664d15b75181327c Mon Sep 17 00:00:00 2001
From: pompolic <pompolic@special-circumstanc.es>
Date: Wed, 13 Jul 2022 18:51:10 +0200
Subject: [PATCH] Refactor testcase to use setUp() and tearDown()

---
 gdb-port/tests/unit/ast.py | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/gdb-port/tests/unit/ast.py b/gdb-port/tests/unit/ast.py
index 3f562d9..802c1e4 100644
--- a/gdb-port/tests/unit/ast.py
+++ b/gdb-port/tests/unit/ast.py
@@ -121,22 +121,22 @@ class HParseResultTests(unittest.TestCase):
 
 #class HParsedTokenCreation(unittest.TestCase):
 
-class ASTManagerTests(unittest.TestCase):
-	def test_set_top_node(self):
-		hpr_patcher = unittest.mock.patch('__main__.HParseResult', autospec=True)
-		parser_patcher = unittest.mock.patch('__main__.Parser', autospec=True)
+class ASTManagerSetTopNode(unittest.TestCase):
+	def setUp(self):
+		self.hpr_patcher = unittest.mock.patch('__main__.HParseResult', autospec=True)
+		self.parser_patcher = unittest.mock.patch('__main__.Parser', autospec=True)
+		self.hpr_mock_object = self.hpr_patcher.start()
+		self.parser_mock_object = self.parser_patcher.start()
 
-		hpr_mock_object = hpr_patcher.start()
-		parser_mock_object = parser_patcher.start()
+	def tearDown(self):
+		self.parser_patcher.stop()
+		self.hpr_patcher.stop()
 
+	def test_set_top_node(self):
 		p = Parser('test_parser', 0xdeadbfff)
 		ast_manager = ASTManager()
 		ast_manager.set_top_node(0xdeadbeef, p)
 
-		#TODO: use setUp() and tearDown(), otherwise other tests break if this fails
-		parser_patcher.stop()
-		hpr_patcher.stop()
-
 		#self.assertEquals(ast_manager.top_node, hpr_mock_object)
-		self.assertEquals(ast_manager.parser, p)
-		self.assertEquals(hpr_mock_object.mock_calls, [unittest.mock.call(0xdeadbeef)])
+		self.assertEqual(ast_manager.parser, p)
+		self.assertEqual(self.hpr_mock_object.mock_calls, [unittest.mock.call(0xdeadbeef)])
-- 
GitLab