Skip to content

Commit

Permalink
Account for stdlib back compatibility in test_manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Nov 22, 2022
1 parent e845c08 commit 9df6af9
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions setuptools/tests/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,20 +322,35 @@ class TestFileListTest(TempDirTestCase):
to ensure setuptools' version of FileList keeps parity with distutils.
"""

def get_logs(self, caplog, *levels):
return [
record.getMessage()
for record in caplog.records
if record.levelno in levels
]
@pytest.fixture(autouse=True)
def _compat_record_logs(self, monkeypatch):
"""Account for stdlib compatibility"""
self.logs = []
if (
os.getenv("SETUPTOOLS_USE_DISTUTILS") == "stdlib"
and hasattr(log, 'Log')
):
def _log(_logger, level, msg, args):
exc = sys.exc_info()
rec = logging.LogRecord('distutils', level, '', 0, msg, args, exc)
self.logs.append(rec)

monkeypatch.setattr(log.Log, '_log', _log)

def get_records(self, caplog, *levels):
return [r for r in (caplog.records + self.logs) if r.levelno in levels]

def clear_logs(self, caplog):
caplog.clear()
self.logs = []

def assertNoWarnings(self, caplog):
assert self.get_logs(caplog, log.WARN) == []
caplog.clear()
assert self.get_records(caplog, log.WARN) == []
self.clear_logs(caplog)

def assertWarnings(self, caplog):
assert len(self.get_logs(caplog, log.WARN)) > 0
caplog.clear()
assert len(self.get_records(caplog, log.WARN)) > 0
self.clear_logs(caplog)

def make_files(self, files):
for file in files:
Expand Down

0 comments on commit 9df6af9

Please sign in to comment.