|
| 1 | +import builtins |
1 | 2 | import sys
|
2 | 3 | import tempfile
|
3 | 4 | import os
|
4 | 5 | import zipfile
|
5 | 6 | import datetime
|
6 | 7 | import time
|
| 8 | +import plistlib |
7 | 9 | import subprocess
|
8 | 10 | import stat
|
9 | 11 | import distutils.dist
|
@@ -323,6 +325,30 @@ def test_dist_info_is_not_dir(tmp_path, only):
|
323 | 325 | assert not pkg_resources.dist_factory(str(tmp_path), str(dist_info), only)
|
324 | 326 |
|
325 | 327 |
|
| 328 | +def test_macos_vers_fallback(monkeypatch, tmp_path): |
| 329 | + """Regression test for pkg_resources._macos_vers""" |
| 330 | + orig_open = builtins.open |
| 331 | + |
| 332 | + # Pretend we need to use the plist file |
| 333 | + monkeypatch.setattr('platform.mac_ver', mock.Mock(return_value=('', (), ''))) |
| 334 | + |
| 335 | + # Create fake content for the fake plist file |
| 336 | + with open(tmp_path / 'fake.plist', 'wb') as fake_file: |
| 337 | + plistlib.dump({"ProductVersion": "11.4"}, fake_file) |
| 338 | + |
| 339 | + # Pretend the fake file exists |
| 340 | + monkeypatch.setattr('os.path.exists', mock.Mock(return_value=True)) |
| 341 | + |
| 342 | + def fake_open(file, *args, **kwargs): |
| 343 | + return orig_open(tmp_path / 'fake.plist', *args, **kwargs) |
| 344 | + |
| 345 | + # Ensure that the _macos_vers works correctly |
| 346 | + with mock.patch('builtins.open', mock.Mock(side_effect=fake_open)) as m: |
| 347 | + assert pkg_resources._macos_vers([]) == ["11", "4"] |
| 348 | + |
| 349 | + m.assert_called() |
| 350 | + |
| 351 | + |
326 | 352 | class TestDeepVersionLookupDistutils:
|
327 | 353 | @pytest.fixture
|
328 | 354 | def env(self, tmpdir):
|
|
0 commit comments