/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_source.py

  • Committer: Martin Pool
  • Date: 2009-06-05 23:21:51 UTC
  • mfrom: (4415 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4416.
  • Revision ID: mbp@sourcefrog.net-20090605232151-luwmyyl95siraqyz
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
#
15
15
# You should have received a copy of the GNU General Public License
16
16
# along with this program; if not, write to the Free Software
17
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
 
19
19
"""These tests are tests about the source code of bzrlib itself.
20
20
 
42
42
 
43
43
# Files which are listed here will be skipped when testing for Copyright (or
44
44
# GPL) statements.
45
 
COPYRIGHT_EXCEPTIONS = ['bzrlib/lsprof.py']
 
45
COPYRIGHT_EXCEPTIONS = ['bzrlib/lsprof.py', 'bzrlib/_bencode_py.py']
46
46
 
47
 
LICENSE_EXCEPTIONS = ['bzrlib/lsprof.py']
 
47
LICENSE_EXCEPTIONS = ['bzrlib/lsprof.py', 'bzrlib/_bencode_py.py']
48
48
# Technically, 'bzrlib/lsprof.py' should be 'bzrlib/util/lsprof.py',
49
49
# (we do not check bzrlib/util/, since that is code bundled from elsewhere)
50
50
# but for compatibility with previous releases, we don't want to move it.
109
109
                              % source_dir)
110
110
        return source_dir
111
111
 
112
 
    def get_source_files(self):
 
112
    def get_source_files(self, extensions=None):
113
113
        """Yield all source files for bzr and bzrlib
114
114
 
115
115
        :param our_files_only: If true, exclude files from included libraries
116
116
            or plugins.
117
117
        """
118
118
        bzrlib_dir = self.get_bzrlib_dir()
 
119
        if extensions is None:
 
120
            extensions = ('.py',)
119
121
 
120
122
        # This is the front-end 'bzr' script
121
123
        bzr_path = self.get_bzr_path()
126
128
                if d.endswith('.tmp'):
127
129
                    dirs.remove(d)
128
130
            for f in files:
129
 
                if not f.endswith('.py'):
 
131
                for extension in extensions:
 
132
                    if f.endswith(extension):
 
133
                        break
 
134
                else:
 
135
                    # Did not match the accepted extensions
130
136
                    continue
131
137
                yield osutils.pathjoin(root, f)
132
138
 
133
 
    def get_source_file_contents(self):
134
 
        for fname in self.get_source_files():
 
139
    def get_source_file_contents(self, extensions=None):
 
140
        for fname in self.get_source_files(extensions=extensions):
135
141
            f = open(fname, 'rb')
136
142
            try:
137
143
                text = f.read()
175
181
                          % filename)
176
182
 
177
183
    def test_copyright(self):
178
 
        """Test that all .py files have a valid copyright statement"""
179
 
        # These are files which contain a different copyright statement
180
 
        # and that is okay.
 
184
        """Test that all .py and .pyx files have a valid copyright statement"""
181
185
        incorrect = []
182
186
 
183
187
        copyright_re = re.compile('#\\s*copyright.*(?=\n)', re.I)
187
191
            r'.*Canonical Ltd' # And containing 'Canonical Ltd'
188
192
            )
189
193
 
190
 
        for fname, text in self.get_source_file_contents():
 
194
        for fname, text in self.get_source_file_contents(
 
195
                extensions=('.py', '.pyx')):
191
196
            if self.is_copyright_exception(fname):
192
197
                continue
193
198
            match = copyright_canonical_re.search(text)
222
227
            self.fail('\n'.join(help_text))
223
228
 
224
229
    def test_gpl(self):
225
 
        """Test that all .py files have a GPL disclaimer"""
 
230
        """Test that all .py and .pyx files have a GPL disclaimer."""
226
231
        incorrect = []
227
232
 
228
233
        gpl_txt = """
238
243
#
239
244
# You should have received a copy of the GNU General Public License
240
245
# along with this program; if not, write to the Free Software
241
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
246
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
242
247
"""
243
248
        gpl_re = re.compile(re.escape(gpl_txt), re.MULTILINE)
244
249
 
245
 
        for fname, text in self.get_source_file_contents():
 
250
        for fname, text in self.get_source_file_contents(
 
251
                extensions=('.py', '.pyx')):
246
252
            if self.is_license_exception(fname):
247
253
                continue
248
254
            if not gpl_re.search(text):
277
283
    def test_coding_style(self):
278
284
        """Check if bazaar code conforms to some coding style conventions.
279
285
 
280
 
        Currently we check for:
 
286
        Currently we assert that the following is not present:
281
287
         * any tab characters
282
 
         * trailing white space
283
288
         * non-unix newlines
284
289
         * no newline at end of files
 
290
 
 
291
        Print how many files have
 
292
         * trailing white space
285
293
         * lines longer than 79 chars
286
 
           (only print how many files and lines are in violation)
287
294
        """
288
295
        tabs = {}
289
296
        trailing_ws = {}
290
297
        illegal_newlines = {}
291
298
        long_lines = {}
292
299
        no_newline_at_eof = []
293
 
        for fname, text in self.get_source_file_contents():
 
300
        for fname, text in self.get_source_file_contents(
 
301
                extensions=('.py', '.pyx')):
294
302
            if not self.is_our_code(fname):
295
303
                continue
296
304
            lines = text.splitlines(True)
313
321
                'Tab characters were found in the following source files.'
314
322
                '\nThey should either be replaced by "\\t" or by spaces:'))
315
323
        if trailing_ws:
316
 
            problems.append(self._format_message(trailing_ws,
317
 
                'Trailing white space was found in the following source files:'
318
 
                ))
 
324
            print ("There are %i lines with trailing white space in %i files."
 
325
                % (sum([len(lines) for f, lines in trailing_ws.items()]),
 
326
                    len(trailing_ws)))
319
327
        if illegal_newlines:
320
328
            problems.append(self._format_message(illegal_newlines,
321
329
                'Non-unix newlines were found in the following source files:'))