1 | # ***** BEGIN LICENSE BLOCK *****
|
---|
2 | # Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
3 | #
|
---|
4 | # The contents of this file are subject to the Mozilla Public License Version
|
---|
5 | # 1.1 (the "License"); you may not use this file except in compliance with
|
---|
6 | # the License. You may obtain a copy of the License at
|
---|
7 | # http://www.mozilla.org/MPL/
|
---|
8 | #
|
---|
9 | # Software distributed under the License is distributed on an "AS IS" basis,
|
---|
10 | # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
11 | # for the specific language governing rights and limitations under the
|
---|
12 | # License.
|
---|
13 | #
|
---|
14 | # The Original Code is Python XPCOM language bindings.
|
---|
15 | #
|
---|
16 | # The Initial Developer of the Original Code is
|
---|
17 | # ActiveState Tool Corp.
|
---|
18 | # Portions created by the Initial Developer are Copyright (C) 2000
|
---|
19 | # the Initial Developer. All Rights Reserved.
|
---|
20 | #
|
---|
21 | # Contributor(s):
|
---|
22 | # Mark Hammond <[email protected]> (original author)
|
---|
23 | #
|
---|
24 | # Alternatively, the contents of this file may be used under the terms of
|
---|
25 | # either the GNU General Public License Version 2 or later (the "GPL"), or
|
---|
26 | # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
27 | # in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
28 | # of those above. If you wish to allow use of your version of this file only
|
---|
29 | # under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
30 | # use your version of this file under the terms of the MPL, indicate your
|
---|
31 | # decision by deleting the provisions above and replace them with the notice
|
---|
32 | # and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
33 | # the provisions above, a recipient may use your version of this file under
|
---|
34 | # the terms of any one of the MPL, the GPL or the LGPL.
|
---|
35 | #
|
---|
36 | # ***** END LICENSE BLOCK *****
|
---|
37 |
|
---|
38 | # regrtest.py
|
---|
39 | #
|
---|
40 | # The Regression Tests for the xpcom package.
|
---|
41 | import os
|
---|
42 | import sys
|
---|
43 |
|
---|
44 | import unittest
|
---|
45 |
|
---|
46 | # A little magic to create a single "test suite" from all test_ files
|
---|
47 | # in this dir. A single suite makes for prettier output test :)
|
---|
48 | def suite():
|
---|
49 | # Loop over all test_*.py files here
|
---|
50 | try:
|
---|
51 | me = __file__
|
---|
52 | except NameError:
|
---|
53 | me = sys.argv[0]
|
---|
54 | me = os.path.abspath(me)
|
---|
55 | files = os.listdir(os.path.dirname(me))
|
---|
56 | suite = unittest.TestSuite()
|
---|
57 | # XXX - add the others here!
|
---|
58 | #suite.addTest(unittest.FunctionTestCase(import_all))
|
---|
59 | for file in files:
|
---|
60 | base, ext = os.path.splitext(file)
|
---|
61 | if ext=='.py' and os.path.basename(base).startswith("test_"):
|
---|
62 | mod = __import__(base)
|
---|
63 | if hasattr(mod, "suite"):
|
---|
64 | test = mod.suite()
|
---|
65 | else:
|
---|
66 | test = unittest.defaultTestLoader.loadTestsFromModule(mod)
|
---|
67 | suite.addTest(test)
|
---|
68 | return suite
|
---|
69 |
|
---|
70 | class CustomLoader(unittest.TestLoader):
|
---|
71 | def loadTestsFromModule(self, module):
|
---|
72 | return suite()
|
---|
73 |
|
---|
74 | try:
|
---|
75 | unittest.TestProgram(testLoader=CustomLoader())(argv=sys.argv)
|
---|
76 | finally:
|
---|
77 | from xpcom import _xpcom
|
---|
78 | _xpcom.NS_ShutdownXPCOM() # To get leak stats and otherwise ensure life is good.
|
---|
79 | ni = _xpcom._GetInterfaceCount()
|
---|
80 | ng = _xpcom._GetGatewayCount()
|
---|
81 | if ni or ng:
|
---|
82 | # The old 'regrtest' that was not based purely on unittest did not
|
---|
83 | # do this check at the end - it relied on each module doing it itself.
|
---|
84 | # Thus, these leaks are not new, just newly noticed :) Likely to be
|
---|
85 | # something silly like module globals.
|
---|
86 | if ni == 6 and ng == 1:
|
---|
87 | print "Sadly, there are 6/1 leaks, but these appear normal and benign"
|
---|
88 | else:
|
---|
89 | print "********* WARNING - Leaving with %d/%d objects alive" % (ni,ng)
|
---|
90 | else:
|
---|
91 | print "yay! Our leaks have all vanished!"
|
---|