diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2021-06-01 15:42:07 -0400 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2021-06-01 20:01:20 -0400 |
commit | 16c3f033943206b4b90532a9656f64678e87a7ec (patch) | |
tree | df2087377105deb1dcbe0a337befa913395da892 /run_unittests.py | |
parent | 6aef800ba83a4dd469c354900b6e537777d3080c (diff) | |
download | meson-16c3f033943206b4b90532a9656f64678e87a7ec.zip meson-16c3f033943206b4b90532a9656f64678e87a7ec.tar.gz meson-16c3f033943206b4b90532a9656f64678e87a7ec.tar.bz2 |
typed_kwargs: Add since and deprecated annotations
Diffstat (limited to 'run_unittests.py')
-rwxr-xr-x | run_unittests.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/run_unittests.py b/run_unittests.py index 1c6d491..3a98368 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -1586,6 +1586,38 @@ class InternalTests(unittest.TestCase): _(None, mock.Mock(), [], {'input': ['a']}) self.assertEqual(str(cm.exception), "testfunc keyword argument \"input\" container should be of even length, but is not") + def test_typed_kwarg_since(self) -> None: + @typed_kwargs( + 'testfunc', + KwargInfo('input', str, since='1.0', deprecated='2.0') + ) + def _(obj, node, args: T.Tuple, kwargs: T.Dict[str, str]) -> None: + self.assertIsInstance(kwargs['input'], str) + self.assertEqual(kwargs['input'], 'foo') + + # With Meson 0.1 it should trigger the "introduced" warning but not the "deprecated" warning + mesonbuild.mesonlib.project_meson_versions[''] = '0.1' + sys.stdout = io.StringIO() + _(None, mock.Mock(subproject=''), [], {'input': 'foo'}) + self.assertRegex(sys.stdout.getvalue(), r'WARNING:.*introduced.*input arg in testfunc') + self.assertNotRegex(sys.stdout.getvalue(), r'WARNING:.*deprecated.*input arg in testfunc') + + # With Meson 1.5 it shouldn't trigger any warning + mesonbuild.mesonlib.project_meson_versions[''] = '1.5' + sys.stdout = io.StringIO() + _(None, mock.Mock(subproject=''), [], {'input': 'foo'}) + self.assertNotRegex(sys.stdout.getvalue(), r'WARNING:.*') + self.assertNotRegex(sys.stdout.getvalue(), r'WARNING:.*') + + # With Meson 2.0 it should trigger the "deprecated" warning but not the "introduced" warning + mesonbuild.mesonlib.project_meson_versions[''] = '2.0' + sys.stdout = io.StringIO() + _(None, mock.Mock(subproject=''), [], {'input': 'foo'}) + self.assertRegex(sys.stdout.getvalue(), r'WARNING:.*deprecated.*input arg in testfunc') + self.assertNotRegex(sys.stdout.getvalue(), r'WARNING:.*introduced.*input arg in testfunc') + + sys.stdout = sys.__stdout__ + @unittest.skipIf(is_tarball(), 'Skipping because this is a tarball release') class DataTests(unittest.TestCase): |