Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
test_logging.py77 linesDownload Raw Back to tests
1import functools2import inspect3import logging4import sys5 6import pytest7 8IS_PYPY = '__pypy__' in sys.builtin_module_names9 10 11setup_py = """\12from setuptools import setup13 14setup(15    name="test_logging",16    version="0.0"17)18"""19 20 21@pytest.mark.parametrize(22    ('flags', 'expected_level'), [([], "INFO"), (["--verbose"], "DEBUG")]23)24def test_verbosity_level(tmp_path, monkeypatch, flags, expected_level):25    """Make sure the correct verbosity level is set (issue #3038)"""26    import setuptools  # noqa: F401  # import setuptools to monkeypatch distutils27 28    import distutils  # <- load distutils after all the patches take place29 30    logger = logging.Logger(__name__)31    monkeypatch.setattr(logging, "root", logger)32    unset_log_level = logger.getEffectiveLevel()33    assert logging.getLevelName(unset_log_level) == "NOTSET"34 35    setup_script = tmp_path / "setup.py"36    setup_script.write_text(setup_py, encoding="utf-8")37    dist = distutils.core.run_setup(setup_script, stop_after="init")38    dist.script_args = flags + ["sdist"]39    dist.parse_command_line()  # <- where the log level is set40    log_level = logger.getEffectiveLevel()41    log_level_name = logging.getLevelName(log_level)42    assert log_level_name == expected_level43 44 45def flaky_on_pypy(func):46    @functools.wraps(func)47    def _func():48        try:49            func()50        except AssertionError:  # pragma: no cover51            if IS_PYPY:52                msg = "Flaky monkeypatch on PyPy (#4124)"53                pytest.xfail(f"{msg}. Original discussion in #3707, #3709.")54            raise55 56    return _func57 58 59@flaky_on_pypy60def test_patching_does_not_cause_problems():61    # Ensure `dist.log` is only patched if necessary62 63    import _distutils_hack64 65    import setuptools.logging66 67    from distutils import dist68 69    setuptools.logging.configure()70 71    if _distutils_hack.enabled():72        # Modern logging infra, no problematic patching.73        assert dist.__file__ is None or "setuptools" in dist.__file__74        assert isinstance(dist.log, logging.Logger)75    else:76        assert inspect.ismodule(dist.log)77 
codekingpro/portable-devtools · Team Ai