aboutsummaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2022-11-18 13:25:12 -0800
committerEli Schwartz <eschwartz@archlinux.org>2023-05-31 17:20:44 -0400
commitada2a976f003f505181d2f252ef907f8caa345e0 (patch)
tree547aac75202aa63aec5688e5c064f80ca43cf557 /unittests
parent1e79553c36bf6473a58559254dc25fc550dfca99 (diff)
downloadmeson-ada2a976f003f505181d2f252ef907f8caa345e0.zip
meson-ada2a976f003f505181d2f252ef907f8caa345e0.tar.gz
meson-ada2a976f003f505181d2f252ef907f8caa345e0.tar.bz2
mlog: use a hidden class for state
This is a pretty common pattern in python (the standard library uses it a ton): A class is created, with a single private instance in the module, and then it's methods are exposed as public API. This removes the need for the global statement, and is generally a little easier to reason about thanks to encapsulation.
Diffstat (limited to 'unittests')
-rw-r--r--unittests/baseplatformtests.py4
-rw-r--r--unittests/internaltests.py18
2 files changed, 11 insertions, 11 deletions
diff --git a/unittests/baseplatformtests.py b/unittests/baseplatformtests.py
index 251c15d..489e5c4 100644
--- a/unittests/baseplatformtests.py
+++ b/unittests/baseplatformtests.py
@@ -229,8 +229,8 @@ class BasePlatformTests(TestCase):
finally:
# Close log file to satisfy Windows file locking
mesonbuild.mlog.shutdown()
- mesonbuild.mlog.log_dir = None
- mesonbuild.mlog.log_file = None
+ mesonbuild.mlog._logger.log_dir = None
+ mesonbuild.mlog._logger.log_file = None
if 'MESON_SKIP_TEST' in out:
raise SkipTest('Project requested skipping.')
diff --git a/unittests/internaltests.py b/unittests/internaltests.py
index 720782e..aea6890 100644
--- a/unittests/internaltests.py
+++ b/unittests/internaltests.py
@@ -947,23 +947,23 @@ class InternalTests(unittest.TestCase):
def test_log_once(self):
f = io.StringIO()
- with mock.patch('mesonbuild.mlog.log_file', f), \
- mock.patch('mesonbuild.mlog._logged_once', set()):
- mesonbuild.mlog.log_once('foo')
- mesonbuild.mlog.log_once('foo')
+ with mock.patch('mesonbuild.mlog._logger.log_file', f), \
+ mock.patch('mesonbuild.mlog._logger.logged_once', set()):
+ mesonbuild.mlog.log('foo', once=True)
+ mesonbuild.mlog.log('foo', once=True)
actual = f.getvalue().strip()
self.assertEqual(actual, 'foo', actual)
def test_log_once_ansi(self):
f = io.StringIO()
- with mock.patch('mesonbuild.mlog.log_file', f), \
- mock.patch('mesonbuild.mlog._logged_once', set()):
- mesonbuild.mlog.log_once(mesonbuild.mlog.bold('foo'))
- mesonbuild.mlog.log_once(mesonbuild.mlog.bold('foo'))
+ with mock.patch('mesonbuild.mlog._logger.log_file', f), \
+ mock.patch('mesonbuild.mlog._logger.logged_once', set()):
+ mesonbuild.mlog.log(mesonbuild.mlog.bold('foo'), once=True)
+ mesonbuild.mlog.log(mesonbuild.mlog.bold('foo'), once=True)
actual = f.getvalue().strip()
self.assertEqual(actual.count('foo'), 1, actual)
- mesonbuild.mlog.log_once('foo')
+ mesonbuild.mlog.log('foo', once=True)
actual = f.getvalue().strip()
self.assertEqual(actual.count('foo'), 1, actual)