diff --git a/pkg_resources/tests/test_pkg_resources.py b/pkg_resources/tests/test_pkg_resources.py index a05aeb2603..0dd9c3c105 100644 --- a/pkg_resources/tests/test_pkg_resources.py +++ b/pkg_resources/tests/test_pkg_resources.py @@ -1,9 +1,11 @@ +import builtins import sys import tempfile import os import zipfile import datetime import time +import plistlib import subprocess import stat import distutils.dist @@ -323,6 +325,32 @@ def test_dist_info_is_not_dir(tmp_path, only): assert not pkg_resources.dist_factory(str(tmp_path), str(dist_info), only) +@pytest.mark.skipif(sys.version_info >= (3, 9), reason="requires Python < 3.9") +@pytest.mark.filterwarnings("ignore::DeprecationWarning") +def test_macos_vers_fallback(monkeypatch, tmp_path): + """Regression test for pkg_resources._macos_vers""" + orig_open = builtins.open + + # Pretend we need to use the plist file + monkeypatch.setattr('platform.mac_ver', mock.Mock(return_value=('', (), ''))) + + # Create fake content for the fake plist file + with open(tmp_path / 'fake.plist', 'wb') as fake_file: + plistlib.dump({"ProductVersion": "11.4"}, fake_file) + + # Pretend the fake file exists + monkeypatch.setattr('os.path.exists', mock.Mock(return_value=True)) + + def fake_open(file, *args, **kwargs): + return orig_open(tmp_path / 'fake.plist', *args, **kwargs) + + # Ensure that the _macos_vers works correctly + with mock.patch('builtins.open', mock.Mock(side_effect=fake_open)) as m: + assert pkg_resources._macos_vers([]) == ["11", "4"] + + m.assert_called() + + class TestDeepVersionLookupDistutils: @pytest.fixture def env(self, tmpdir):