diff options
author | Luke Plant <L.Plant.98@cantab.net> | 2015-10-19 12:06:08 +0100 |
---|---|---|
committer | Luke Plant <L.Plant.98@cantab.net> | 2015-10-19 12:06:08 +0100 |
commit | 25fdf1432fdb48d572167a77ba28a30a8bc35c88 (patch) | |
tree | 69142ed91470976b890074b4a27ac9ca216adc84 | |
parent | 49c8db8469414981669aee77839ebc1011f28e73 (diff) | |
download | python-setuptools-bitbucket-25fdf1432fdb48d572167a77ba28a30a8bc35c88.tar.gz |
Added test utility for building files quickly.
And made use of it in test_egg_info.
-rw-r--r-- | setuptools/tests/files.py | 32 | ||||
-rw-r--r-- | setuptools/tests/test_egg_info.py | 23 |
2 files changed, 44 insertions, 11 deletions
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): |