diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2016-06-06 07:23:42 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2016-06-06 07:23:42 -0400 |
commit | df3905616933c90af95e99f705b800a2f5c1c921 (patch) | |
tree | f9def47225ce6dd5d88cd51bd7442f3c78aab877 /setuptools/tests | |
parent | 48b63f309650af9e43368cf0d6792ea247ad8663 (diff) | |
parent | f43c0f0651edfe1f52b0a178cfe2a5234a008af0 (diff) | |
download | external_python_setuptools-df3905616933c90af95e99f705b800a2f5c1c921.tar.gz external_python_setuptools-df3905616933c90af95e99f705b800a2f5c1c921.tar.bz2 external_python_setuptools-df3905616933c90af95e99f705b800a2f5c1c921.zip |
Merge with master
Diffstat (limited to 'setuptools/tests')
-rw-r--r-- | setuptools/tests/py26compat.py | 8 | ||||
-rw-r--r-- | setuptools/tests/test_build_py.py | 31 | ||||
-rw-r--r-- | setuptools/tests/test_easy_install.py | 14 | ||||
-rw-r--r-- | setuptools/tests/test_egg_info.py | 80 | ||||
-rw-r--r-- | setuptools/tests/test_upload_docs.py | 12 |
5 files changed, 137 insertions, 8 deletions
diff --git a/setuptools/tests/py26compat.py b/setuptools/tests/py26compat.py index c5680881..7211f275 100644 --- a/setuptools/tests/py26compat.py +++ b/setuptools/tests/py26compat.py @@ -3,10 +3,10 @@ import tarfile import contextlib def _tarfile_open_ex(*args, **kwargs): - """ - Extend result as a context manager. - """ - return contextlib.closing(tarfile.open(*args, **kwargs)) + """ + Extend result as a context manager. + """ + return contextlib.closing(tarfile.open(*args, **kwargs)) if sys.version_info[:2] < (2, 7) or (3, 0) <= sys.version_info[:2] < (3, 2): tarfile_open = _tarfile_open_ex diff --git a/setuptools/tests/test_build_py.py b/setuptools/tests/test_build_py.py new file mode 100644 index 00000000..ed1703ac --- /dev/null +++ b/setuptools/tests/test_build_py.py @@ -0,0 +1,31 @@ +import os + +import pytest + +from setuptools.dist import Distribution + + +@pytest.yield_fixture +def tmpdir_as_cwd(tmpdir): + with tmpdir.as_cwd(): + yield tmpdir + + +def test_directories_in_package_data_glob(tmpdir_as_cwd): + """ + Directories matching the glob in package_data should + not be included in the package data. + + Regression test for #261. + """ + dist = Distribution(dict( + script_name='setup.py', + script_args=['build_py'], + packages=[''], + name='foo', + package_data={'': ['path/*']}, + )) + os.makedirs('path/subpath') + #with contexts.quiet(): + dist.parse_command_line() + dist.run_commands() diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py index 55b8b05a..fd06b6ef 100644 --- a/setuptools/tests/test_easy_install.py +++ b/setuptools/tests/test_easy_install.py @@ -6,7 +6,6 @@ from __future__ import absolute_import import sys import os -import shutil import tempfile import site import contextlib @@ -119,6 +118,19 @@ class TestEasyInstallTest: with pytest.raises(distutils.errors.DistutilsError): cmd.cant_write_to_target() + def test_all_site_dirs(self, monkeypatch): + """ + get_site_dirs should always return site dirs reported by + site.getsitepackages. + """ + mock_gsp = lambda: ['/setuptools/test/site-packages'] + monkeypatch.setattr(site, 'getsitepackages', mock_gsp, raising=False) + assert '/setuptools/test/site-packages' in ei.get_site_dirs() + + def test_all_site_dirs_works_without_getsitepackages(self, monkeypatch): + monkeypatch.delattr(site, 'getsitepackages', raising=False) + assert ei.get_site_dirs() + class TestPTHFileWriter: def test_add_from_cwd_site_sets_dirty(self): diff --git a/setuptools/tests/test_egg_info.py b/setuptools/tests/test_egg_info.py index d37567b4..3a0db58f 100644 --- a/setuptools/tests/test_egg_info.py +++ b/setuptools/tests/test_egg_info.py @@ -1,7 +1,11 @@ import os import glob +import re import stat +import sys +from setuptools.command.egg_info import egg_info +from setuptools.dist import Distribution from setuptools.extern.six.moves import map import pytest @@ -59,6 +63,79 @@ class TestEggInfo(object): }) yield env + def test_egg_info_save_version_info_setup_empty(self, tmpdir_cwd, env): + """ + When the egg_info section is empty or not present, running + save_version_info should add the settings to the setup.cfg + in a deterministic order, consistent with the ordering found + on Python 2.6 and 2.7 with PYTHONHASHSEED=0. + """ + setup_cfg = os.path.join(env.paths['home'], 'setup.cfg') + dist = Distribution() + ei = egg_info(dist) + ei.initialize_options() + ei.save_version_info(setup_cfg) + + with open(setup_cfg, 'r') as f: + content = f.read() + + assert '[egg_info]' in content + assert 'tag_build =' in content + assert 'tag_date = 0' in content + assert 'tag_svn_revision = 0' in content + + expected_order = 'tag_build', 'tag_date', 'tag_svn_revision' + + self._validate_content_order(content, expected_order) + + @staticmethod + def _validate_content_order(content, expected): + """ + Assert that the strings in expected appear in content + in order. + """ + if sys.version_info < (2, 7): + # On Python 2.6, expect dict key order. + expected = dict.fromkeys(expected).keys() + + pattern = '.*'.join(expected) + flags = re.MULTILINE | re.DOTALL + assert re.search(pattern, content, flags) + + def test_egg_info_save_version_info_setup_defaults(self, tmpdir_cwd, env): + """ + When running save_version_info on an existing setup.cfg + with the 'default' values present from a previous run, + the file should remain unchanged, except on Python 2.6, + where the order of the keys will be changed to match the + order as found in a dictionary of those keys. + """ + setup_cfg = os.path.join(env.paths['home'], 'setup.cfg') + build_files({ + setup_cfg: DALS(""" + [egg_info] + tag_build = + tag_date = 0 + tag_svn_revision = 0 + """), + }) + dist = Distribution() + ei = egg_info(dist) + ei.initialize_options() + ei.save_version_info(setup_cfg) + + with open(setup_cfg, 'r') as f: + content = f.read() + + assert '[egg_info]' in content + assert 'tag_build =' in content + assert 'tag_date = 0' in content + assert 'tag_svn_revision = 0' in content + + expected_order = 'tag_build', 'tag_date', 'tag_svn_revision' + + self._validate_content_order(content, expected_order) + def test_egg_base_installed_egg_info(self, tmpdir_cwd, env): self._create_project() @@ -104,7 +181,6 @@ class TestEggInfo(object): 'setup.py': setup_script, }) - @pytest.mark.xfail(reason="Functionality disabled; see #523") def test_install_requires_with_markers(self, tmpdir_cwd, env): self._setup_script_with_requires( """install_requires=["barbazquux;python_version<'2'"],""") @@ -115,14 +191,12 @@ class TestEggInfo(object): requires_txt).read().split('\n') assert glob.glob(os.path.join(env.paths['lib'], 'barbazquux*')) == [] - @pytest.mark.xfail(reason="Functionality disabled; see #523") def test_setup_requires_with_markers(self, tmpdir_cwd, env): self._setup_script_with_requires( """setup_requires=["barbazquux;python_version<'2'"],""") self._run_install_command(tmpdir_cwd, env) assert glob.glob(os.path.join(env.paths['lib'], 'barbazquux*')) == [] - @pytest.mark.xfail(reason="Functionality disabled; see #523") def test_tests_require_with_markers(self, tmpdir_cwd, env): self._setup_script_with_requires( """tests_require=["barbazquux;python_version<'2'"],""") diff --git a/setuptools/tests/test_upload_docs.py b/setuptools/tests/test_upload_docs.py index cc71cadb..d3dee616 100644 --- a/setuptools/tests/test_upload_docs.py +++ b/setuptools/tests/test_upload_docs.py @@ -57,3 +57,15 @@ class TestUploadDocsTest: with contextlib.closing(zipfile.ZipFile(tmp_file)) as zip_file: assert zip_file.namelist() == ['index.html'] + + def test_build_multipart(self): + data = dict( + a="foo", + b="bar", + file=('file.txt', b'content'), + ) + body, content_type = upload_docs._build_multipart(data) + assert 'form-data' in content_type + assert isinstance(body, bytes) + assert b'foo' in body + assert b'content' in body |