Skip to content

Commit

Permalink
Add unit tests for manual SOABI detection
Browse files Browse the repository at this point in the history
  • Loading branch information
natefoo committed Oct 13, 2015
1 parent a55fa5a commit 1b5b4ac
Showing 1 changed file with 70 additions and 7 deletions.
77 changes: 70 additions & 7 deletions tests/unit/test_wheel.py
Expand Up @@ -294,6 +294,50 @@ def test_version_underscore_conversion(self):

class TestPEP425Tags(object):

def mock_get_config_var(self, **kwd):
"""
Patch sysconfig.get_config_var for arbitrary keys.
"""
import pip.pep425tags

get_config_var = pip.pep425tags.sysconfig.get_config_var

def _mock_get_config_var(var):
if var in kwd:
return kwd[var]
return get_config_var(var)
return _mock_get_config_var

def abi_tag_unicode(self, flags, config_vars):
"""
Used to test ABI tags, verify correct use of the `u` flag
"""
import pip.pep425tags

config_vars.update({'SOABI': None})
base = pip.pep425tags.get_abbr_impl() + pip.pep425tags.get_impl_ver()

config_vars.update({'Py_UNICODE_SIZE': 2})
mock_gcf = self.mock_get_config_var(**config_vars)
with patch('pip.pep425tags.sysconfig.get_config_var', mock_gcf):
abi_tag = pip.pep425tags.get_abi_tag()
assert abi_tag == base + flags

config_vars.update({'Py_UNICODE_SIZE': 4})
mock_gcf = self.mock_get_config_var(**config_vars)
with patch('pip.pep425tags.sysconfig.get_config_var', mock_gcf):
abi_tag = pip.pep425tags.get_abi_tag()
assert abi_tag == base + flags + 'u'

# On Python >= 3.3, UCS-4 is essentially permanently enabled, and
# Py_UNICODE_SIZE is None. SOABI on these builds does not include the
# 'u' so manual SOABI detection should not do so either.
config_vars.update({'Py_UNICODE_SIZE': None})
mock_gcf = self.mock_get_config_var(**config_vars)
with patch('pip.pep425tags.sysconfig.get_config_var', mock_gcf):
abi_tag = pip.pep425tags.get_abi_tag()
assert abi_tag == base + flags

def test_broken_sysconfig(self):
"""
Test that pep425tags still works when sysconfig is broken.
Expand All @@ -314,21 +358,40 @@ def test_no_hyphen_tag(self):
"""
import pip.pep425tags

get_config_var = pip.pep425tags.sysconfig.get_config_var

def mock_soabi(var):
if var == 'SOABI':
return 'cpython-35m-darwin'
return get_config_var(var)
mock_gcf = self.mock_get_config_var(SOABI='cpython-35m-darwin')

with patch('pip.pep425tags.sysconfig.get_config_var', mock_soabi):
with patch('pip.pep425tags.sysconfig.get_config_var', mock_gcf):
supported = pip.pep425tags.get_supported()

for (py, abi, plat) in supported:
assert '-' not in py
assert '-' not in abi
assert '-' not in plat

def test_manual_abi_noflags(self):
"""
Test that no flags are set on a non-PyDebug, non-Pymalloc ABI tag.
"""
self.abi_tag_unicode('', {'Py_DEBUG': False, 'WITH_PYMALLOC': False})

def test_manual_abi_d_flag(self):
"""
Test that the `d` flag is set on a PyDebug, non-Pymalloc ABI tag.
"""
self.abi_tag_unicode('d', {'Py_DEBUG': True, 'WITH_PYMALLOC': False})

def test_manual_abi_m_flag(self):
"""
Test that the `m` flag is set on a non-PyDebug, Pymalloc ABI tag.
"""
self.abi_tag_unicode('m', {'Py_DEBUG': False, 'WITH_PYMALLOC': True})

def test_manual_abi_dm_flags(self):
"""
Test that the `dm` flags are set on a PyDebug, Pymalloc ABI tag.
"""
self.abi_tag_unicode('dm', {'Py_DEBUG': True, 'WITH_PYMALLOC': True})


class TestMoveWheelFiles(object):
"""
Expand Down

0 comments on commit 1b5b4ac

Please sign in to comment.