PageRenderTime 84ms CodeModel.GetById 0ms RepoModel.GetById 0ms 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. import os
  27. import unittest
  28. import test_apiary
  29. class ComprehensiveTestLoader (unittest.TestLoader):
  30. # Sheesh... I can't believe we have to write this class to discover all tests in a package:
  31. def loadTestsFromModule(self, module):
  32. def import_submodule(modname):
  33. m = __import__(modname)
  34. for frag in modname.split('.')[1:]:
  35. m = getattr(m, frag)
  36. return m
  37. path = module.__file__
  38. if os.path.splitext(os.path.basename(path))[0] == '__init__':
  39. # This is a package, rather than a simple module:
  40. suites = []
  41. for name in os.listdir(os.path.dirname(path)):
  42. stem, ext = os.path.splitext(name)
  43. if stem == '__init__':
  44. continue
  45. elif ext == '.py':
  46. m = import_submodule(module.__name__ + '.' + stem)
  47. suites.append(self.loadTestsFromModule(m))
  48. elif ext == '':
  49. subpath = os.path.join(path, name)
  50. if os.path.isdir(subpath):
  51. # *FIX: This may fail if there is a non-package subdirectory:
  52. m = import_submodule(module.__name__ + '.' + name)
  53. suites.append(self.loadTestsFromModule(m))
  54. else:
  55. pass # Ignore other file types.
  56. return self.suiteClass(suites)
  57. else:
  58. # Simple superclass loader handles a single module:
  59. return unittest.TestLoader.loadTestsFromModule(self, module)
  60. if __name__ == '__main__':
  61. unittest.main(module=test_apiary, testLoader=ComprehensiveTestLoader())