PageRenderTime 241ms CodeModel.GetById 93ms app.highlight 43ms RepoModel.GetById 98ms app.codeStats 0ms

/test_apiary/main.py

https://bitbucket.org/lindenlab/apiary/
Python | 70 lines | 37 code | 6 blank | 27 comment | 6 complexity | 3ea0dbe83b7352de93f1c1b411686717 MD5 | raw file
 1#! /usr/bin/env python
 2#
 3# $LicenseInfo:firstyear=2010&license=mit$
 4# 
 5# Copyright (c) 2010, Linden Research, Inc.
 6# 
 7# Permission is hereby granted, free of charge, to any person obtaining a copy
 8# of this software and associated documentation files (the "Software"), to deal
 9# in the Software without restriction, including without limitation the rights
10# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11# copies of the Software, and to permit persons to whom the Software is
12# furnished to do so, subject to the following conditions:
13# 
14# The above copyright notice and this permission notice shall be included in
15# all copies or substantial portions of the Software.
16# 
17# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23# THE SOFTWARE.
24# $/LicenseInfo$
25#
26
27import os
28import unittest
29
30import test_apiary
31
32
33class ComprehensiveTestLoader (unittest.TestLoader):
34    # Sheesh...  I can't believe we have to write this class to discover all tests in a package:
35    def loadTestsFromModule(self, module):
36        def import_submodule(modname):
37            m = __import__(modname)
38            for frag in modname.split('.')[1:]:
39                m = getattr(m, frag)
40            return m
41            
42        path = module.__file__
43        if os.path.splitext(os.path.basename(path))[0] == '__init__':
44            # This is a package, rather than a simple module:
45            suites = []
46            
47            for name in os.listdir(os.path.dirname(path)):
48                stem, ext = os.path.splitext(name)
49                if stem == '__init__':
50                    continue
51                elif ext == '.py':
52                    m = import_submodule(module.__name__ + '.' + stem)
53                    suites.append(self.loadTestsFromModule(m))
54                elif ext == '':
55                    subpath = os.path.join(path, name)
56                    if os.path.isdir(subpath):
57                        # *FIX: This may fail if there is a non-package subdirectory:
58                        m = import_submodule(module.__name__ + '.' + name)
59                        suites.append(self.loadTestsFromModule(m))
60                else:
61                    pass # Ignore other file types.
62            return self.suiteClass(suites)
63        else:
64            # Simple superclass loader handles a single module:
65            return unittest.TestLoader.loadTestsFromModule(self, module)
66                    
67
68
69if __name__ == '__main__':
70    unittest.main(module=test_apiary, testLoader=ComprehensiveTestLoader())