• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zopefoundation / zc.zope3recipes / 5499723136

pending completion
5499723136

push

github

icemac
Fix tests for current setuptools version.

148 of 264 branches covered (56.06%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

371 of 707 relevant lines covered (52.48%)

0.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.87
/src/zc/zope3recipes/tests.py
1
##############################################################################
2
#
3
# Copyright (c) 2006 Zope Corporation and Contributors.
4
# All Rights Reserved.
5
#
6
# This software is subject to the provisions of the Zope Public License,
7
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
8
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11
# FOR A PARTICULAR PURPOSE.
12
#
13
##############################################################################
14

15

16
import doctest
1✔
17
import os
1✔
18
import re
1✔
19
import sys
1✔
20
import textwrap
1✔
21
import unittest
1✔
22

23
import zc.buildout.testing
1✔
24
from zope.testing import renormalizing
1✔
25

26

27
def ls_optional(dir, ignore=(), *subs):
1✔
28
    if subs:
1!
29
        dir = os.path.join(dir, *subs)
×
30
    names = os.listdir(dir)
1✔
31
    names.sort()
1✔
32
    for name in names:
1✔
33
        if name in ignore:
1!
34
            continue
×
35
        if os.path.isdir(os.path.join(dir, name)):
1!
36
            print('d ', end='')
1✔
37
        elif os.path.islink(os.path.join(dir, name)):
×
38
            print('l ', end='')
×
39
        else:
40
            print('- ', end='')
×
41
        print(name)
1✔
42

43

44
def test_ctl():
1✔
45
    """
46
The ctl script is an extended version of zdaemon that provides an
47
extra command, run.  Let's create a buildout that installs it as an
48
ordinary script:
49

50
    >>> write('buildout.cfg',
51
    ... '''
52
    ... [buildout]
53
    ... parts = ctl
54
    ...
55
    ... [ctl]
56
    ... recipe = zc.recipe.egg
57
    ... eggs = zc.zope3recipes
58
    ...        zdaemon
59
    ... entry-points = ctl=zc.zope3recipes.ctl:main
60
    ... scripts = ctl
61
    ... ''')
62

63
    >>> print(system(join('bin', 'buildout')), end='')
64
    Installing ctl...
65
    Generated script '/sample-buildout/bin/ctl'.
66

67
We'll create a configuration file:
68

69
    >>> write('conf',
70
    ... '''
71
    ... <runner>
72
    ...   program echo hi
73
    ... </runner>
74
    ... ''')
75

76
The configuration doesn't matter much. :)
77

78
Unlike a normal zdaemon script, we have to pass two extra arguments, a
79
script to run the zope debugger with, and the name of a zope
80
configuration file. For demonstration purposes, we'll just use echo.
81

82
    >>> print(system(join('bin', 'ctl')+' echo zope.conf -Cconf fg there'), end='')
83
    echo hi there
84
    hi there
85

86
Notice:
87

88
  - The first 2 arguments were ignored.
89

90
  - It got the program, 'echo hi', from the configuration file.
91

92
  - We ran the program in the foreground, passing the extra argument, there.
93

94
Now, if we use the run command, it will run the script we passed as
95
the first argument:
96

97
    >>> print(system(join('bin', 'ctl')+' echo zope.conf -Cconf run there'), end='')
98
    -C zope.conf there
99

100
debug is another name for run:
101

102
    >>> print(system(join('bin', 'ctl')+' echo zope.conf -Cconf debug there'), end='')
103
    -C zope.conf there
104

105
"""  # noqa: E501 line too long
106

107

108
def test_sane_errors_from_recipe():
1✔
109
    """
110
There was a bug in the recipe error handling that caused errors to be hidden
111

112
    >>> write('buildout.cfg',
113
    ... '''
114
    ... [buildout]
115
    ... parts = instance
116
    ...
117
    ... [myapp]
118
    ... location = foo
119
    ... ;; Note that 'servers' has a default value when the
120
    ... ;; application recipe is involved.
121
    ... servers = twisted
122
    ...
123
    ... [instance]
124
    ... recipe = zc.zope3recipes:instance
125
    ... application = myapp
126
    ... zope.conf =
127
    ... ''')
128

129
    >>> print(system(join('bin', 'buildout')), end='')
130
    Couldn't find index page for 'zc.recipe.egg' (maybe misspelled?)
131
    Installing instance.
132
    While:
133
      Installing instance.
134
    Error: No database sections have been defined.
135
    """
136

137

138
def work_with_old_zc_deployment():
1✔
139
    """
140

141
    >>> mkdir('demo1')
142
    >>> write('demo1', 'setup.py',
143
    ... '''
144
    ... from setuptools import setup
145
    ... setup(name = 'demo1')
146
    ... ''')
147

148
    >>> mkdir('demo2')
149
    >>> write('demo2', 'setup.py',
150
    ... '''
151
    ... from setuptools import setup
152
    ... setup(name = 'demo2', install_requires='demo1')
153
    ... ''')
154

155
    >>> root = tmpdir('root')
156
    >>> mkdir(root, 'etc')
157
    >>> mkdir(root, 'etc', 'myapp-run')
158
    >>> mkdir(root, 'etc', 'init.d')
159
    >>> mkdir(root, 'etc', 'logrotate.d')
160

161
    >>> write('buildout.cfg',
162
    ... '''
163
    ... [buildout]
164
    ... develop = demo1 demo2
165
    ... parts = instance
166
    ...
167
    ... [myapp]
168
    ... recipe = zc.zope3recipes:application
169
    ... site.zcml = <include package="demo2" />
170
    ...             <principal
171
    ...                 id="zope.manager"
172
    ...                 title="Manager"
173
    ...                 login="jim"
174
    ...                 password_manager="SHA1"
175
    ...                 password="40bd001563085fc35165329ea1ff5c5ecbdbbeef"
176
    ...                 />
177
    ...             <grant
178
    ...                 role="zope.Manager"
179
    ...                 principal="zope.manager"
180
    ...                 />
181
    ... eggs = demo2
182
    ...
183
    ... [instance]
184
    ... recipe = zc.zope3recipes:instance
185
    ... application = myapp
186
    ... zope.conf = ${database:zconfig}
187
    ... address = 8081
188
    ... deployment = myapp-run
189
    ...
190
    ... [database]
191
    ... recipe = zc.recipe.filestorage
192
    ...
193
    ... [myapp-run]
194
    ... etc-directory = %(root)s/etc/myapp-run
195
    ... rc-directory = %(root)s/etc/init.d
196
    ... logrotate-directory = %(root)s/etc/logrotate.d
197
    ... log-directory = %(root)s/var/log/myapp-run
198
    ... run-directory = %(root)s/var/run/myapp-run
199
    ... user = zope
200
    ... ''' % globals())
201

202
    >>> print(system(join('bin', 'buildout')), end='')
203
    Develop: '/sample-buildout/demo1'
204
    Develop: '/sample-buildout/demo2'
205
    Installing database.
206
    Installing myapp.
207
    Generated script '/sample-buildout/parts/myapp/runzope'.
208
    Generated script '/sample-buildout/parts/myapp/debugzope'.
209
    Installing instance.
210
    Generated script '/root/etc/init.d/myapp-run-instance'.
211

212
    """
213

214

215
def setUp(test):
1✔
216
    zc.buildout.testing.buildoutSetUp(test)
1✔
217
    zc.buildout.testing.install_develop('zc.zope3recipes', test)
1✔
218
    zc.buildout.testing.install('zope.exceptions', test)
1✔
219
    zc.buildout.testing.install('zope.interface', test)
1✔
220
    zc.buildout.testing.install('PasteScript', test)
1✔
221
    zc.buildout.testing.install('PasteDeploy', test)
1✔
222
    zc.buildout.testing.install('Paste', test)
1✔
223
    zc.buildout.testing.install('zope.testing', test)
1✔
224
    zc.buildout.testing.install('zc.recipe.egg', test)
1✔
225
    zc.buildout.testing.install('zdaemon', test)
1✔
226
    zc.buildout.testing.install('ZConfig', test)
1✔
227
    zc.buildout.testing.install('zc.recipe.filestorage', test)
1✔
228
    # prevent upgrade during test
229
    conf_dir = os.path.join(os.path.expanduser('~'), '.buildout')
1✔
230
    conf_file = os.path.join(conf_dir, 'default.cfg')
1✔
231
    if not os.path.exists(conf_dir):
1!
232
        os.makedirs(conf_dir)
1✔
233
    if not os.path.exists(conf_file):
1!
234
        with open(conf_file, 'w') as fp:
1✔
235
            fp.write(
1✔
236
                "[buildout]\n"
237
                "newest = false\n"
238
            )
239
    else:
240
        raise RuntimeWarning('Unable to set "newest=false" for tests')
×
241

242

243
checker = renormalizing.RENormalizing([
1✔
244
    zc.buildout.testing.normalize_path,
245
    (re.compile(
246
        r"Couldn't find index page for '[a-zA-Z0-9.]+' "
247
        r"\(maybe misspelled\?\)"
248
        r"\n"
249
    ), ''),
250
    # Windows
251
    (re.compile(r'\r\n'), '\n'),
252
    # this directory
253
    (re.compile(r"""['"][^\n"']+zc.zope3recipes['"],"""),
254
     "'/zc.zope3recipes',"),
255
    # welp, when we do things like `tox -e coverage`, everything's in
256
    # .tox/coverage/lib/pythonX.Y/site-packages and that's what gets added to
257
    # sys.path in the generated scripts
258
    (re.compile("""['"][^\n"']+site-packages['"],"""),
259
     "'/site-packages',"),
260
    (re.compile('#![^\n]+\n'), ''),
261
    (re.compile(r'-[^-]+-py\d[.]\d(-\S+)?.egg'),
262
     '-pyN.N.egg'),
263
    # Turn "distribute" into "setuptools" so the tests can pass with either:
264
    (re.compile(r'\bdistribute-pyN\.N\.egg'),
265
     'setuptools-pyN.N.egg'),
266
    # Running the tests under coverage changes the output ordering!  This makes
267
    # no sense!
268
    (re.compile(
269
        r"( *'/zope3recipes',\n)( *'/sample-buildout/demo1',\n)"
270
    ), r'\2\1'),
271
    # Running the tests with buildout + bin/test adds ZConfig and zdaemon
272
    # eggs to sys.path of generated tests.  Running the tests with tox does
273
    # not (because ZConfig and zdaemon are already in .../site-packages)
274
    (re.compile(
275
        r" *'/sample-buildout/eggs/(ZConfig|zdaemon)-pyN.N.egg',\n"
276
    ), ''),
277
    (re.compile(
278
        r" *join\(base, 'eggs/(ZConfig|zdaemon)-pyN.N.egg'\),\n"
279
    ), ''),
280
    (re.compile(
281
        r"( *'/sample-buildout/eggs/(PasteScript|"
282
        r"PasteDeploy|Paste)-pyN.N.egg',\n)+"
283
    ), "  '/site-packages',\n"),
284
    # tox -e coverage does this!  I've no idea why!
285
    (re.compile(
286
        r"Uninstalling myapp.\n"
287
        r"(Updating database.\n|Installing database.\n"
288
        r"|Uninstalling database.\n|)"
289
        r"Installing myapp.\n"
290
        r"(Generated script '/sample-buildout/parts/myapp/[^']+'\.\n)*",
291
    ), "\\1Updating myapp.\n"),
292
    (re.compile(
293
        r"Uninstalling instance.\n"
294
        r"(Updating myapp.\n|)"
295
        r"Installing instance.\n"
296
        r"(Generated script '/sample-buildout/bin/[^']+'\.\n)*",
297
    ), "\\1Updating instance.\n"),
298
    # Ignore Setuptools deprecation warnings for now:
299
    (re.compile(r'.*EasyInstallDeprecationWarning.*\n'), ''),
300
    (re.compile(r'.*SetuptoolsDeprecationWarning.*\n'), ''),
301
    # Ignore warnings for Python <= 3.10:
302
    (re.compile(r'.*warnings.warn\(\n'), ''),
303
    # Ignore Setuptools warnings:
304
    (re.compile(textwrap.dedent(r'''
305
        !!
306

307
                \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
308
                Please avoid running ``setup.py`` and ``easy_install``.
309
                Instead, use pypa/build, pypa/installer, pypa/build or
310
                other standards-based tools.
311

312
                See https://github.com/pypa/setuptools/issues/917 for details.
313
                \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
314

315
        !!
316
          easy_install.initialize_options\(self\)\(?\)?'''), re.M), ''),  # noqa: E501 line too long
317
    (re.compile(textwrap.dedent(r'''
318
        !!
319

320
                \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
321
                Please avoid running ``setup.py`` directly.
322
                Instead, use pypa/build, pypa/installer, pypa/build or
323
                other standards-based tools.
324

325
                See https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html for details.
326
                \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
327

328
        !!
329
          self.initialize_options\(\)\(?\)?'''), re.M), ''),  # noqa: E501 line too long
330

331
])
332

333

334
def test_suite():
1✔
335
    suite = unittest.TestSuite()
1✔
336
    optionflags = (
1✔
337
        doctest.NORMALIZE_WHITESPACE
338
        | doctest.ELLIPSIS
339
        | doctest.REPORT_NDIFF
340
    )
341
    if sys.platform[:3].lower() == "win":
1!
342
        suite.addTest(
×
343
            doctest.DocFileSuite(
344
                'WINDOWS.rst',
345
                setUp=setUp,
346
                tearDown=zc.buildout.testing.buildoutTearDown,
347
                checker=checker,
348
                optionflags=optionflags,
349
            )
350
        )
351
    else:
352
        suite.addTest(
1✔
353
            doctest.DocTestSuite(
354
                setUp=setUp,
355
                tearDown=zc.buildout.testing.buildoutTearDown,
356
                checker=checker,
357
                optionflags=optionflags,
358
            )
359
        )
360
        suite.addTest(
1✔
361
            doctest.DocFileSuite(
362
                'README.rst',
363
                setUp=setUp,
364
                tearDown=zc.buildout.testing.buildoutTearDown,
365
                checker=checker,
366
                optionflags=optionflags,
367
            )
368
        )
369

370
    return suite
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2024 Coveralls, Inc