diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2022-10-05 03:27:32 -0400 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2022-11-13 10:03:20 -0500 |
| commit | 74652cabdeaacadc76ccf126563bed8ee2ccf3ef (patch) | |
| tree | e6f4b8b8d305d5e43467ca242f375eade52e5518 /distutils/tests/test_log.py | |
| parent | f95d384957ba4c358c6e1345c932b4445a4a38d3 (diff) | |
| download | python-setuptools-git-74652cabdeaacadc76ccf126563bed8ee2ccf3ef.tar.gz | |
Replace bespoke logging facility with logging module, available since Python 2.3.
Diffstat (limited to 'distutils/tests/test_log.py')
| -rw-r--r-- | distutils/tests/test_log.py | 51 |
1 files changed, 6 insertions, 45 deletions
diff --git a/distutils/tests/test_log.py b/distutils/tests/test_log.py index 7aeee405..d346d07b 100644 --- a/distutils/tests/test_log.py +++ b/distutils/tests/test_log.py @@ -1,52 +1,13 @@ """Tests for distutils.log""" -import io -import sys -from test.support import swap_attr - -import pytest +import logging from distutils import log class TestLog: - @pytest.mark.parametrize( - 'errors', - ( - 'strict', - 'backslashreplace', - 'surrogateescape', - 'replace', - 'ignore', - ), - ) - def test_non_ascii(self, errors): - # Issues #8663, #34421: test that non-encodable text is escaped with - # backslashreplace error handler and encodable non-ASCII text is - # output as is. - stdout = io.TextIOWrapper(io.BytesIO(), encoding='cp437', errors=errors) - stderr = io.TextIOWrapper(io.BytesIO(), encoding='cp437', errors=errors) - old_threshold = log.set_threshold(log.DEBUG) - try: - with swap_attr(sys, 'stdout', stdout), swap_attr(sys, 'stderr', stderr): - log.debug('Dεbug\tMėssãge') - log.fatal('Fαtal\tÈrrōr') - finally: - log.set_threshold(old_threshold) - - stdout.seek(0) - assert stdout.read().rstrip() == ( - 'Dεbug\tM?ss?ge' - if errors == 'replace' - else 'Dεbug\tMssge' - if errors == 'ignore' - else 'Dεbug\tM\\u0117ss\\xe3ge' - ) - stderr.seek(0) - assert stderr.read().rstrip() == ( - 'Fαtal\t?rr?r' - if errors == 'replace' - else 'Fαtal\trrr' - if errors == 'ignore' - else 'Fαtal\t\\xc8rr\\u014dr' - ) + def test_non_ascii(self, caplog): + caplog.set_level(logging.DEBUG) + log.debug('Dεbug\tMėssãge') + log.fatal('Fαtal\tÈrrōr') + assert caplog.messages == ['Dεbug\tMėssãge', 'Fαtal\tÈrrōr'] |
