From bfc525457225a7c0a45553d0fcf29592230e9855 Mon Sep 17 00:00:00 2001 From: Luke Plant Date: Mon, 19 Oct 2015 12:06:08 +0100 Subject: Added test utility for building files quickly. And made use of it in test_egg_info. --- setuptools/tests/files.py | 32 ++++++++++++++++++++++++++++++++ setuptools/tests/test_egg_info.py | 23 ++++++++++++----------- 2 files changed, 44 insertions(+), 11 deletions(-) create mode 100644 setuptools/tests/files.py (limited to 'setuptools/tests') diff --git a/setuptools/tests/files.py b/setuptools/tests/files.py new file mode 100644 index 00000000..4364241b --- /dev/null +++ b/setuptools/tests/files.py @@ -0,0 +1,32 @@ +import os + + +def build_files(file_defs, prefix=""): + """ + Build a set of files/directories, as described by the file_defs dictionary. + + Each key/value pair in the dictionary is interpreted as a filename/contents + pair. If the contents value is a dictionary, a directory is created, and the + dictionary interpreted as the files within it, recursively. + + For example: + + {"README.txt": "A README file", + "foo": { + "__init__.py": "", + "bar": { + "__init__.py": "", + }, + "baz.py": "# Some code", + } + } + """ + for name, contents in file_defs.items(): + full_name = os.path.join(prefix, name) + if isinstance(contents, dict): + if not os.path.exists(full_name): + os.makedirs(full_name) + build_files(contents, prefix=full_name) + else: + with open(full_name, 'w') as f: + f.write(contents) diff --git a/setuptools/tests/test_egg_info.py b/setuptools/tests/test_egg_info.py index a1caf9fd..8d831107 100644 --- a/setuptools/tests/test_egg_info.py +++ b/setuptools/tests/test_egg_info.py @@ -4,6 +4,7 @@ import stat import pytest from . import environment +from .files import build_files from .textwrap import DALS from . import contexts @@ -22,14 +23,13 @@ class TestEggInfo: """) def _create_project(self): - with open('setup.py', 'w') as f: - f.write(self.setup_script) - - with open('hello.py', 'w') as f: - f.write(DALS(""" + build_files({ + 'setup.py': self.setup_script, + 'hello.py': DALS(""" def run(): print('hello') - """)) + """) + }) @pytest.yield_fixture def env(self): @@ -44,13 +44,14 @@ class TestEggInfo: for dirname in subs ) list(map(os.mkdir, env.paths.values())) - config = os.path.join(env.paths['home'], '.pydistutils.cfg') - with open(config, 'w') as f: - f.write(DALS(""" + build_files({ + env.paths['home']: { + '.pydistutils.cfg': DALS(""" [egg_info] egg-base = %(egg-base)s - """ % env.paths - )) + """ % env.paths) + } + }) yield env def test_egg_base_installed_egg_info(self, tmpdir_cwd, env): -- cgit v1.2.3 From 0b9fa15f89c18733d3b17d147a64a72134e0d8a3 Mon Sep 17 00:00:00 2001 From: Luke Plant Date: Mon, 19 Oct 2015 11:49:29 +0100 Subject: Pulled out some test code for re-use. --- setuptools/tests/test_egg_info.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'setuptools/tests') diff --git a/setuptools/tests/test_egg_info.py b/setuptools/tests/test_egg_info.py index 8d831107..4977ea01 100644 --- a/setuptools/tests/test_egg_info.py +++ b/setuptools/tests/test_egg_info.py @@ -57,6 +57,20 @@ class TestEggInfo: def test_egg_base_installed_egg_info(self, tmpdir_cwd, env): self._create_project() + self._run_install_command(tmpdir_cwd, env) + actual = self._find_egg_info_files(env.paths['lib']) + + expected = [ + 'PKG-INFO', + 'SOURCES.txt', + 'dependency_links.txt', + 'entry_points.txt', + 'not-zip-safe', + 'top_level.txt', + ] + assert sorted(actual) == expected + + def _run_install_command(self, tmpdir_cwd, env): environ = os.environ.copy().update( HOME=env.paths['home'], ) @@ -76,18 +90,6 @@ class TestEggInfo: if code: raise AssertionError(data) - actual = self._find_egg_info_files(env.paths['lib']) - - expected = [ - 'PKG-INFO', - 'SOURCES.txt', - 'dependency_links.txt', - 'entry_points.txt', - 'not-zip-safe', - 'top_level.txt', - ] - assert sorted(actual) == expected - def _find_egg_info_files(self, root): results = ( filenames -- cgit v1.2.3 From a9c3739984908d8ed9e902e3a6efe21f031c2908 Mon Sep 17 00:00:00 2001 From: Luke Plant Date: Mon, 19 Oct 2015 12:04:26 +0100 Subject: Added test to ensure that egg_info applies MANIFEST.in The 'self.read_template()' line of manifest_maker was previously uncovered by any test, and the test suite passed if you commented it out. --- setuptools/tests/test_egg_info.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'setuptools/tests') diff --git a/setuptools/tests/test_egg_info.py b/setuptools/tests/test_egg_info.py index 4977ea01..8281fdc1 100644 --- a/setuptools/tests/test_egg_info.py +++ b/setuptools/tests/test_egg_info.py @@ -58,7 +58,7 @@ class TestEggInfo: self._create_project() self._run_install_command(tmpdir_cwd, env) - actual = self._find_egg_info_files(env.paths['lib']) + _, actual = self._find_egg_info_files(env.paths['lib']) expected = [ 'PKG-INFO', @@ -70,6 +70,21 @@ class TestEggInfo: ] assert sorted(actual) == expected + def test_manifest_template_is_read(self, tmpdir_cwd, env): + self._create_project() + build_files({ + 'MANIFEST.in': DALS(""" + recursive-include docs *.rst + """), + 'docs': { + 'usage.rst': "Run 'hi'", + } + }) + self._run_install_command(tmpdir_cwd, env) + egg_info_dir, _ = self._find_egg_info_files(env.paths['lib']) + sources_txt = os.path.join(egg_info_dir, 'SOURCES.txt') + assert 'docs/usage.rst' in open(sources_txt).read().split('\n') + def _run_install_command(self, tmpdir_cwd, env): environ = os.environ.copy().update( HOME=env.paths['home'], @@ -92,7 +107,7 @@ class TestEggInfo: def _find_egg_info_files(self, root): results = ( - filenames + (dirpath, filenames) for dirpath, dirnames, filenames in os.walk(root) if os.path.basename(dirpath) == 'EGG-INFO' ) -- cgit v1.2.3