summaryrefslogtreecommitdiff
path: root/unittests/datatests.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2024-01-22 15:49:44 -0800
committerDylan Baker <dylan@pnwbakers.com>2024-01-25 10:01:50 -0800
commitadc8d6bae4010c06fc3b779b8d84c1c5b4a910ad (patch)
tree7b7e810833ffd3d6c346bec7ebcf578413fc9206 /unittests/datatests.py
parent37883e7d5fe25f9abcc93f100655b61a0e23f8e5 (diff)
downloadmeson-adc8d6bae4010c06fc3b779b8d84c1c5b4a910ad.tar.gz
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.
Diffstat (limited to 'unittests/datatests.py')
-rw-r--r--unittests/datatests.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/unittests/datatests.py b/unittests/datatests.py
index ae32a9491..4f9d52032 100644
--- a/unittests/datatests.py
+++ b/unittests/datatests.py
@@ -5,6 +5,7 @@ import re
import unittest
from itertools import chain
from pathlib import Path
+from unittest import mock
import mesonbuild.mlog
import mesonbuild.depfile
@@ -208,7 +209,10 @@ class DataTests(unittest.TestCase):
name = name.replace('_', '-')
self.assertIn(name, html)
- @unittest.mock.patch.dict(os.environ)
+ @mock.patch.dict(os.environ)
+ @mock.patch.object(Interpreter, 'load_root_meson_file', mock.Mock(return_value=None))
+ @mock.patch.object(Interpreter, 'sanity_check_ast', mock.Mock(return_value=None))
+ @mock.patch.object(Interpreter, 'parse_project', mock.Mock(return_value=None))
def test_vim_syntax_highlighting(self):
'''
Ensure that vim syntax highlighting files were updated for new
@@ -217,13 +221,16 @@ class DataTests(unittest.TestCase):
# Disable unit test specific syntax
del os.environ['MESON_RUNNING_IN_PROJECT_TESTS']
env = get_fake_env()
- interp = Interpreter(FakeBuild(env), mock=True)
+ interp = Interpreter(FakeBuild(env))
with open('data/syntax-highlighting/vim/syntax/meson.vim', encoding='utf-8') as f:
res = re.search(r'syn keyword mesonBuiltin(\s+\\\s\w+)+', f.read(), re.MULTILINE)
defined = set([a.strip() for a in res.group().split('\\')][1:])
self.assertEqual(defined, set(chain(interp.funcs.keys(), interp.builtin.keys())))
- @unittest.mock.patch.dict(os.environ)
+ @mock.patch.dict(os.environ)
+ @mock.patch.object(Interpreter, 'load_root_meson_file', mock.Mock(return_value=None))
+ @mock.patch.object(Interpreter, 'sanity_check_ast', mock.Mock(return_value=None))
+ @mock.patch.object(Interpreter, 'parse_project', mock.Mock(return_value=None))
def test_all_functions_defined_in_ast_interpreter(self):
'''
Ensure that the all functions defined in the Interpreter are also defined
@@ -232,6 +239,6 @@ class DataTests(unittest.TestCase):
# Disable unit test specific syntax
del os.environ['MESON_RUNNING_IN_PROJECT_TESTS']
env = get_fake_env()
- interp = Interpreter(FakeBuild(env), mock=True)
+ interp = Interpreter(FakeBuild(env))
astint = AstInterpreter('.', '', '')
self.assertEqual(set(interp.funcs.keys()), set(astint.funcs.keys()))