diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2021-06-08 11:40:43 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2021-06-14 12:30:02 -0700 |
commit | 5bb75dc3af4d1b91af024e70d9cb2432886eb959 (patch) | |
tree | 9893578621ffd634f71256a1a08ba6649d225d69 /run_unittests.py | |
parent | 6490b13f2283debf5c166c1ae252bba105470bc5 (diff) | |
download | meson-5bb75dc3af4d1b91af024e70d9cb2432886eb959.zip meson-5bb75dc3af4d1b91af024e70d9cb2432886eb959.tar.gz meson-5bb75dc3af4d1b91af024e70d9cb2432886eb959.tar.bz2 |
interpreterbase: Add deprecated_values and since_values to KwargInfo
This allows checking specific values that are added or deprecated, which
we do a surprising amount of. This works with both containers and scalar
values
Diffstat (limited to 'run_unittests.py')
-rwxr-xr-x | run_unittests.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/run_unittests.py b/run_unittests.py index b43e8f0..d17c243 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -1655,6 +1655,45 @@ class InternalTests(unittest.TestCase): _(None, mock.Mock(), tuple(), dict(native=True)) + @mock.patch.dict(mesonbuild.mesonlib.project_meson_versions, {'': '1.0'}) + def test_typed_kwarg_since_values(self) -> None: + @typed_kwargs( + 'testfunc', + KwargInfo('input', ContainerTypeInfo(list, str), listify=True, default=[], deprecated_values={'foo': '0.9'}, since_values={'bar': '1.1'}), + KwargInfo('output', ContainerTypeInfo(dict, str), default={}, deprecated_values={'foo': '0.9'}, since_values={'bar': '1.1'}), + KwargInfo( + 'mode', str, + validator=lambda x: 'Should be one of "clean", "build", "rebuild"' if x not in {'clean', 'build', 'rebuild', 'deprecated', 'since'} else None, + deprecated_values={'deprecated': '1.0'}, + since_values={'since': '1.1'}), + ) + def _(obj, node, args: T.Tuple, kwargs: T.Dict[str, str]) -> None: + pass + + with mock.patch('sys.stdout', io.StringIO()) as out: + _(None, mock.Mock(subproject=''), [], {'input': ['foo']}) + self.assertRegex(out.getvalue(), r"""WARNING:.Project targeting '1.0'.*deprecated since '0.9': "testfunc" keyword argument "input" value "foo".*""") + + with mock.patch('sys.stdout', io.StringIO()) as out: + _(None, mock.Mock(subproject=''), [], {'input': ['bar']}) + self.assertRegex(out.getvalue(), r"""WARNING:.Project targeting '1.0'.*introduced in '1.1': "testfunc" keyword argument "input" value "bar".*""") + + with mock.patch('sys.stdout', io.StringIO()) as out: + _(None, mock.Mock(subproject=''), [], {'output': {'foo': 'a'}}) + self.assertRegex(out.getvalue(), r"""WARNING:.Project targeting '1.0'.*deprecated since '0.9': "testfunc" keyword argument "output" value "foo".*""") + + with mock.patch('sys.stdout', io.StringIO()) as out: + _(None, mock.Mock(subproject=''), [], {'output': {'bar': 'b'}}) + self.assertRegex(out.getvalue(), r"""WARNING:.Project targeting '1.0'.*introduced in '1.1': "testfunc" keyword argument "output" value "bar".*""") + + with mock.patch('sys.stdout', io.StringIO()) as out: + _(None, mock.Mock(subproject=''), [], {'mode': 'deprecated'}) + self.assertRegex(out.getvalue(), r"""WARNING:.Project targeting '1.0'.*deprecated since '1.0': "testfunc" keyword argument "mode" value "deprecated".*""") + + with mock.patch('sys.stdout', io.StringIO()) as out: + _(None, mock.Mock(subproject=''), [], {'mode': 'since'}) + self.assertRegex(out.getvalue(), r"""WARNING:.Project targeting '1.0'.*introduced in '1.1': "testfunc" keyword argument "mode" value "since".*""") + @unittest.skipIf(is_tarball(), 'Skipping because this is a tarball release') class DataTests(unittest.TestCase): |