def test_fix_harfbuzz(self, clear_harfbuzz, args, monkeypatch, caplog, harfbuzz, qt_version, platform, expected): """Check the QT_HARFBUZZ env var.""" args.harfbuzz = harfbuzz monkeypatch.setattr(earlyinit, '_qt_version', lambda: pkg_resources.parse_version(qt_version)) monkeypatch.setattr(earlyinit.sys, 'platform', platform) with caplog.at_level(logging.WARNING): # Because QtWidgets is already imported earlyinit.fix_harfbuzz(args) assert os.environ.get('QT_HARFBUZZ', None) == expected
def test_widgets_warning(self, args, monkeypatch, caplog, frozen, level): """Make sure fix_harfbuzz warns when QtWidgets is imported.""" # Make sure QtWidgets is in sys.modules from PyQt5 import QtWidgets # pylint: disable=unused-variable if frozen: monkeypatch.setattr(earlyinit.sys, 'frozen', True, raising=False) else: monkeypatch.delattr(earlyinit.sys, 'frozen', raising=False) with caplog.at_level(level): earlyinit.fix_harfbuzz(args) record = caplog.records[0] assert record.levelno == level msg = "Harfbuzz fix attempted but QtWidgets is already imported!" assert record.message == msg
def test_no_warning(self, args, monkeypatch): """Without QtWidgets in sys.modules, no warning should be shown.""" monkeypatch.setattr(earlyinit.sys, 'modules', {}) earlyinit.fix_harfbuzz(args)