diff options
| author | Dylan Baker <dylan@pnwbakers.com> | 2022-11-18 13:25:12 -0800 |
|---|---|---|
| committer | Eli Schwartz <eschwartz@archlinux.org> | 2023-05-31 17:20:44 -0400 |
| commit | ada2a976f003f505181d2f252ef907f8caa345e0 (patch) | |
| tree | 547aac75202aa63aec5688e5c064f80ca43cf557 /unittests/internaltests.py | |
| parent | 1e79553c36bf6473a58559254dc25fc550dfca99 (diff) | |
| download | meson-ada2a976f003f505181d2f252ef907f8caa345e0.tar.gz | |
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/internaltests.py')
| -rw-r--r-- | unittests/internaltests.py | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/unittests/internaltests.py b/unittests/internaltests.py index 720782e3d..aea68900d 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) |
