|
27 | 27 | )
|
28 | 28 | from pip._internal.utils.deprecation import PipDeprecationWarning, deprecated
|
29 | 29 | from pip._internal.utils.encoding import BOMS, auto_decode
|
30 |
| -from pip._internal.utils.glibc import check_glibc_version |
| 30 | +from pip._internal.utils.glibc import ( |
| 31 | + check_glibc_version, glibc_version_string, glibc_version_string_confstr, |
| 32 | + glibc_version_string_ctypes, |
| 33 | +) |
31 | 34 | from pip._internal.utils.hashes import Hashes, MissingHashes
|
32 | 35 | from pip._internal.utils.misc import (
|
33 | 36 | call_subprocess, egg_link_path, ensure_dir, format_command_args,
|
@@ -704,6 +707,10 @@ def raising_mkdir(*args, **kwargs):
|
704 | 707 | pass
|
705 | 708 |
|
706 | 709 |
|
| 710 | +def raises(error): |
| 711 | + raise error |
| 712 | + |
| 713 | + |
707 | 714 | class TestGlibc(object):
|
708 | 715 | def test_manylinux_check_glibc_version(self):
|
709 | 716 | """
|
@@ -737,6 +744,35 @@ def test_manylinux_check_glibc_version(self):
|
737 | 744 | # Didn't find the warning we were expecting
|
738 | 745 | assert False
|
739 | 746 |
|
| 747 | + def test_glibc_version_string(self, monkeypatch): |
| 748 | + monkeypatch.setattr( |
| 749 | + os, "confstr", lambda x: "glibc 2.20", raising=False, |
| 750 | + ) |
| 751 | + assert glibc_version_string() == "2.20" |
| 752 | + |
| 753 | + def test_glibc_version_string_confstr(self, monkeypatch): |
| 754 | + monkeypatch.setattr( |
| 755 | + os, "confstr", lambda x: "glibc 2.20", raising=False, |
| 756 | + ) |
| 757 | + assert glibc_version_string_confstr() == "2.20" |
| 758 | + |
| 759 | + @pytest.mark.parametrize("failure", [ |
| 760 | + lambda x: raises(ValueError), |
| 761 | + lambda x: raises(OSError), |
| 762 | + lambda x: "XXX", |
| 763 | + ]) |
| 764 | + def test_glibc_version_string_confstr_fail(self, monkeypatch, failure): |
| 765 | + monkeypatch.setattr(os, "confstr", failure, raising=False) |
| 766 | + assert glibc_version_string_confstr() is None |
| 767 | + |
| 768 | + def test_glibc_version_string_confstr_missing(self, monkeypatch): |
| 769 | + monkeypatch.delattr(os, "confstr", raising=False) |
| 770 | + assert glibc_version_string_confstr() is None |
| 771 | + |
| 772 | + def test_glibc_version_string_ctypes_missing(self, monkeypatch): |
| 773 | + monkeypatch.setitem(sys.modules, "ctypes", None) |
| 774 | + assert glibc_version_string_ctypes() is None |
| 775 | + |
740 | 776 |
|
741 | 777 | @pytest.mark.parametrize('version_info, expected', [
|
742 | 778 | ((), (0, 0, 0)),
|
|
0 commit comments