Commit fe6b33fc authored by Godefroid Chapelle's avatar Godefroid Chapelle

Problem: tests.py becomes very long

Solution: move to directory
starts to chop into pieces
parent c323c5f8
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2020 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import re
import os
import sys
import shutil
import tempfile
import zc.buildout
def create_sample_eggs(test, executable=sys.executable):
assert executable == sys.executable, (executable, sys.executable)
write = test.globs['write']
dest = test.globs['sample_eggs']
tmp = tempfile.mkdtemp()
try:
write(tmp, 'README.txt', '')
for i in (0, 1, 2):
write(tmp, 'eggrecipedemoneeded.py', 'y=%s\ndef f():\n pass' % i)
rc1 = i==2 and 'rc1' or ''
write(
tmp, 'setup.py',
"from setuptools import setup\n"
"setup(name='demoneeded', py_modules=['eggrecipedemoneeded'],"
" zip_safe=True, version='1.%s%s', author='bob', url='bob', "
"author_email='bob')\n"
% (i, rc1)
)
zc.buildout.testing.sdist(tmp, dest)
write(
tmp, 'distutilsscript',
'#!/usr/bin/python\n'
'# -*- coding: utf-8 -*-\n'
'"""Module docstring."""\n'
'from __future__ import print_statement\n'
'import os\n'
'import sys; sys.stdout.write("distutils!\\n")\n'
)
write(
tmp, 'setup.py',
"from setuptools import setup\n"
"setup(name='other', zip_safe=False, version='1.0', "
"scripts=['distutilsscript'],"
"py_modules=['eggrecipedemoneeded'])\n"
)
zc.buildout.testing.bdist_egg(tmp, sys.executable, dest)
write(
tmp, 'setup.py',
"from setuptools import setup\n"
"setup(name='du_zipped', zip_safe=True, version='1.0', "
"scripts=['distutilsscript'],"
"py_modules=['eggrecipedemoneeded'])\n"
)
zc.buildout.testing.bdist_egg(tmp, executable, dest)
os.remove(os.path.join(tmp, 'distutilsscript'))
os.remove(os.path.join(tmp, 'eggrecipedemoneeded.py'))
for i in (1, 2, 3, 4):
write(
tmp, 'eggrecipedemo.py',
'import eggrecipedemoneeded, sys\n'
'def print_(*a):\n'
' sys.stdout.write(" ".join(map(str, a))+"\\n")\n'
'x=%s\n'
'def main():\n'
' print_(x, eggrecipedemoneeded.y)\n'
% i)
rc1 = i==4 and 'rc1' or ''
write(
tmp, 'setup.py',
"from setuptools import setup\n"
"setup(name='demo', py_modules=['eggrecipedemo'],"
" install_requires = 'demoneeded',"
" entry_points={'console_scripts': "
"['demo = eggrecipedemo:main']},"
" zip_safe=True, version='0.%s%s')\n" % (i, rc1)
)
zc.buildout.testing.bdist_egg(tmp, dest)
write(tmp, 'mixedcase.py', 'def f():\n pass')
write(
tmp, 'setup.py',
"from setuptools import setup\n"
"setup(name='MIXEDCASE', py_modules=['mixedcase'],"
" author='bob', url='bob', author_email='bob',"
" install_requires = 'demoneeded',"
" zip_safe=True, version='0.5')\n"
)
zc.buildout.testing.sdist(tmp, dest)
# rename file to lower case
# to test issues between file and package name
curdir = os.getcwd()
os.chdir(dest)
for file in os.listdir(dest):
if "MIXEDCASE" in file:
os.rename(file, file.lower())
os.chdir(curdir)
write(tmp, 'eggrecipebigdemo.py', 'import eggrecipedemo')
write(
tmp, 'setup.py',
"from setuptools import setup\n"
"setup(name='bigdemo', "
" install_requires = 'demo',"
" py_modules=['eggrecipebigdemo'], "
" zip_safe=True, version='0.1')\n"
)
zc.buildout.testing.bdist_egg(tmp, sys.executable, dest)
finally:
shutil.rmtree(tmp)
extdemo_c2 = """
#include <Python.h>
#include <extdemo.h>
static PyMethodDef methods[] = {{NULL}};
PyMODINIT_FUNC
initextdemo(void)
{
PyObject *m;
m = Py_InitModule3("extdemo", methods, "");
#ifdef TWO
PyModule_AddObject(m, "val", PyInt_FromLong(2));
#else
PyModule_AddObject(m, "val", PyInt_FromLong(EXTDEMO));
#endif
}
"""
extdemo_c3 = """
#include <Python.h>
#include <extdemo.h>
static PyMethodDef methods[] = {{NULL}};
#define MOD_DEF(ob, name, doc, methods) \
static struct PyModuleDef moduledef = { \
PyModuleDef_HEAD_INIT, name, doc, -1, methods, }; \
ob = PyModule_Create(&moduledef);
#define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void)
MOD_INIT(extdemo)
{
PyObject *m;
MOD_DEF(m, "extdemo", "", methods);
#ifdef TWO
PyModule_AddObject(m, "val", PyLong_FromLong(2));
#else
PyModule_AddObject(m, "val", PyLong_FromLong(EXTDEMO));
#endif
return m;
}
"""
extdemo_c = sys.version_info[0] < 3 and extdemo_c2 or extdemo_c3
extdemo_setup_py = r"""
import os, sys
from distutils.core import setup, Extension
if os.environ.get('test_environment_variable'):
print(
"Have environment test_environment_variable: %%s"
%% os.environ['test_environment_variable']
)
setup(name = "extdemo", version = "%s", url="http://www.zope.org",
author="Demo", author_email="demo@demo.com",
ext_modules = [Extension('extdemo', ['extdemo.c'])],
)
"""
def add_source_dist(test, version=1.4):
if 'extdemo' not in test.globs:
test.globs['extdemo'] = test.globs['tmpdir']('extdemo')
tmp = test.globs['extdemo']
write = test.globs['write']
try:
write(tmp, 'extdemo.c', extdemo_c);
write(tmp, 'setup.py', extdemo_setup_py % version);
write(tmp, 'README', "");
write(tmp, 'MANIFEST.in', "include *.c\n");
test.globs['sdist'](tmp, test.globs['sample_eggs'])
except:
shutil.rmtree(tmp)
def easy_install_SetUp(test):
zc.buildout.testing.buildoutSetUp(test)
sample_eggs = test.globs['tmpdir']('sample_eggs')
test.globs['sample_eggs'] = sample_eggs
os.mkdir(os.path.join(sample_eggs, 'index'))
create_sample_eggs(test)
add_source_dist(test)
test.globs['link_server'] = test.globs['start_server'](
test.globs['sample_eggs'])
test.globs['update_extdemo'] = lambda : add_source_dist(test, 1.5)
zc.buildout.testing.install_develop('zc.recipe.egg', test)
normalize_bang = (
re.compile(re.escape('#!'+
zc.buildout.easy_install._safe_arg(sys.executable))),
'#!/usr/local/bin/python2.7',
)
def create_egg(name, version, dest, install_requires=None,
dependency_links=None):
d = tempfile.mkdtemp()
if dest=='available':
extras = dict(x=['x'])
else:
extras = {}
if dependency_links:
links = 'dependency_links = %s, ' % dependency_links
else:
links = ''
if install_requires:
requires = 'install_requires = %s, ' % install_requires
else:
requires = ''
try:
with open(os.path.join(d, 'setup.py'), 'w') as f:
f.write(
'from setuptools import setup\n'
'setup(name=%r, version=%r, extras_require=%r, zip_safe=True,\n'
' %s %s py_modules=["setup"]\n)'
% (name, str(version), extras, requires, links)
)
zc.buildout.testing.bdist_egg(d, sys.executable, os.path.abspath(dest))
finally:
shutil.rmtree(d)
......@@ -28,10 +28,13 @@ import re
import shutil
import sys
import tempfile
import unittest
import zc.buildout.easy_install
import zc.buildout.testing
import zipfile
from zc.buildout.tests import easy_install_SetUp
from zc.buildout.tests import normalize_bang
from zc.buildout.tests import create_egg
from zc.buildout.tests import create_sample_eggs
os_path_sep = os.path.sep
if os_path_sep == '\\':
......@@ -2325,33 +2328,6 @@ need to make it to the download cache.
"""
def create_egg(name, version, dest, install_requires=None,
dependency_links=None):
d = tempfile.mkdtemp()
if dest=='available':
extras = dict(x=['x'])
else:
extras = {}
if dependency_links:
links = 'dependency_links = %s, ' % dependency_links
else:
links = ''
if install_requires:
requires = 'install_requires = %s, ' % install_requires
else:
requires = ''
try:
with open(os.path.join(d, 'setup.py'), 'w') as f:
f.write(
'from setuptools import setup\n'
'setup(name=%r, version=%r, extras_require=%r, zip_safe=True,\n'
' %s %s py_modules=["setup"]\n)'
% (name, str(version), extras, requires, links)
)
zc.buildout.testing.bdist_egg(d, sys.executable, os.path.abspath(dest))
finally:
shutil.rmtree(d)
def prefer_final_permutation(existing, available):
for d in ('existing', 'available'):
if os.path.exists(d):
......@@ -2887,246 +2863,6 @@ def increment_buildout_with_multiple_extended_files_421022():
recipe='zc.buildout:debug'
"""
def increment_default_cfg():
r"""
>>> home = tmpdir('home')
>>> mkdir(home, '.buildout')
>>> default_cfg = join(home, '.buildout', 'default.cfg')
>>> write(default_cfg, '''
... [debug]
... dec = 1
... 2
... inc = 1
... ''')
>>> write('buildout.cfg', '''
... [buildout]
...
... [debug]
... dec -= 2
... inc += 2
... ''')
>>> env = dict(HOME=home, USERPROFILE=home)
>>> print_(system(buildout+' annotate debug', env=env), end='')
<BLANKLINE>
Annotated sections
==================
<BLANKLINE>
[debug]
dec= 1
/home/.buildout/default.cfg
-= buildout.cfg
inc= 1
2
/home/.buildout/default.cfg
+= buildout.cfg
"""
def increment_default_cfg_extensions():
r"""
Add two extensions as develop eggs
>>> mkdir('demo')
>>> write('demo', 'demo.py', '''
... import sys
... def ext(buildout):
... sys.stdout.write('demo %s %s\\n' % ('ext', sorted(buildout)))
... def unload(buildout):
... sys.stdout.write('demo %s %s\\n' % ('unload', sorted(buildout)))
... ''')
>>> write('demo', 'setup.py', '''
... from setuptools import setup
...
... setup(
... name = "demo",
... entry_points = {
... 'zc.buildout.extension': ['ext = demo:ext'],
... 'zc.buildout.unloadextension': ['ext = demo:unload'],
... },
... )
... ''')
>>> mkdir('demo2')
>>> write('demo2', 'demo2.py', '''
... import sys
... def ext(buildout):
... sys.stdout.write('demo2 %s %s\\n' % ('ext', sorted(buildout)))
... def unload(buildout):
... sys.stdout.write('demo2 %s %s\\n' % ('unload', sorted(buildout)))
... ''')
>>> write('demo2', 'setup.py', '''
... from setuptools import setup
...
... setup(
... name = "demo2",
... entry_points = {
... 'zc.buildout.extension': ['ext = demo2:ext'],
... 'zc.buildout.unloadextension': ['ext = demo2:unload'],
... },
... )
... ''')
>>> write('buildout.cfg', '''
... [buildout]
... develop = demo demo2
... parts =
... ''')
Run buildout once without extensions to actually develop the eggs.
(Develop happens after loading extensions.)
>>> print_(system(buildout), end='')
Develop: '/sample-buildout/demo'
Develop: '/sample-buildout/demo2'
>>> ls("develop-eggs")
- demo.egg-link
- demo2.egg-link
- zc.recipe.egg.egg-link
extensions in .buildout/default.cfg
incremented in buildout.cfg
>>> home = tmpdir('home')
>>> mkdir(home, '.buildout')
>>> default_cfg = join(home, '.buildout', 'default.cfg')
>>> write(default_cfg, '''
... [buildout]
... extensions = demo
... ''')
>>> write('buildout.cfg', '''
... [buildout]
... develop = demo demo2
... extensions += demo2
... parts =
... ''')
>>> env = dict(HOME=home, USERPROFILE=home)
>>> print_(system(buildout+' annotate buildout', env=env), end='')
... # doctest: +ELLIPSIS
<BLANKLINE>
Annotated sections
==================
<BLANKLINE>
[buildout]
...
extensions= demo
demo2
/home/.buildout/default.cfg
+= buildout.cfg
...
versions= versions
DEFAULT_VALUE
>>> print_(system(buildout, env=env), end='')
demo ext ['buildout', 'versions']
demo2 ext ['buildout', 'versions']
Develop: '/sample-buildout/demo'
Develop: '/sample-buildout/demo2'
demo unload ['buildout', 'versions']
demo2 unload ['buildout', 'versions']
"""
def default_cfg_extensions_with_extends_increment_in_base():
r"""
Add two extensions as develop eggs
>>> mkdir('demo')
>>> write('demo', 'demo.py', '''
... import sys
... def ext(buildout):
... sys.stdout.write('demo %s %s\\n' % ('ext', sorted(buildout)))
... def unload(buildout):
... sys.stdout.write('demo %s %s\\n' % ('unload', sorted(buildout)))
... ''')
>>> write('demo', 'setup.py', '''
... from setuptools import setup
...
... setup(
... name = "demo",
... entry_points = {
... 'zc.buildout.extension': ['ext = demo:ext'],
... 'zc.buildout.unloadextension': ['ext = demo:unload'],
... },
... )
... ''')
>>> mkdir('demo2')
>>> write('demo2', 'demo2.py', '''
... import sys
... def ext(buildout):
... sys.stdout.write('demo2 %s %s\\n' % ('ext', sorted(buildout)))
... def unload(buildout):
... sys.stdout.write('demo2 %s %s\\n' % ('unload', sorted(buildout)))
... ''')
>>> write('demo2', 'setup.py', '''
... from setuptools import setup
...
... setup(
... name = "demo2",
... entry_points = {
... 'zc.buildout.extension': ['ext = demo2:ext'],
... 'zc.buildout.unloadextension': ['ext = demo2:unload'],
... },
... )
... ''')
>>> write('buildout.cfg', '''
... [buildout]
... develop = demo demo2
... parts =
... ''')
Run buildout once without extensions to actually develop the eggs.
(Develop happens after loading extensions.)
>>> print_(system(buildout), end='')
Develop: '/sample-buildout/demo'
Develop: '/sample-buildout/demo2'
>>> ls("develop-eggs")
- demo.egg-link
- demo2.egg-link
- zc.recipe.egg.egg-link
extensions in .buildout/default.cfg
incremented in base.cfg
buildout.cfg extends base.cfg
>>> home = tmpdir('home')
>>> mkdir(home, '.buildout')
>>> default_cfg = join(home, '.buildout', 'default.cfg')
>>> write(default_cfg, '''
... [buildout]
... extensions = demo
... ''')
>>> write('base.cfg', '''
... [buildout]
... develop = demo demo2
... extensions += demo2
... ''')
>>> write('buildout.cfg', '''
... [buildout]
... extends = base.cfg
... parts =
... ''')
>>> env = dict(HOME=home, USERPROFILE=home)
>>> print_(system(buildout+' annotate buildout', env=env), end='')
... # doctest: +ELLIPSIS
<BLANKLINE>
Annotated sections
==================
<BLANKLINE>
[buildout]
...
extensions= demo
demo2
/home/.buildout/default.cfg
+= base.cfg
...
versions= versions
DEFAULT_VALUE
>>> print_(system(buildout, env=env), end='')
demo ext ['buildout', 'versions']
demo2 ext ['buildout', 'versions']
Develop: '/sample-buildout/demo'
Develop: '/sample-buildout/demo2'
demo unload ['buildout', 'versions']
demo2 unload ['buildout', 'versions']
"""
def increment_on_command_line():
r"""
......@@ -3498,204 +3234,6 @@ if sys.platform == 'win32':
######################################################################
def create_sample_eggs(test, executable=sys.executable):
assert executable == sys.executable, (executable, sys.executable)
write = test.globs['write']
dest = test.globs['sample_eggs']
tmp = tempfile.mkdtemp()
try:
write(tmp, 'README.txt', '')
for i in (0, 1, 2):
write(tmp, 'eggrecipedemoneeded.py', 'y=%s\ndef f():\n pass' % i)
rc1 = i==2 and 'rc1' or ''
write(
tmp, 'setup.py',
"from setuptools import setup\n"
"setup(name='demoneeded', py_modules=['eggrecipedemoneeded'],"
" zip_safe=True, version='1.%s%s', author='bob', url='bob', "
"author_email='bob')\n"
% (i, rc1)
)
zc.buildout.testing.sdist(tmp, dest)
write(
tmp, 'distutilsscript',
'#!/usr/bin/python\n'
'# -*- coding: utf-8 -*-\n'
'"""Module docstring."""\n'
'from __future__ import print_statement\n'
'import os\n'
'import sys; sys.stdout.write("distutils!\\n")\n'
)
write(
tmp, 'setup.py',
"from setuptools import setup\n"
"setup(name='other', zip_safe=False, version='1.0', "
"scripts=['distutilsscript'],"
"py_modules=['eggrecipedemoneeded'])\n"
)
zc.buildout.testing.bdist_egg(tmp, sys.executable, dest)
write(
tmp, 'setup.py',
"from setuptools import setup\n"
"setup(name='du_zipped', zip_safe=True, version='1.0', "
"scripts=['distutilsscript'],"
"py_modules=['eggrecipedemoneeded'])\n"
)
zc.buildout.testing.bdist_egg(tmp, executable, dest)
os.remove(os.path.join(tmp, 'distutilsscript'))
os.remove(os.path.join(tmp, 'eggrecipedemoneeded.py'))
for i in (1, 2, 3, 4):
write(
tmp, 'eggrecipedemo.py',
'import eggrecipedemoneeded, sys\n'
'def print_(*a):\n'
' sys.stdout.write(" ".join(map(str, a))+"\\n")\n'
'x=%s\n'
'def main():\n'
' print_(x, eggrecipedemoneeded.y)\n'
% i)
rc1 = i==4 and 'rc1' or ''
write(
tmp, 'setup.py',
"from setuptools import setup\n"
"setup(name='demo', py_modules=['eggrecipedemo'],"
" install_requires = 'demoneeded',"
" entry_points={'console_scripts': "
"['demo = eggrecipedemo:main']},"
" zip_safe=True, version='0.%s%s')\n" % (i, rc1)
)
zc.buildout.testing.bdist_egg(tmp, dest)
write(tmp, 'mixedcase.py', 'def f():\n pass')
write(
tmp, 'setup.py',
"from setuptools import setup\n"
"setup(name='MIXEDCASE', py_modules=['mixedcase'],"
" author='bob', url='bob', author_email='bob',"
" install_requires = 'demoneeded',"
" zip_safe=True, version='0.5')\n"
)
zc.buildout.testing.sdist(tmp, dest)
# rename file to lower case
# to test issues between file and package name
curdir = os.getcwd()
os.chdir(dest)
for file in os.listdir(dest):
if "MIXEDCASE" in file:
os.rename(file, file.lower())
os.chdir(curdir)
write(tmp, 'eggrecipebigdemo.py', 'import eggrecipedemo')
write(
tmp, 'setup.py',
"from setuptools import setup\n"
"setup(name='bigdemo', "
" install_requires = 'demo',"
" py_modules=['eggrecipebigdemo'], "
" zip_safe=True, version='0.1')\n"
)
zc.buildout.testing.bdist_egg(tmp, sys.executable, dest)
finally:
shutil.rmtree(tmp)
extdemo_c2 = """
#include <Python.h>
#include <extdemo.h>
static PyMethodDef methods[] = {{NULL}};
PyMODINIT_FUNC
initextdemo(void)
{
PyObject *m;
m = Py_InitModule3("extdemo", methods, "");
#ifdef TWO
PyModule_AddObject(m, "val", PyInt_FromLong(2));
#else
PyModule_AddObject(m, "val", PyInt_FromLong(EXTDEMO));
#endif
}
"""
extdemo_c3 = """
#include <Python.h>
#include <extdemo.h>
static PyMethodDef methods[] = {{NULL}};
#define MOD_DEF(ob, name, doc, methods) \
static struct PyModuleDef moduledef = { \
PyModuleDef_HEAD_INIT, name, doc, -1, methods, }; \
ob = PyModule_Create(&moduledef);
#define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void)
MOD_INIT(extdemo)
{
PyObject *m;
MOD_DEF(m, "extdemo", "", methods);
#ifdef TWO
PyModule_AddObject(m, "val", PyLong_FromLong(2));
#else
PyModule_AddObject(m, "val", PyLong_FromLong(EXTDEMO));
#endif
return m;
}
"""
extdemo_c = sys.version_info[0] < 3 and extdemo_c2 or extdemo_c3
extdemo_setup_py = r"""
import os, sys
from distutils.core import setup, Extension
if os.environ.get('test_environment_variable'):
print(
"Have environment test_environment_variable: %%s"
%% os.environ['test_environment_variable']
)
setup(name = "extdemo", version = "%s", url="http://www.zope.org",
author="Demo", author_email="demo@demo.com",
ext_modules = [Extension('extdemo', ['extdemo.c'])],
)
"""
def add_source_dist(test, version=1.4):
if 'extdemo' not in test.globs:
test.globs['extdemo'] = test.globs['tmpdir']('extdemo')
tmp = test.globs['extdemo']
write = test.globs['write']
try:
write(tmp, 'extdemo.c', extdemo_c);
write(tmp, 'setup.py', extdemo_setup_py % version);
write(tmp, 'README', "");
write(tmp, 'MANIFEST.in', "include *.c\n");
test.globs['sdist'](tmp, test.globs['sample_eggs'])
except:
shutil.rmtree(tmp)
def easy_install_SetUp(test):
zc.buildout.testing.buildoutSetUp(test)
sample_eggs = test.globs['tmpdir']('sample_eggs')
test.globs['sample_eggs'] = sample_eggs
os.mkdir(os.path.join(sample_eggs, 'index'))
create_sample_eggs(test)
add_source_dist(test)
test.globs['link_server'] = test.globs['start_server'](
test.globs['sample_eggs'])
test.globs['update_extdemo'] = lambda : add_source_dist(test, 1.5)
zc.buildout.testing.install_develop('zc.recipe.egg', test)
def buildout_txt_setup(test):
zc.buildout.testing.buildoutSetUp(test)
......@@ -3832,11 +3370,6 @@ def bootstrapSetup(test):
os.environ['bootstrap-testing-find-links'] = test.globs['link_server']
test.globs['bootstrap_py'] = bootstrap_py
normalize_bang = (
re.compile(re.escape('#!'+
zc.buildout.easy_install._safe_arg(sys.executable))),
'#!/usr/local/bin/python2.7',
)
normalize_S = (
re.compile(r'#!/usr/local/bin/python2.7 -S'),
......@@ -4121,7 +3654,7 @@ def test_suite():
doctest.DocFileSuite('testing_bugfix.txt'),
]
docdir = os.path.join(ancestor(__file__, 4), 'doc')
docdir = os.path.join(ancestor(__file__, 5), 'doc')
if os.path.exists(docdir) and not sys.platform.startswith('win'):
# Note that the purpose of the documentation tests are mainly
# to test the documentation, not to test buildout.
......
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2020 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import doctest
import re
from zope.testing import renormalizing
import zc.buildout.testing
from zc.buildout.tests import easy_install_SetUp
from zc.buildout.tests import normalize_bang
def increment_default_cfg():
r"""
>>> home = tmpdir('home')
>>> mkdir(home, '.buildout')
>>> default_cfg = join(home, '.buildout', 'default.cfg')
>>> write(default_cfg, '''
... [debug]
... dec = 1
... 2
... inc = 1
... ''')
>>> write('buildout.cfg', '''
... [buildout]
...
... [debug]
... dec -= 2
... inc += 2
... ''')
>>> env = dict(HOME=home, USERPROFILE=home)
>>> print_(system(buildout+' annotate debug', env=env), end='')
<BLANKLINE>
Annotated sections
==================
<BLANKLINE>
[debug]
dec= 1
/home/.buildout/default.cfg
-= buildout.cfg
inc= 1
2
/home/.buildout/default.cfg
+= buildout.cfg
"""
def increment_default_cfg_extensions():
r"""
Add two extensions as develop eggs
>>> mkdir('demo')
>>> write('demo', 'demo.py', '''
... import sys
... def ext(buildout):
... sys.stdout.write('demo %s %s\\n' % ('ext', sorted(buildout)))
... def unload(buildout):
... sys.stdout.write('demo %s %s\\n' % ('unload', sorted(buildout)))
... ''')
>>> write('demo', 'setup.py', '''
... from setuptools import setup
...
... setup(
... name = "demo",
... entry_points = {
... 'zc.buildout.extension': ['ext = demo:ext'],
... 'zc.buildout.unloadextension': ['ext = demo:unload'],
... },
... )
... ''')
>>> mkdir('demo2')
>>> write('demo2', 'demo2.py', '''
... import sys
... def ext(buildout):
... sys.stdout.write('demo2 %s %s\\n' % ('ext', sorted(buildout)))
... def unload(buildout):
... sys.stdout.write('demo2 %s %s\\n' % ('unload', sorted(buildout)))
... ''')
>>> write('demo2', 'setup.py', '''
... from setuptools import setup
...
... setup(
... name = "demo2",
... entry_points = {
... 'zc.buildout.extension': ['ext = demo2:ext'],
... 'zc.buildout.unloadextension': ['ext = demo2:unload'],
... },
... )
... ''')
>>> write('buildout.cfg', '''
... [buildout]
... develop = demo demo2
... parts =
... ''')
Run buildout once without extensions to actually develop the eggs.
(Develop happens after loading extensions.)
>>> print_(system(buildout), end='')
Develop: '/sample-buildout/demo'
Develop: '/sample-buildout/demo2'
>>> ls("develop-eggs")
- demo.egg-link
- demo2.egg-link
- zc.recipe.egg.egg-link
extensions in .buildout/default.cfg
incremented in buildout.cfg
>>> home = tmpdir('home')
>>> mkdir(home, '.buildout')
>>> default_cfg = join(home, '.buildout', 'default.cfg')
>>> write(default_cfg, '''
... [buildout]
... extensions = demo
... ''')
>>> write('buildout.cfg', '''
... [buildout]
... develop = demo demo2
... extensions += demo2
... parts =
... ''')
>>> env = dict(HOME=home, USERPROFILE=home)
>>> print_(system(buildout+' annotate buildout', env=env), end='')
... # doctest: +ELLIPSIS
<BLANKLINE>
Annotated sections
==================
<BLANKLINE>
[buildout]
...
extensions= demo
demo2
/home/.buildout/default.cfg
+= buildout.cfg
...
versions= versions
DEFAULT_VALUE
>>> print_(system(buildout, env=env), end='')
demo ext ['buildout', 'versions']
demo2 ext ['buildout', 'versions']
Develop: '/sample-buildout/demo'
Develop: '/sample-buildout/demo2'
demo unload ['buildout', 'versions']
demo2 unload ['buildout', 'versions']
"""
def default_cfg_extensions_with_extends_increment_in_base():
r"""
Add two extensions as develop eggs
>>> mkdir('demo')
>>> write('demo', 'demo.py', '''
... import sys
... def ext(buildout):
... sys.stdout.write('demo %s %s\\n' % ('ext', sorted(buildout)))
... def unload(buildout):
... sys.stdout.write('demo %s %s\\n' % ('unload', sorted(buildout)))
... ''')
>>> write('demo', 'setup.py', '''
... from setuptools import setup
...
... setup(
... name = "demo",
... entry_points = {
... 'zc.buildout.extension': ['ext = demo:ext'],
... 'zc.buildout.unloadextension': ['ext = demo:unload'],
... },
... )
... ''')
>>> mkdir('demo2')
>>> write('demo2', 'demo2.py', '''
... import sys
... def ext(buildout):
... sys.stdout.write('demo2 %s %s\\n' % ('ext', sorted(buildout)))
... def unload(buildout):
... sys.stdout.write('demo2 %s %s\\n' % ('unload', sorted(buildout)))
... ''')
>>> write('demo2', 'setup.py', '''
... from setuptools import setup
...
... setup(
... name = "demo2",
... entry_points = {
... 'zc.buildout.extension': ['ext = demo2:ext'],
... 'zc.buildout.unloadextension': ['ext = demo2:unload'],
... },
... )
... ''')
>>> write('buildout.cfg', '''
... [buildout]
... develop = demo demo2
... parts =
... ''')
Run buildout once without extensions to actually develop the eggs.
(Develop happens after loading extensions.)
>>> print_(system(buildout), end='')
Develop: '/sample-buildout/demo'
Develop: '/sample-buildout/demo2'
>>> ls("develop-eggs")
- demo.egg-link
- demo2.egg-link
- zc.recipe.egg.egg-link
extensions in .buildout/default.cfg
incremented in base.cfg
buildout.cfg extends base.cfg
>>> home = tmpdir('home')
>>> mkdir(home, '.buildout')
>>> default_cfg = join(home, '.buildout', 'default.cfg')
>>> write(default_cfg, '''
... [buildout]
... extensions = demo
... ''')
>>> write('base.cfg', '''
... [buildout]
... develop = demo demo2
... extensions += demo2
... ''')
>>> write('buildout.cfg', '''
... [buildout]
... extends = base.cfg
... parts =
... ''')
>>> env = dict(HOME=home, USERPROFILE=home)
>>> print_(system(buildout+' annotate buildout', env=env), end='')
... # doctest: +ELLIPSIS
<BLANKLINE>
Annotated sections
==================
<BLANKLINE>
[buildout]
...
extensions= demo
demo2
/home/.buildout/default.cfg
+= base.cfg
...
versions= versions
DEFAULT_VALUE
>>> print_(system(buildout, env=env), end='')
demo ext ['buildout', 'versions']
demo2 ext ['buildout', 'versions']
Develop: '/sample-buildout/demo'
Develop: '/sample-buildout/demo2'
demo unload ['buildout', 'versions']
demo2 unload ['buildout', 'versions']
"""
def test_suite():
return doctest.DocTestSuite(
setUp=easy_install_SetUp,
tearDown=zc.buildout.testing.buildoutTearDown,
checker=renormalizing.RENormalizing([
zc.buildout.testing.normalize_path,
zc.buildout.testing.normalize_endings,
zc.buildout.testing.normalize_script,
zc.buildout.testing.normalize_egg_py,
zc.buildout.testing.normalize___pycache__,
zc.buildout.testing.not_found,
zc.buildout.testing.normalize_exception_type_for_python_2_and_3,
zc.buildout.testing.adding_find_link,
zc.buildout.testing.python27_warning,
zc.buildout.testing.python27_warning_2,
normalize_bang,
(re.compile(r'^(\w+\.)*(Missing\w+: )'), '\2'),
(re.compile(r"buildout: Running \S*setup.py"),
'buildout: Running setup.py'),
(re.compile(r'pip-\S+-'),
'pip.egg'),
(re.compile(r'setuptools-\S+-'),
'setuptools.egg'),
(re.compile(r'zc.buildout-\S+-'),
'zc.buildout.egg'),
(re.compile(r'pip = \S+'), 'pip = 20.0.0'),
(re.compile(r'setuptools = \S+'), 'setuptools = 0.7.99'),
(re.compile(r'File "\S+one.py"'),
'File "one.py"'),
(re.compile(r'We have a develop egg: (\S+) (\S+)'),
r'We have a develop egg: \1 V'),
(re.compile(r'Picked: setuptools = \S+'),
'Picked: setuptools = V'),
(re.compile('[-d] pip'), '- pip'),
(re.compile('[-d] setuptools'), '- setuptools'),
(re.compile(r'\\[\\]?'), '/'),
(re.compile(
'-q develop -mxN -d "/sample-buildout/develop-eggs'),
'-q develop -mxN -d /sample-buildout/develop-eggs'
),
(re.compile(r'^[*]...'), '...'),
# for
# bug_92891
# bootstrap_crashes_with_egg_recipe_in_buildout_section
(re.compile(r"Unused options for buildout: 'eggs' 'scripts'\."),
"Unused options for buildout: 'scripts' 'eggs'."),
# Python 3.4 changed the wording of NameErrors
(re.compile('NameError: global name'), 'NameError: name'),
# fix for test_distutils_scripts_using_import_are_properly_parsed
# and test_distutils_scripts_using_from_are_properly_parsed
# win32 apparently adds a " around sys.executable
(re.compile('#!"python"'), '#!python'),
]),
)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment