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
|
# Ubuntu CI Engine
# Copyright 2014 Canonical Ltd.
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License version 3, as
# published by the Free Software Foundation.
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranties of
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Helpers to implement style tests.
uci-tests relies on the assumption that all tests reside in python
packages. This isn't true for some of the uci-engine tests. The classes below
provide a directory where test files should be checked instead.
"""
import cStringIO
import os
from ucitests import (
assertions,
styles,
)
class TestPep8(styles.TestPep8):
directory = None
def test_pep8_conformance(self):
self.assertIsNot(None, self.directory,
'You should define the directory to check')
self.pep8style.input_dir(self.directory)
self.assertEqual([], self.report._msgs,
'\n'.join(self.report._msgs))
class TestPyflakes(styles.TestPyflakes):
directory = None
def test_pyflakes_conformance(self):
from pyflakes import (
api,
reporter,
)
self.assertIsNot(None, self.directory,
'You should define the directory to check')
out = cStringIO.StringIO()
err = cStringIO.StringIO()
report = reporter.Reporter(out, err)
paths = [self.directory]
walker = styles.PythonFileWalker(None)
for p in paths:
root, base = os.path.split(p)
sw = walker.SubWalker(root)
styles.pyflakes_check_dir(sw, base, self.excludes,
api.checkPath, report)
out_val = out.getvalue()
if out_val:
assertions.assertMultiLineAlmostEqual(self, '', out_val)
err_val = err.getvalue()
if err_val:
assertions.assertMultiLineAlmostEqual(self, '', err_val)
|