aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/tests
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2014-09-29 21:14:51 -0400
committerJason R. Coombs <jaraco@jaraco.com>2014-09-29 21:14:51 -0400
commit626fa69fb0470710e870628afd0cb7ec0ba96ddf (patch)
treebefcacc09c560133266eb5a1757a45ea43d93453 /setuptools/tests
parent96aed21b42121acde68dd6b3732c3fbae0903569 (diff)
parent9e7f35fec4178dea678693cb768b6076d45e7ddd (diff)
downloadexternal_python_setuptools-626fa69fb0470710e870628afd0cb7ec0ba96ddf.tar.gz
external_python_setuptools-626fa69fb0470710e870628afd0cb7ec0ba96ddf.tar.bz2
external_python_setuptools-626fa69fb0470710e870628afd0cb7ec0ba96ddf.zip
Merge with 6.0.2
--HG-- branch : feature/issue-229
Diffstat (limited to 'setuptools/tests')
-rw-r--r--setuptools/tests/test_integration.py3
-rw-r--r--setuptools/tests/test_msvc9compiler.py157
-rw-r--r--setuptools/tests/test_resources.py27
-rw-r--r--setuptools/tests/test_sandbox.py10
-rw-r--r--setuptools/tests/test_sdist.py28
-rw-r--r--setuptools/tests/win_script_wrapper.txt8
6 files changed, 209 insertions, 24 deletions
diff --git a/setuptools/tests/test_integration.py b/setuptools/tests/test_integration.py
index 7144aa6c..8d6c1e55 100644
--- a/setuptools/tests/test_integration.py
+++ b/setuptools/tests/test_integration.py
@@ -25,6 +25,9 @@ def install_context(request, tmpdir, monkeypatch):
install_dir = tmpdir.mkdir('install_dir')
def fin():
+ # undo the monkeypatch, particularly needed under
+ # windows because of kept handle on cwd
+ monkeypatch.undo()
new_cwd.remove()
user_base.remove()
user_site.remove()
diff --git a/setuptools/tests/test_msvc9compiler.py b/setuptools/tests/test_msvc9compiler.py
new file mode 100644
index 00000000..970f7679
--- /dev/null
+++ b/setuptools/tests/test_msvc9compiler.py
@@ -0,0 +1,157 @@
+"""msvc9compiler monkey patch test
+
+This test ensures that importing setuptools is sufficient to replace
+the standard find_vcvarsall function with our patched version that
+finds the Visual C++ for Python package.
+"""
+
+import os
+import shutil
+import sys
+import tempfile
+import unittest
+import distutils.errors
+import contextlib
+
+# importing only setuptools should apply the patch
+__import__('setuptools')
+
+class MockReg:
+ """Mock for distutils.msvc9compiler.Reg. We patch it
+ with an instance of this class that mocks out the
+ functions that access the registry.
+ """
+
+ def __init__(self, hkey_local_machine={}, hkey_current_user={}):
+ self.hklm = hkey_local_machine
+ self.hkcu = hkey_current_user
+
+ def __enter__(self):
+ self.original_read_keys = distutils.msvc9compiler.Reg.read_keys
+ self.original_read_values = distutils.msvc9compiler.Reg.read_values
+
+ _winreg = getattr(distutils.msvc9compiler, '_winreg', None)
+ winreg = getattr(distutils.msvc9compiler, 'winreg', _winreg)
+
+ hives = {
+ winreg.HKEY_CURRENT_USER: self.hkcu,
+ winreg.HKEY_LOCAL_MACHINE: self.hklm,
+ }
+
+ def read_keys(cls, base, key):
+ """Return list of registry keys."""
+ hive = hives.get(base, {})
+ return [k.rpartition('\\')[2]
+ for k in hive if k.startswith(key.lower())]
+
+ def read_values(cls, base, key):
+ """Return dict of registry keys and values."""
+ hive = hives.get(base, {})
+ return dict((k.rpartition('\\')[2], hive[k])
+ for k in hive if k.startswith(key.lower()))
+
+ distutils.msvc9compiler.Reg.read_keys = classmethod(read_keys)
+ distutils.msvc9compiler.Reg.read_values = classmethod(read_values)
+
+ return self
+
+ def __exit__(self, exc_type, exc_value, exc_tb):
+ distutils.msvc9compiler.Reg.read_keys = self.original_read_keys
+ distutils.msvc9compiler.Reg.read_values = self.original_read_values
+
+@contextlib.contextmanager
+def patch_env(**replacements):
+ """
+ In a context, patch the environment with replacements. Pass None values
+ to clear the values.
+ """
+ saved = dict(
+ (key, os.environ['key'])
+ for key in replacements
+ if key in os.environ
+ )
+
+ # remove values that are null
+ remove = (key for (key, value) in replacements.items() if value is None)
+ for key in list(remove):
+ os.environ.pop(key, None)
+ replacements.pop(key)
+
+ os.environ.update(replacements)
+
+ try:
+ yield saved
+ finally:
+ for key in replacements:
+ os.environ.pop(key, None)
+ os.environ.update(saved)
+
+class TestMSVC9Compiler(unittest.TestCase):
+
+ def test_find_vcvarsall_patch(self):
+ if not hasattr(distutils, 'msvc9compiler'):
+ # skip
+ return
+
+ self.assertEqual(
+ "setuptools.msvc9_support",
+ distutils.msvc9compiler.find_vcvarsall.__module__,
+ "find_vcvarsall was not patched"
+ )
+
+ find_vcvarsall = distutils.msvc9compiler.find_vcvarsall
+ query_vcvarsall = distutils.msvc9compiler.query_vcvarsall
+
+ # No registry entries or environment variable means we should
+ # not find anything
+ with patch_env(VS90COMNTOOLS=None):
+ with MockReg():
+ self.assertIsNone(find_vcvarsall(9.0))
+
+ try:
+ query_vcvarsall(9.0)
+ self.fail('Expected DistutilsPlatformError from query_vcvarsall()')
+ except distutils.errors.DistutilsPlatformError:
+ exc_message = str(sys.exc_info()[1])
+ self.assertIn('aka.ms/vcpython27', exc_message)
+
+ key_32 = r'software\microsoft\devdiv\vcforpython\9.0\installdir'
+ key_64 = r'software\wow6432node\microsoft\devdiv\vcforpython\9.0\installdir'
+
+ # Make two mock files so we can tell whether HCKU entries are
+ # preferred to HKLM entries.
+ mock_installdir_1 = tempfile.mkdtemp()
+ mock_vcvarsall_bat_1 = os.path.join(mock_installdir_1, 'vcvarsall.bat')
+ open(mock_vcvarsall_bat_1, 'w').close()
+ mock_installdir_2 = tempfile.mkdtemp()
+ mock_vcvarsall_bat_2 = os.path.join(mock_installdir_2, 'vcvarsall.bat')
+ open(mock_vcvarsall_bat_2, 'w').close()
+ try:
+ # Ensure we get the current user's setting first
+ with MockReg(
+ hkey_current_user={key_32: mock_installdir_1},
+ hkey_local_machine={
+ key_32: mock_installdir_2,
+ key_64: mock_installdir_2,
+ }
+ ):
+ self.assertEqual(mock_vcvarsall_bat_1, find_vcvarsall(9.0))
+
+ # Ensure we get the local machine value if it's there
+ with MockReg(hkey_local_machine={key_32: mock_installdir_2}):
+ self.assertEqual(mock_vcvarsall_bat_2, find_vcvarsall(9.0))
+
+ # Ensure we prefer the 64-bit local machine key
+ # (*not* the Wow6432Node key)
+ with MockReg(
+ hkey_local_machine={
+ # This *should* only exist on 32-bit machines
+ key_32: mock_installdir_1,
+ # This *should* only exist on 64-bit machines
+ key_64: mock_installdir_2,
+ }
+ ):
+ self.assertEqual(mock_vcvarsall_bat_1, find_vcvarsall(9.0))
+ finally:
+ shutil.rmtree(mock_installdir_1)
+ shutil.rmtree(mock_installdir_2)
diff --git a/setuptools/tests/test_resources.py b/setuptools/tests/test_resources.py
index 2db87efa..b688cfe0 100644
--- a/setuptools/tests/test_resources.py
+++ b/setuptools/tests/test_resources.py
@@ -15,14 +15,10 @@ from pkg_resources import (parse_requirements, VersionConflict, parse_version,
from setuptools.command.easy_install import (get_script_header, is_sh,
nt_quote_arg)
+from .py26compat import skipIf
import six
-try:
- frozenset
-except NameError:
- from sets import ImmutableSet as frozenset
-
def safe_repr(obj, short=False):
""" copied from Python2.7"""
try:
@@ -576,13 +572,8 @@ class NamespaceTests(TestCase):
pkg_resources._namespace_packages = self._ns_pkgs.copy()
sys.path = self._prev_sys_path[:]
- def _assertIn(self, member, container):
- """ assertIn and assertTrue does not exist in Python2.3"""
- if member not in container:
- standardMsg = '%s not found in %s' % (safe_repr(member),
- safe_repr(container))
- self.fail(self._formatMessage(msg, standardMsg))
-
+ msg = "Test fails when /tmp is a symlink. See #231"
+ @skipIf(os.path.islink(tempfile.gettempdir()), msg)
def test_two_levels_deep(self):
"""
Test nested namespace packages
@@ -606,15 +597,17 @@ class NamespaceTests(TestCase):
pkg2_init.write(ns_str)
pkg2_init.close()
import pkg1
- self._assertIn("pkg1", pkg_resources._namespace_packages.keys())
+ assert "pkg1" in pkg_resources._namespace_packages
try:
import pkg1.pkg2
except ImportError:
self.fail("Setuptools tried to import the parent namespace package")
# check the _namespace_packages dict
- self._assertIn("pkg1.pkg2", pkg_resources._namespace_packages.keys())
- self.assertEqual(pkg_resources._namespace_packages["pkg1"], ["pkg1.pkg2"])
+ assert "pkg1.pkg2" in pkg_resources._namespace_packages
+ assert pkg_resources._namespace_packages["pkg1"] == ["pkg1.pkg2"]
# check the __path__ attribute contains both paths
- self.assertEqual(pkg1.pkg2.__path__, [
+ expected = [
os.path.join(self._tmpdir, "site-pkgs", "pkg1", "pkg2"),
- os.path.join(self._tmpdir, "site-pkgs2", "pkg1", "pkg2")])
+ os.path.join(self._tmpdir, "site-pkgs2", "pkg1", "pkg2"),
+ ]
+ assert pkg1.pkg2.__path__ == expected
diff --git a/setuptools/tests/test_sandbox.py b/setuptools/tests/test_sandbox.py
index 06b3d434..6a890ebc 100644
--- a/setuptools/tests/test_sandbox.py
+++ b/setuptools/tests/test_sandbox.py
@@ -19,7 +19,7 @@ def has_win32com():
if not sys.platform.startswith('win32'):
return False
try:
- mod = __import__('win32com')
+ __import__('win32com')
except ImportError:
return False
return True
@@ -33,8 +33,6 @@ class TestSandbox(unittest.TestCase):
shutil.rmtree(self.dir)
def test_devnull(self):
- if sys.version < '2.4':
- return
sandbox = DirectorySandbox(self.dir)
sandbox.run(self._file_writer(os.devnull))
@@ -75,5 +73,11 @@ class TestSandbox(unittest.TestCase):
setuptools.sandbox._execfile(target, vars(namespace))
assert namespace.result == 'passed'
+ def test_setup_py_with_CRLF(self):
+ setup_py = os.path.join(self.dir, 'setup.py')
+ with open(setup_py, 'wb') as stream:
+ stream.write(b'"degenerate script"\r\n')
+ setuptools.sandbox._execfile(setup_py, globals())
+
if __name__ == '__main__':
unittest.main()
diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py
index c78e5b0f..26b072cc 100644
--- a/setuptools/tests/test_sdist.py
+++ b/setuptools/tests/test_sdist.py
@@ -87,6 +87,7 @@ class TestSdistTest(unittest.TestCase):
f = open(os.path.join(self.temp_dir, 'setup.py'), 'w')
f.write(SETUP_PY)
f.close()
+
# Set up the rest of the test package
test_pkg = os.path.join(self.temp_dir, 'sdist_test')
os.mkdir(test_pkg)
@@ -122,6 +123,33 @@ class TestSdistTest(unittest.TestCase):
self.assertTrue(os.path.join('sdist_test', 'b.txt') in manifest)
self.assertTrue(os.path.join('sdist_test', 'c.rst') not in manifest)
+
+ def test_defaults_case_sensitivity(self):
+ """
+ Make sure default files (README.*, etc.) are added in a case-sensitive
+ way to avoid problems with packages built on Windows.
+ """
+
+ open(os.path.join(self.temp_dir, 'readme.rst'), 'w').close()
+ open(os.path.join(self.temp_dir, 'SETUP.cfg'), 'w').close()
+
+ dist = Distribution(SETUP_ATTRS)
+ # the extension deliberately capitalized for this test
+ # to make sure the actual filename (not capitalized) gets added
+ # to the manifest
+ dist.script_name = 'setup.PY'
+ cmd = sdist(dist)
+ cmd.ensure_finalized()
+
+ with quiet():
+ cmd.run()
+
+ # lowercase all names so we can test in a case-insensitive way to make sure the files are not included
+ manifest = map(lambda x: x.lower(), cmd.filelist.files)
+ self.assertFalse('readme.rst' in manifest, manifest)
+ self.assertFalse('setup.py' in manifest, manifest)
+ self.assertFalse('setup.cfg' in manifest, manifest)
+
def test_manifest_is_written_with_utf8_encoding(self):
# Test for #303.
dist = Distribution(SETUP_ATTRS)
diff --git a/setuptools/tests/win_script_wrapper.txt b/setuptools/tests/win_script_wrapper.txt
index 731243dd..b3a52e0a 100644
--- a/setuptools/tests/win_script_wrapper.txt
+++ b/setuptools/tests/win_script_wrapper.txt
@@ -3,7 +3,7 @@ Python Script Wrapper for Windows
setuptools includes wrappers for Python scripts that allows them to be
executed like regular windows programs. There are 2 wrappers, once
-for command-line programs, cli.exe, and one for graphica programs,
+for command-line programs, cli.exe, and one for graphical programs,
gui.exe. These programs are almost identical, function pretty much
the same way, and are generated from the same source file. The
wrapper programs are used by copying them to the directory containing
@@ -44,7 +44,7 @@ We'll also copy cli.exe to the sample-directory with the name foo.exe:
When the copy of cli.exe, foo.exe in this example, runs, it examines
the path name it was run with and computes a Python script path name
-by removing the '.exe' suffic and adding the '-script.py' suffix. (For
+by removing the '.exe' suffix and adding the '-script.py' suffix. (For
GUI programs, the suffix '-script-pyw' is added.) This is why we
named out script the way we did. Now we can run out script by running
the wrapper:
@@ -68,8 +68,8 @@ This example was a little pathological in that it exercised windows
- Double quotes in strings need to be escaped by preceding them with
back slashes.
-- One or more backslashes preceding double quotes quotes need to be
- escaped by preceding each of them them with back slashes.
+- One or more backslashes preceding double quotes need to be escaped
+ by preceding each of them with back slashes.
Specifying Python Command-line Options