Skip to content
Merged
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ def readall(*args):
packages=find_packages(),
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",
extras_require={
'test': ['pytest >= 3.0.0', 'pytest-cov']
'test': ['pytest >= 3.0.0', 'pytest-cov', 'pytest-mock']
},
include_package_data=True,
zip_safe=False,
entry_points={
'console_scripts': [
'wheel=wheel.cli:main'
'wheel=wheel.cli:main',
Comment thread
Czaki marked this conversation as resolved.
Outdated
],
'distutils.commands': [
'bdist_wheel=wheel.bdist_wheel:bdist_wheel'
Expand Down
81 changes: 81 additions & 0 deletions tests/test_lib_file_analyse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import os
from wheel.lib_file_analyse import extract_macosx_min_system_version
Comment thread
Czaki marked this conversation as resolved.
Outdated
from wheel.pep425tags import get_platform


def test_read_from_dynlib():
dirname = os.path.dirname(__file__)
dylib_dir = os.path.join(dirname, "testdata",
"macos_minimal_system_version")
versions = [
("test_lib_10_6_fat.dynlib", "10.6"),
("test_lib_10_10_fat.dynlib", "10.10"),
("test_lib_10_14_fat.dynlib", "10.14"),
("test_lib_10_6.dynlib", "10.6"),
("test_lib_10_10.dynlib", "10.10"),
("test_lib_10_14.dynlib", "10.14"),
("test_lib_10_6_386.dynlib", "10.6"),
("test_lib_10_10_386.dynlib", "10.10"),
("test_lib_10_14_386.dynlib", "10.14"),
("test_lib_multiple_fat.dynlib", "10.14")
]
for file_name, ver in versions:
extracted = extract_macosx_min_system_version(
os.path.join(dylib_dir, file_name)
)
str_ver = str(extracted[0]) + "." + str(extracted[1])
assert str_ver == ver
assert extract_macosx_min_system_version(
os.path.join(dylib_dir, "test_lib.c")
) is None


def test_get_platform_macos(mocker, capsys):
print(mocker, mocker.patch, mocker.patch.mock_module)
dirname = os.path.dirname(__file__)
dylib_dir = os.path.join(dirname, "testdata",
"macos_minimal_system_version")
with mocker.patch("distutils.util.get_platform", return_value="macosx-10.14-x86_64"):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're using mocks in with blocks, what's the point of using mocker in the first place?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm learning how to use mock. If I good understand in python 2.7 there is preference to use mock library and in python 3.4+ use unittests.mock.

And I do not have idea how test this functions without mock.

How to fix it in best way. change dependency on mock. Do some if depends on python version?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python 2.6 did not have unittest.mock. But Python 2.7 does. The mocker fixture, on the other hand, works like pytest's built-in monkeypatch fixture in that it automatically undoes all the mocks that it sets up during the test request.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rewrite tests to base on monkeypatch. First I think that it is not enough, but maybe I better understand it.

assert get_platform(dylib_dir) == "macosx_10_14_x86_64"
with mocker.patch("distutils.util.get_platform", return_value="macosx-10.9-x86_64"):
assert get_platform(dylib_dir) == "macosx_10_14_x86_64"
captured = capsys.readouterr()
assert "[WARNING] This wheel needs higher macosx version than" in captured.err
with mocker.patch("distutils.util.get_platform", return_value="macosx-10.9-x86_64"):
with mocker.patch("os.walk", return_value=[
(dylib_dir, [], ["test_lib_10_6.dynlib", "test_lib_10_10_fat.dynlib"])]):
assert get_platform(dylib_dir) == "macosx_10_10_x86_64"
captured = capsys.readouterr()
assert "[WARNING] This wheel needs higher macosx version than" in captured.err
assert "test_lib_10_10_fat.dynlib" in captured.err

with mocker.patch("os.walk", return_value=[
(dylib_dir, [], ["test_lib_10_6.dynlib", "test_lib_10_6_fat.dynlib"])]):
assert get_platform(dylib_dir) == "macosx_10_9_x86_64"
mocker.patch.dict('os.environ', {"MACOSX_DEPLOYMENT_TARGET": "10.10"})
assert get_platform(dylib_dir) == "macosx_10_10_x86_64"
captured = capsys.readouterr()
assert captured.err == ""

mocker.stopall()
with mocker.patch("distutils.util.get_platform", return_value="macosx-10.9-x86_64"):
mocker.patch.dict('os.environ', {"MACOSX_DEPLOYMENT_TARGET": "10.8"})
with mocker.patch("os.walk", return_value=[
(dylib_dir, [], ["test_lib_10_6.dynlib", "test_lib_10_6_fat.dynlib"])]):
assert get_platform(dylib_dir) == "macosx_10_9_x86_64"
captured = capsys.readouterr()
print("aa", captured.err)
assert "[WARNING] MACOSX_DEPLOYMENT_TARGET is set to lower value" in captured.err
with mocker.patch("os.walk", return_value=[
(dylib_dir, [], ["test_lib_10_6.dynlib", "test_lib_10_10_fat.dynlib"])]):
assert get_platform(dylib_dir) == "macosx_10_10_x86_64"
captured = capsys.readouterr()
print("aa", captured.err)
assert "[WARNING] MACOSX_DEPLOYMENT_TARGET is set to lower value" in captured.err
mocker.stopall()


def test_get_platform_linux(mocker):
with mocker.patch("distutils.util.get_platform", return_value="linux_x86_64"):
mocker.patch("sys.maxsize", new=2147483647)
assert get_platform(None) == "linux_i686"
13 changes: 13 additions & 0 deletions tests/testdata/macos_minimal_system_version/test_lib.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
int num_of_letters(char* text){
int num = 0;
char * lett = text;
while (lett != 0){
if (*lett >= 'a' && *lett <= 'z'){
num += 1;
} else if (*lett >= 'A' && *lett <= 'Z'){
num += 1;
}
lett += 1;
}
return num;
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
10 changes: 8 additions & 2 deletions wheel/bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from .pkginfo import write_pkg_info
from .metadata import pkginfo_to_metadata
from .wheelfile import WheelFile

Comment thread
Czaki marked this conversation as resolved.
Outdated
from . import pep425tags
from . import __version__ as wheel_version

Expand All @@ -48,7 +49,7 @@ class bdist_wheel(Command):
"temporary directory for creating the distribution"),
('plat-name=', 'p',
"platform name to embed in generated filenames "
"(default: %s)" % get_platform()),
"(default: %s)" % get_platform(None)),
('keep-temp', 'k',
"keep the pseudo-installation tree around after " +
"creating the distribution archive"),
Expand Down Expand Up @@ -150,7 +151,11 @@ def get_tag(self):
elif self.root_is_pure:
plat_name = 'any'
else:
plat_name = self.plat_name or get_platform()
# macosx contains system version in platform name so need special handle
if self.plat_name and not self.plat_name.startswith("macosx"):
plat_name = self.plat_name
else:
plat_name = get_platform(self.bdist_dir)
Comment thread
Czaki marked this conversation as resolved.
if plat_name in ('linux-x86_64', 'linux_x86_64') and sys.maxsize == 2147483647:
plat_name = 'linux_i686'
plat_name = plat_name.replace('-', '_').replace('.', '_')
Expand All @@ -173,6 +178,7 @@ def get_tag(self):
abi_tag = str(get_abi_tag()).lower()
tag = (impl, abi_tag, plat_name)
supported_tags = pep425tags.get_supported(
self.bdist_dir,
supplied_platform=plat_name if self.plat_name_supplied else None)
# XXX switch to this alternate implementation for non-pure:
if not self.py_limited_api:
Expand Down
Loading