PageRenderTime 50ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/rpy/tests.py

https://bitbucket.org/breisfeld/rpy2_w32_fix
Python | 101 lines | 97 code | 1 blank | 3 comment | 1 complexity | 7c1685bbee6f3f7539ff568531b7c5b5 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause
  1. #!/usr/bin/env python
  2. '''tests.py - run all the tests worth running
  3. The goal is that "ERRORS" and "FAILURES" are true failures, and expected
  4. problems sould be dealt with using decorators.'''
  5. from __future__ import print_function
  6. # if `singledispatch` is absent, the unit tests are failing with a rather
  7. # obscure / misleading error message. Test it now and report the problem.
  8. import sys
  9. if sys.version_info[0] < 3 or (sys.version_info[0] == 3 and sys.version_info[1] < 4):
  10. try:
  11. from singledispatch import singledispatch
  12. except ImportError as ie:
  13. print('The module "singledispatch is required for Python < 3.4')
  14. raise ie
  15. from os.path import dirname
  16. import unittest
  17. import rpy2
  18. import rpy2.tests_rpy_classic
  19. def load_tests(loader, tests, pattern):
  20. '''Run tests a little faster than with TestLoader.discover()
  21. Note that we are using the unittest API here, but blithely ignore the values
  22. passed in for `tests` and `pattern`'''
  23. # For some reason, the commented code directly below is slow and loads some
  24. # things twice One specific message is regarding package_dependencies from
  25. # the tools package.
  26. # rpy_root = dirname(rpy2.__file__)
  27. # alltests = unittest.defaultTestLoader.discover(rpy_root, pattern='test*')
  28. rpy_root = dirname(rpy2.__file__)
  29. tests = unittest.TestSuite()
  30. pattern = 'test*'
  31. # This now catches some extra tests (bypassing the suite() functions),
  32. # at least in a virtualenv that lacks various packages, like numpy &
  33. # pandas
  34. suite_robjects = loader.discover('robjects', pattern, rpy_root)
  35. suite_rinterface = loader.discover('rinterface', pattern, rpy_root)
  36. suite_rlike = loader.discover('rlike', pattern, rpy_root)
  37. # This is once again testless
  38. suite_interactive = loader.discover('interactive', pattern, rpy_root)
  39. # ipython is a little trickier because it is an optional
  40. # dependency.
  41. try:
  42. import IPython
  43. has_ipython = True
  44. except ImportError as ie:
  45. has_ipython = False
  46. if has_ipython:
  47. suite_ipython= loader.discover('ipython', pattern, rpy_root)
  48. else:
  49. class MissingIpythonTestCase(unittest.TestCase):
  50. @unittest.skip("The optional dependency IPython is required in order to test features using it.")
  51. def testHasIpython(self):
  52. pass
  53. suite_ipython = unittest.TestLoader().loadTestsFromTestCase(MissingIpythonTestCase)
  54. suite_rpy_classic = rpy2.tests_rpy_classic.suite()
  55. tests.addTests([suite_rinterface,
  56. suite_robjects,
  57. suite_rlike,
  58. suite_interactive,
  59. suite_ipython,
  60. suite_rpy_classic
  61. ])
  62. return tests
  63. if __name__ == "__main__":
  64. import sys, rpy2.rinterface
  65. print("rpy2 version: %s" % rpy2.__version__)
  66. print("- built against R version: %s" % '-'.join(str(x)
  67. for x in rpy2.rinterface.R_VERSION_BUILD))
  68. try:
  69. import rpy2.rinterface
  70. except Exception as e:
  71. print("'rpy2.rinterface' could not be imported:")
  72. print(e)
  73. sys.exit(1)
  74. try:
  75. rpy2.rinterface.initr()
  76. except Exception as e:
  77. print("- The embedded R could not be initialized")
  78. print(e)
  79. sys.exit(1)
  80. try:
  81. rv = rpy2.rinterface.baseenv['R.version.string']
  82. print("- running linked to R version: %s" % rv[0])
  83. except KeyError as ke:
  84. print("The R version dynamically linked cannot be identified.")
  85. # This will sys.exit() with an appropriate error code
  86. unittest.main(buffer=True)