2
# arch-tag: f6217865-fab7-4233-8a8b-ab6cb5388657
3
# Copyright (C) 2003 Ben Burns <bburns@mailops.com>
4
# 2004 David Allouche <david@allouche.net>
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28
from arch.tests import framework
31
def matchFiles(files, regexp):
34
mymatch = re.findall(regexp, f)
39
def filesInDir(directory):
41
for (dirpath, dirname, filenames) in os.walk(directory):
43
result.append(dirpath + os.path.sep + f)
46
def findPythonFiles():
47
files = filesInDir('.')
48
files = matchFiles(files, r'.*\.py$')
49
archfiles=matchFiles(files, '{arch}')
50
for archfile in archfiles:
51
files.remove(archfile)
54
def getWrappedText(text, length=80):
56
for line in text.splitlines():
58
wrappedLines.append(line)
60
for wrappedLine in textwrap.wrap(line, length):
61
wrappedLines.append(wrappedLine)
62
wrappedText = '\n'.join(wrappedLines)+'\n'
66
class CodingStandards(unittest.TestCase):
68
"""Test what we can as far as coding standards go."""
70
def testTextWrap(self):
71
"""Wrapping is idempotent on source files."""
72
for filename in findPythonFiles():
73
text = open(filename).read()
74
wrapped = getWrappedText(text)
75
if not text == wrapped:
76
lines = text.splitlines()
77
wraps = wrapped.splitlines()
80
if not line == wraps[index]:
81
msg = "Difference in %s" % (filename,)
82
msg += " on line %s" % (index+1,)
83
msg += "\nLine: " + line
84
msg += "\nWrap: " + wraps[index]
85
self.failUnlessEqual(line, wraps[index], msg)
89
def test_suite(limit=()):
93
return framework.make_test_suite(globals(), classes, limit)
96
return framework.run_test_suite(argv, test_suite)
98
if __name__ == "__main__":
99
sys.exit(main(sys.argv))