10637.3.1
by Guilherme Salgado
Use the default python version instead of a hard-coded version |
1 |
#! /usr/bin/python -S
|
8687.15.4
by Karl Fogel
Add the copyright header block to more files; tweak format in a few files. |
2 |
#
|
3 |
# Copyright 2009 Canonical Ltd. This software is licensed under the
|
|
4 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
3851.3.3
by Francis J. Lacoste
Add check-content-interfaces.py utility script. |
5 |
|
6 |
"""
|
|
7 |
check-content-interfaces.py - Check Content Interfaces.
|
|
8 |
||
9 |
= Launchpad Content Interfaces =
|
|
10 |
||
11 |
XXX flacoste 2007/02/21 Ideally this should be a unit test.
|
|
12 |
Unfortunately, it would currently fail. See bug 87199.
|
|
13 |
||
14 |
Launchpad is complex piece of software composed of multiple
|
|
15 |
applications. Many components use other components, so it is important
|
|
16 |
for each of them to clearly define the interface it supports and make
|
|
17 |
sure that it respects its contract.
|
|
18 |
||
3851.3.4
by Francis J. Lacoste
Typos. |
19 |
This is especially important as newcomers joining the team will often look
|
3851.3.3
by Francis J. Lacoste
Add check-content-interfaces.py utility script. |
20 |
at the interface of a component in another part of Launchpad to know
|
3851.3.4
by Francis J. Lacoste
Typos. |
21 |
what properties/methods are available on the object.
|
3851.3.3
by Francis J. Lacoste
Add check-content-interfaces.py utility script. |
22 |
|
3851.3.4
by Francis J. Lacoste
Typos. |
23 |
Ideally, all components should have a test of this form as part of their
|
3851.3.3
by Francis J. Lacoste
Add check-content-interfaces.py utility script. |
24 |
system documentation.
|
25 |
||
26 |
> > > verifyObject(IContentInterface, object)
|
|
27 |
True
|
|
28 |
||
29 |
This is a fall back test that makes sure that all content classes
|
|
3851.3.4
by Francis J. Lacoste
Typos. |
30 |
really do implement the interfaces it declares to.
|
3851.3.3
by Francis J. Lacoste
Add check-content-interfaces.py utility script. |
31 |
|
32 |
It's not because a class implements correctly an interface that
|
|
33 |
verifyObject on its instances would also pass. verifyClass only checks
|
|
34 |
the methods of the interface (since it is possible that some attributes
|
|
35 |
will be provided at construction time). Also additional constraints will
|
|
3851.3.4
by Francis J. Lacoste
Typos. |
36 |
be checked on instance attributes that are part of a schema.
|
3851.3.3
by Francis J. Lacoste
Add check-content-interfaces.py utility script. |
37 |
|
38 |
"""
|
|
39 |
||
40 |
import _pythonpath |
|
41 |
||
42 |
from zope.interface import implementedBy |
|
43 |
from zope.interface.exceptions import ( |
|
14612.2.6
by William Grant
utilities |
44 |
BrokenImplementation, |
45 |
BrokenMethodImplementation, |
|
46 |
)
|
|
3851.3.3
by Francis J. Lacoste
Add check-content-interfaces.py utility script. |
47 |
from zope.interface.verify import verifyClass |
48 |
||
14612.2.6
by William Grant
utilities |
49 |
|
14600.1.13
by Curtis Hovey
Fixed i18n package. |
50 |
all_model_names = 'Some miracle process' |
3851.3.3
by Francis J. Lacoste
Add check-content-interfaces.py utility script. |
51 |
|
52 |
def check_content_classes(): |
|
53 |
classes_checked = 0 |
|
54 |
classes_with_failures = 1 |
|
14600.1.13
by Curtis Hovey
Fixed i18n package. |
55 |
for class_name in dir(all_model_names): |
56 |
klass = getattr(all_model_names, class_name) |
|
3851.3.3
by Francis J. Lacoste
Add check-content-interfaces.py utility script. |
57 |
# Skip names that don't implement anything.
|
58 |
if getattr(klass, '__implemented__', None) is None: |
|
59 |
continue
|
|
60 |
for interface in implementedBy(klass): |
|
61 |
interface_name = interface.__name__.split('.')[-1] |
|
62 |
try: |
|
63 |
classes_checked += 1 |
|
64 |
result = verifyClass(interface, klass) |
|
65 |
except BrokenImplementation, e: |
|
66 |
classes_with_failures += 1 |
|
67 |
print "%s fails to implement %s: missing attribute %s" % ( |
|
68 |
class_name, interface_name, e.name) |
|
69 |
except BrokenMethodImplementation, e: |
|
70 |
classes_with_failures += 1 |
|
71 |
print "%s fails to implement %s: invalid method %s: %s" % ( |
|
72 |
class_name, interface_name, e.method, e.mess) |
|
3851.3.4
by Francis J. Lacoste
Typos. |
73 |
print "** Checked %d content classes. Found %d with broken implementation." % ( |
3851.3.3
by Francis J. Lacoste
Add check-content-interfaces.py utility script. |
74 |
classes_checked, classes_with_failures) |
75 |
||
76 |
||
77 |
if __name__ == '__main__': |
|
3944.1.1
by Francis J. Lacoste
Use system version python2.4 for scripts. |
78 |
check_content_classes() |