~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_source.py

Add bzrlib.pyutils, which has get_named_object, a wrapper around __import__.

This is used to replace various ad hoc implementations of the same logic,
notably the version used in registry's _LazyObjectGetter which had a bug when
getting a module without also getting a member.  And of course, this new
function has unit tests, unlike the replaced code.

This also adds a KnownHooksRegistry subclass to provide a more natural home for
some other logic.

I'm not thrilled about the name of the new module or the new functions, but it's
hard to think of good names for such generic functionality.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
 
41
41
# Files which are listed here will be skipped when testing for Copyright (or
42
42
# GPL) statements.
43
 
COPYRIGHT_EXCEPTIONS = ['bzrlib/lsprof.py', 'bzrlib/_bencode_py.py',
44
 
    'bzrlib/doc_generate/sphinx_conf.py']
 
43
COPYRIGHT_EXCEPTIONS = [
 
44
    'bzrlib/_bencode_py.py',
 
45
    'bzrlib/doc_generate/conf.py',
 
46
    'bzrlib/lsprof.py',
 
47
    ]
45
48
 
46
 
LICENSE_EXCEPTIONS = ['bzrlib/lsprof.py', 'bzrlib/_bencode_py.py',
47
 
    'bzrlib/doc_generate/sphinx_conf.py']
 
49
LICENSE_EXCEPTIONS = [
 
50
    'bzrlib/_bencode_py.py',
 
51
    'bzrlib/doc_generate/conf.py',
 
52
    'bzrlib/lsprof.py',
 
53
    ]
48
54
# Technically, 'bzrlib/lsprof.py' should be 'bzrlib/util/lsprof.py',
49
55
# (we do not check bzrlib/util/, since that is code bundled from elsewhere)
50
56
# but for compatibility with previous releases, we don't want to move it.
382
388
        """
383
389
        both_exc_and_no_exc = []
384
390
        missing_except = []
385
 
        class_re = re.compile(r'^(cdef\s+)?(public\s+)?(api\s+)?class (\w+).*:',
386
 
                              re.MULTILINE)
 
391
        class_re = re.compile(r'^(cdef\s+)?(public\s+)?'
 
392
                              r'(api\s+)?class (\w+).*:', re.MULTILINE)
 
393
        extern_class_re = re.compile(r'## extern cdef class (\w+)',
 
394
                                     re.MULTILINE)
387
395
        except_re = re.compile(r'cdef\s+' # start with cdef
388
396
                               r'([\w *]*?)\s*' # this is the return signature
389
397
                               r'(\w+)\s*\(' # the function name
394
402
        for fname, text in self.get_source_file_contents(
395
403
                extensions=('.pyx',)):
396
404
            known_classes = set([m[-1] for m in class_re.findall(text)])
 
405
            known_classes.update(extern_class_re.findall(text))
397
406
            cdefs = except_re.findall(text)
398
407
            for sig, func, exc_clause, no_exc_comment in cdefs:
399
408
                if sig.startswith('api '):