summaryrefslogtreecommitdiff
path: root/run_unittests.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2021-06-02 15:39:06 -0700
committerDaniel Mensinger <daniel@mensinger-ka.de>2021-06-08 11:00:55 +0200
commit4dc3f2af6369f0090898b8d0d27cd0cf2d849d18 (patch)
tree0691cc09802a5332ee86d019452a68a73fe6cacb /run_unittests.py
parent48ebfa9a99d6c1ffdadb723e85920aad8449110b (diff)
downloadmeson-4dc3f2af6369f0090898b8d0d27cd0cf2d849d18.tar.gz
run_unittests.py: Use mock for monkey patching
it's what mock is for afterall
Diffstat (limited to 'run_unittests.py')
-rwxr-xr-xrun_unittests.py42
1 files changed, 20 insertions, 22 deletions
diff --git a/run_unittests.py b/run_unittests.py
index a0beb48af..39b349685 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -1608,28 +1608,26 @@ class InternalTests(unittest.TestCase):
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__
+ with mock.patch('sys.stdout', io.StringIO()) as out:
+ # With Meson 0.1 it should trigger the "introduced" warning but not the "deprecated" warning
+ mesonbuild.mesonlib.project_meson_versions[''] = '0.1'
+ _(None, mock.Mock(subproject=''), [], {'input': 'foo'})
+ self.assertRegex(out.getvalue(), r'WARNING:.*introduced.*input arg in testfunc')
+ self.assertNotRegex(out.getvalue(), r'WARNING:.*deprecated.*input arg in testfunc')
+
+ with mock.patch('sys.stdout', io.StringIO()) as out:
+ # With Meson 1.5 it shouldn't trigger any warning
+ mesonbuild.mesonlib.project_meson_versions[''] = '1.5'
+ _(None, mock.Mock(subproject=''), [], {'input': 'foo'})
+ self.assertNotRegex(out.getvalue(), r'WARNING:.*')
+ self.assertNotRegex(out.getvalue(), r'WARNING:.*')
+
+ with mock.patch('sys.stdout', io.StringIO()) as out:
+ # With Meson 2.0 it should trigger the "deprecated" warning but not the "introduced" warning
+ mesonbuild.mesonlib.project_meson_versions[''] = '2.0'
+ _(None, mock.Mock(subproject=''), [], {'input': 'foo'})
+ self.assertRegex(out.getvalue(), r'WARNING:.*deprecated.*input arg in testfunc')
+ self.assertNotRegex(out.getvalue(), r'WARNING:.*introduced.*input arg in testfunc')
@unittest.skipIf(is_tarball(), 'Skipping because this is a tarball release')