/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: Robert Collins
  • Date: 2009-05-23 20:57:12 UTC
  • mfrom: (4371 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4441.
  • Revision ID: robertc@robertcollins.net-20090523205712-lcwbfqk6vwavinuv
MergeĀ .dev.

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
 
35
35
    )
36
36
import bzrlib.branch
37
37
from bzrlib.tests import (
38
 
    KnownFailure,
39
38
    TestCase,
40
39
    TestSkipped,
41
40
    )
110
109
                              % source_dir)
111
110
        return source_dir
112
111
 
113
 
    def get_source_files(self):
 
112
    def get_source_files(self, extensions=None):
114
113
        """Yield all source files for bzr and bzrlib
115
114
 
116
115
        :param our_files_only: If true, exclude files from included libraries
117
116
            or plugins.
118
117
        """
119
118
        bzrlib_dir = self.get_bzrlib_dir()
 
119
        if extensions is None:
 
120
            extensions = ('.py',)
120
121
 
121
122
        # This is the front-end 'bzr' script
122
123
        bzr_path = self.get_bzr_path()
127
128
                if d.endswith('.tmp'):
128
129
                    dirs.remove(d)
129
130
            for f in files:
130
 
                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
131
136
                    continue
132
137
                yield osutils.pathjoin(root, f)
133
138
 
134
 
    def get_source_file_contents(self):
135
 
        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):
136
141
            f = open(fname, 'rb')
137
142
            try:
138
143
                text = f.read()
176
181
                          % filename)
177
182
 
178
183
    def test_copyright(self):
179
 
        """Test that all .py files have a valid copyright statement"""
180
 
        # These are files which contain a different copyright statement
181
 
        # and that is okay.
 
184
        """Test that all .py and .pyx files have a valid copyright statement"""
182
185
        incorrect = []
183
186
 
184
187
        copyright_re = re.compile('#\\s*copyright.*(?=\n)', re.I)
188
191
            r'.*Canonical Ltd' # And containing 'Canonical Ltd'
189
192
            )
190
193
 
191
 
        for fname, text in self.get_source_file_contents():
 
194
        for fname, text in self.get_source_file_contents(
 
195
                extensions=('.py', '.pyx')):
192
196
            if self.is_copyright_exception(fname):
193
197
                continue
194
198
            match = copyright_canonical_re.search(text)
223
227
            self.fail('\n'.join(help_text))
224
228
 
225
229
    def test_gpl(self):
226
 
        """Test that all .py files have a GPL disclaimer"""
 
230
        """Test that all .py and .pyx files have a GPL disclaimer."""
227
231
        incorrect = []
228
232
 
229
233
        gpl_txt = """
239
243
#
240
244
# You should have received a copy of the GNU General Public License
241
245
# along with this program; if not, write to the Free Software
242
 
# 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
243
247
"""
244
248
        gpl_re = re.compile(re.escape(gpl_txt), re.MULTILINE)
245
249
 
246
 
        for fname, text in self.get_source_file_contents():
 
250
        for fname, text in self.get_source_file_contents(
 
251
                extensions=('.py', '.pyx')):
247
252
            if self.is_license_exception(fname):
248
253
                continue
249
254
            if not gpl_re.search(text):
278
283
    def test_coding_style(self):
279
284
        """Check if bazaar code conforms to some coding style conventions.
280
285
 
281
 
        Currently we check for:
 
286
        Currently we assert that the following is not present:
282
287
         * any tab characters
283
 
         * trailing white space
284
288
         * non-unix newlines
285
289
         * no newline at end of files
 
290
 
 
291
        Print how many files have
 
292
         * trailing white space
286
293
         * lines longer than 79 chars
287
 
           (only print how many files and lines are in violation)
288
294
        """
289
295
        tabs = {}
290
296
        trailing_ws = {}
291
297
        illegal_newlines = {}
292
298
        long_lines = {}
293
299
        no_newline_at_eof = []
294
 
        for fname, text in self.get_source_file_contents():
 
300
        for fname, text in self.get_source_file_contents(
 
301
                extensions=('.py', '.pyx')):
295
302
            if not self.is_our_code(fname):
296
303
                continue
297
304
            lines = text.splitlines(True)
314
321
                'Tab characters were found in the following source files.'
315
322
                '\nThey should either be replaced by "\\t" or by spaces:'))
316
323
        if trailing_ws:
317
 
            problems.append(self._format_message(trailing_ws,
318
 
                'Trailing white space was found in the following source files:'
319
 
                ))
 
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)))
320
327
        if illegal_newlines:
321
328
            problems.append(self._format_message(illegal_newlines,
322
329
                'Non-unix newlines were found in the following source files:'))
331
338
               '\n\n    %s'
332
339
               % ('\n    '.join(no_newline_at_eof)))
333
340
        if problems:
334
 
            raise KnownFailure("test_coding_style has failed")
335
341
            self.fail('\n\n'.join(problems))
336
342
 
337
343
    def test_no_asserts(self):