aboutsummaryrefslogtreecommitdiffstats
path: root/lib/python2.7/site-packages/buildbot-0.8.8-py2.7.egg/buildbot/test/unit/test_steps_python.py
blob: 4bc31cbc78712fa8c61985ad94d45f66dd3cae5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
# This file is part of Buildbot.  Buildbot is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Buildbot Team Members

from buildbot.status.results import FAILURE, SUCCESS, WARNINGS
from buildbot.steps import python
from buildbot.test.fake.remotecommand import ExpectShell
from buildbot.test.util import steps
from twisted.trial import unittest
from buildbot import config

log_output_success = '''\
Making output directory...
Running Sphinx v1.0.7
loading pickled environment... not yet created
No builder selected, using default: html
building [html]: targets for 24 source files that are out of date
updating environment: 24 added, 0 changed, 0 removed
reading sources... [  4%] index
reading sources... [  8%] manual/cfg-builders
...
copying static files... done
dumping search index... done
dumping object inventory... done
build succeeded.
'''

log_output_nochange = '''\
Running Sphinx v1.0.7
loading pickled environment... done
No builder selected, using default: html
building [html]: targets for 0 source files that are out of date
updating environment: 0 added, 0 changed, 0 removed
looking for now-outdated files... none found
no targets are out of date.
'''

log_output_warnings = '''\
Running Sphinx v1.0.7
loading pickled environment... done
building [html]: targets for 1 source files that are out of date
updating environment: 0 added, 1 changed, 0 removed
reading sources... [100%] file

file.rst:18: (WARNING/2) Literal block expected; none found.

looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [ 50%] index
writing output... [100%] file

index.rst:: WARNING: toctree contains reference to document 'preamble' that \
doesn't have a title: no link will be generated
writing additional files... search
copying static files... done
dumping search index... done
dumping object inventory... done
build succeeded, 2 warnings.'''

warnings = '''\
file.rst:18: (WARNING/2) Literal block expected; none found.
index.rst:: WARNING: toctree contains reference to document 'preamble' that \
doesn't have a title: no link will be generated\
'''


class PyLint(steps.BuildStepMixin, unittest.TestCase):

    def setUp(self):
        return self.setUpBuildStep()

    def tearDown(self):
        return self.tearDownBuildStep()

    def test_success(self):
        self.setupStep(python.PyLint(command=['pylint']))
        self.expectCommands(
            ExpectShell(workdir='wkdir', command=['pylint'],
                        usePTY='slave-config')
            + ExpectShell.log('stdio',
                              stdout='Your code has been rated at 10/10')
            + python.PyLint.RC_OK)
        self.expectOutcome(result=SUCCESS, status_text=['pylint'])
        return self.runStep()

    def test_error(self):
        self.setupStep(python.PyLint(command=['pylint']))
        self.expectCommands(
            ExpectShell(workdir='wkdir', command=['pylint'],
                        usePTY='slave-config')
            + ExpectShell.log(
                'stdio',
                stdout=('W: 11: Bad indentation. Found 6 spaces, expected 4\n'
                        'E: 12: Undefined variable \'foo\'\n'))
            + (python.PyLint.RC_WARNING|python.PyLint.RC_ERROR))
        self.expectOutcome(result=FAILURE,
                           status_text=['pylint', 'error=1', 'warning=1',
                                        'failed'])
        self.expectProperty('pylint-warning', 1)
        self.expectProperty('pylint-error', 1)
        return self.runStep()

    def test_failure(self):
        self.setupStep(python.PyLint(command=['pylint']))
        self.expectCommands(
            ExpectShell(workdir='wkdir', command=['pylint'],
                        usePTY='slave-config')
            + ExpectShell.log(
                'stdio',
                stdout=('W: 11: Bad indentation. Found 6 spaces, expected 4\n'
                        'F: 13: something really strange happened\n'))
            + (python.PyLint.RC_WARNING|python.PyLint.RC_FATAL))
        self.expectOutcome(result=FAILURE,
                           status_text=['pylint', 'fatal=1', 'warning=1',
                                        'failed'])
        self.expectProperty('pylint-warning', 1)
        self.expectProperty('pylint-fatal', 1)
        return self.runStep()

    def test_failure_zero_returncode(self):
        # Make sure that errors result in a failed step when pylint's
        # return code is 0, e.g. when run through a wrapper script.
        self.setupStep(python.PyLint(command=['pylint']))
        self.expectCommands(
            ExpectShell(workdir='wkdir', command=['pylint'],
                        usePTY='slave-config')
            + ExpectShell.log(
                'stdio',
                stdout=('W: 11: Bad indentation. Found 6 spaces, expected 4\n'
                        'E: 12: Undefined variable \'foo\'\n'))
            + 0)
        self.expectOutcome(result=FAILURE,
                           status_text=['pylint', 'error=1', 'warning=1',
                                        'failed'])
        self.expectProperty('pylint-warning', 1)
        self.expectProperty('pylint-error', 1)
        return self.runStep()

    def test_regex_text(self):
        self.setupStep(python.PyLint(command=['pylint']))
        self.expectCommands(
            ExpectShell(workdir='wkdir', command=['pylint'],
                        usePTY='slave-config')
            + ExpectShell.log(
                'stdio',
                stdout=('W: 11: Bad indentation. Found 6 spaces, expected 4\n'
                        'C:  1:foo123: Missing docstring\n'))
            + (python.PyLint.RC_WARNING|python.PyLint.RC_CONVENTION))
        self.expectOutcome(result=WARNINGS,
                           status_text=['pylint', 'convention=1', 'warning=1',
                                        'warnings'])
        self.expectProperty('pylint-warning', 1)
        self.expectProperty('pylint-convention', 1)
        self.expectProperty('pylint-total', 2)
        return self.runStep()

    def test_regex_text_0_24(self):
        # pylint >= 0.24.0 prints out column offsets when using text format
        self.setupStep(python.PyLint(command=['pylint']))
        self.expectCommands(
            ExpectShell(workdir='wkdir', command=['pylint'],
                        usePTY='slave-config')
            + ExpectShell.log(
                'stdio',
                stdout=('W: 11,0: Bad indentation. Found 6 spaces, expected 4\n'
                        'C:  3,10:foo123: Missing docstring\n'))
            + (python.PyLint.RC_WARNING|python.PyLint.RC_CONVENTION))
        self.expectOutcome(result=WARNINGS,
                           status_text=['pylint', 'convention=1', 'warning=1',
                                        'warnings'])
        self.expectProperty('pylint-warning', 1)
        self.expectProperty('pylint-convention', 1)
        self.expectProperty('pylint-total', 2)
        return self.runStep()

    def test_regex_text_ids(self):
        self.setupStep(python.PyLint(command=['pylint']))
        self.expectCommands(
            ExpectShell(workdir='wkdir', command=['pylint'],
                        usePTY='slave-config')
            + ExpectShell.log(
                'stdio',
                stdout=('W0311: 11: Bad indentation.\n'
                        'C0111:  1:funcName: Missing docstring\n'))
            + (python.PyLint.RC_WARNING|python.PyLint.RC_CONVENTION))
        self.expectOutcome(result=WARNINGS,
                           status_text=['pylint', 'convention=1', 'warning=1',
                                        'warnings'])
        self.expectProperty('pylint-warning', 1)
        self.expectProperty('pylint-convention', 1)
        self.expectProperty('pylint-total', 2)
        return self.runStep()

    def test_regex_text_ids_0_24(self):
        # pylint >= 0.24.0 prints out column offsets when using text format
        self.setupStep(python.PyLint(command=['pylint']))
        self.expectCommands(
            ExpectShell(workdir='wkdir', command=['pylint'],
                        usePTY='slave-config')
            + ExpectShell.log(
                'stdio',
                stdout=('W0311: 11,0: Bad indentation.\n'
                        'C0111:  3,10:foo123: Missing docstring\n'))
            + (python.PyLint.RC_WARNING|python.PyLint.RC_CONVENTION))
        self.expectOutcome(result=WARNINGS,
                           status_text=['pylint', 'convention=1', 'warning=1',
                                        'warnings'])
        self.expectProperty('pylint-warning', 1)
        self.expectProperty('pylint-convention', 1)
        self.expectProperty('pylint-total', 2)
        return self.runStep()

    def test_regex_parseable_ids(self):
        self.setupStep(python.PyLint(command=['pylint']))
        self.expectCommands(
            ExpectShell(workdir='wkdir', command=['pylint'],
                        usePTY='slave-config')
            + ExpectShell.log(
                'stdio',
                stdout=('test.py:9: [W0311] Bad indentation.\n'
                        'test.py:3: [C0111, foo123] Missing docstring\n'))
            + (python.PyLint.RC_WARNING|python.PyLint.RC_CONVENTION))
        self.expectOutcome(result=WARNINGS,
                           status_text=['pylint', 'convention=1', 'warning=1',
                                        'warnings'])
        self.expectProperty('pylint-warning', 1)
        self.expectProperty('pylint-convention', 1)
        self.expectProperty('pylint-total', 2)
        return self.runStep()

    def test_regex_parseable(self):
        self.setupStep(python.PyLint(command=['pylint']))
        self.expectCommands(
            ExpectShell(workdir='wkdir', command=['pylint'],
                        usePTY='slave-config')
            + ExpectShell.log(
                'stdio',
                stdout=('test.py:9: [W] Bad indentation.\n'
                        'test.py:3: [C, foo123] Missing docstring\n'))
            + (python.PyLint.RC_WARNING|python.PyLint.RC_CONVENTION))
        self.expectOutcome(result=WARNINGS,
                           status_text=['pylint', 'convention=1', 'warning=1',
                                        'warnings'])
        self.expectProperty('pylint-warning', 1)
        self.expectProperty('pylint-convention', 1)
        self.expectProperty('pylint-total', 2)
        return self.runStep()

class PyFlakes(steps.BuildStepMixin, unittest.TestCase):

    def setUp(self):
        return self.setUpBuildStep()

    def tearDown(self):
        return self.tearDownBuildStep()

    def test_success(self):
        self.setupStep(python.PyFlakes())
        self.expectCommands(
            ExpectShell(workdir='wkdir', command=['make', 'pyflakes'],
                        usePTY='slave-config')
            + 0)
        self.expectOutcome(result=SUCCESS, status_text=['pyflakes'])
        return self.runStep()

    def test_unused(self):
        self.setupStep(python.PyFlakes())
        self.expectCommands(
            ExpectShell(workdir='wkdir', command=['make', 'pyflakes'],
                        usePTY='slave-config')
            + ExpectShell.log(
                'stdio',
                stdout="foo.py:1: 'bar' imported but unused\n")
            + 1)
        self.expectOutcome(result=WARNINGS,
                           status_text=['pyflakes', 'unused=1', 'warnings'])
        self.expectProperty('pyflakes-unused', 1)
        self.expectProperty('pyflakes-total', 1)
        return self.runStep()

    def test_undefined(self):
        self.setupStep(python.PyFlakes())
        self.expectCommands(
            ExpectShell(workdir='wkdir', command=['make', 'pyflakes'],
                        usePTY='slave-config')
            + ExpectShell.log(
                'stdio',
                stdout="foo.py:1: undefined name 'bar'\n")
            + 1)
        self.expectOutcome(result=FAILURE,
                           status_text=['pyflakes', 'undefined=1', 'failed'])
        self.expectProperty('pyflakes-undefined', 1)
        self.expectProperty('pyflakes-total', 1)
        return self.runStep()

    def test_redefs(self):
        self.setupStep(python.PyFlakes())
        self.expectCommands(
            ExpectShell(workdir='wkdir', command=['make', 'pyflakes'],
                        usePTY='slave-config')
            + ExpectShell.log(
                'stdio',
                stdout="foo.py:2: redefinition of unused 'foo' from line 1\n")
            + 1)
        self.expectOutcome(result=WARNINGS,
                           status_text=['pyflakes', 'redefs=1', 'warnings'])
        self.expectProperty('pyflakes-redefs', 1)
        self.expectProperty('pyflakes-total', 1)
        return self.runStep()

    def test_importstar(self):
        self.setupStep(python.PyFlakes())
        self.expectCommands(
            ExpectShell(workdir='wkdir', command=['make', 'pyflakes'],
                        usePTY='slave-config')
            + ExpectShell.log(
                'stdio',
                stdout="foo.py:1: 'from module import *' used; unable to detect undefined names\n")
            + 1)
        self.expectOutcome(result=WARNINGS,
                           status_text=['pyflakes', 'import*=1', 'warnings'])
        self.expectProperty('pyflakes-import*', 1)
        self.expectProperty('pyflakes-total', 1)
        return self.runStep()

    def test_misc(self):
        self.setupStep(python.PyFlakes())
        self.expectCommands(
            ExpectShell(workdir='wkdir', command=['make', 'pyflakes'],
                        usePTY='slave-config')
            + ExpectShell.log(
                'stdio',
                stdout="foo.py:2: redefinition of function 'bar' from line 1\n")
            + 1)
        self.expectOutcome(result=WARNINGS,
                           status_text=['pyflakes', 'misc=1', 'warnings'])
        self.expectProperty('pyflakes-misc', 1)
        self.expectProperty('pyflakes-total', 1)
        return self.runStep()


class TestSphinx(steps.BuildStepMixin, unittest.TestCase):

    def setUp(self):
        return self.setUpBuildStep()

    def tearDown(self):
        return self.tearDownBuildStep()

    def test_builddir_required(self):
        self.assertRaises(config.ConfigErrors, lambda :
                python.Sphinx())

    def test_bad_mode(self):
        self.assertRaises(config.ConfigErrors, lambda: python.Sphinx(
                sphinx_builddir="_build", mode="don't care"))

    def test_success(self):
        self.setupStep(python.Sphinx(sphinx_builddir="_build"))
        self.expectCommands(
            ExpectShell(workdir='wkdir', usePTY='slave-config',
                        command=['sphinx-build', '.', '_build'])
            + ExpectShell.log('stdio',
                stdout=log_output_success)
            + 0
        )
        self.expectOutcome(result=SUCCESS, status_text=["sphinx", "0 warnings"])
        return self.runStep()

    def test_failure(self):
        self.setupStep(python.Sphinx(sphinx_builddir="_build"))
        self.expectCommands(
            ExpectShell(workdir='wkdir', usePTY='slave-config',
                        command=['sphinx-build', '.', '_build'])
            + ExpectShell.log('stdio',
                stdout='oh noes!')
            + 1
        )
        self.expectOutcome(result=FAILURE, status_text=["sphinx", "0 warnings", "failed"])
        return self.runStep()

    def test_nochange(self):
        self.setupStep(python.Sphinx(sphinx_builddir="_build"))
        self.expectCommands(
            ExpectShell(workdir='wkdir', usePTY='slave-config',
                        command=['sphinx-build', '.', '_build'])
            + ExpectShell.log('stdio',
                stdout=log_output_nochange)
            + 0
        )
        self.expectOutcome(result=SUCCESS,
                status_text=["sphinx", "0 warnings"])
        return self.runStep()

    def test_warnings(self):
        self.setupStep(python.Sphinx(sphinx_builddir="_build"))
        self.expectCommands(
            ExpectShell(workdir='wkdir', usePTY='slave-config',
                        command=['sphinx-build', '.', '_build'])
            + ExpectShell.log('stdio',
                stdout=log_output_warnings)
            + 0
        )
        self.expectOutcome(result=WARNINGS,
                status_text=["sphinx", "2 warnings", "warnings"])
        self.expectLogfile("warnings", warnings)
        d = self.runStep()
        def check(_):
            self.assertEqual(self.step_statistics, { 'warnings' : 2 })
        d.addCallback(check)
        return d

    def test_constr_args(self):
        self.setupStep(python.Sphinx(sphinx_sourcedir='src',
                    sphinx_builddir="bld",
                    sphinx_builder='css',
                    sphinx="/path/to/sphinx-build",
                    tags=['a', 'b'],
                    defines=dict(empty=None, t=True, f=False, s="str"),
                    mode='full'))
        self.expectCommands(
            ExpectShell(workdir='wkdir', usePTY='slave-config',
                        command=['/path/to/sphinx-build', '-b', 'css',
                                 '-t', 'a', '-t', 'b', '-D', 'empty',
                                 '-D', 'f=0', '-D', 's=str', '-D', 't=1',
                                 '-E', 'src', 'bld'])
            + ExpectShell.log('stdio',
                stdout=log_output_success)
            + 0
        )
        self.expectOutcome(result=SUCCESS, status_text=["sphinx", "0 warnings"])
        return self.runStep()