From adc8d6bae4010c06fc3b779b8d84c1c5b4a910ad Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 22 Jan 2024 15:49:44 -0800 Subject: interpreter: replace mock keyword argument with unittest.mock Python provides some nifty tools for mocking, without relying on altering running code. We should use these to simplify the actual run paths and move the complicated logic into tests. --- unittests/internaltests.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'unittests/internaltests.py') diff --git a/unittests/internaltests.py b/unittests/internaltests.py index 945faa18b..fd843c88c 100644 --- a/unittests/internaltests.py +++ b/unittests/internaltests.py @@ -1662,13 +1662,16 @@ class InternalTests(unittest.TestCase): actual = mesonbuild.environment.detect_cpu({}) self.assertEqual(actual, expected) + @mock.patch('mesonbuild.interpreter.Interpreter.load_root_meson_file', mock.Mock(return_value=None)) + @mock.patch('mesonbuild.interpreter.Interpreter.sanity_check_ast', mock.Mock(return_value=None)) + @mock.patch('mesonbuild.interpreter.Interpreter.parse_project', mock.Mock(return_value=None)) def test_interpreter_unpicklable(self) -> None: build = mock.Mock() build.environment = mock.Mock() build.environment.get_source_dir = mock.Mock(return_value='') with mock.patch('mesonbuild.interpreter.Interpreter._redetect_machines', mock.Mock()), \ self.assertRaises(mesonbuild.mesonlib.MesonBugException): - i = mesonbuild.interpreter.Interpreter(build, mock=True) + i = mesonbuild.interpreter.Interpreter(build) pickle.dumps(i) def test_major_versions_differ(self) -> None: -- cgit v1.2.3