/rmgpy/scoop_framework/utilTest.py

https://github.com/connie/RMG-Py · Python · 114 lines · 57 code · 30 blank · 27 comment · 9 complexity · 491a99d1ee37dbd52ab6cc3c8ccdb1a9 MD5 · raw file

  1. #!/usr/bin/env python
  2. # encoding: utf-8 -*-
  3. """
  4. This module contains unit tests of the rmgpy.parallel module.
  5. """
  6. import os
  7. import sys
  8. import unittest
  9. from external.wip import work_in_progress
  10. from rmgpy.scoop_framework.framework import TestScoopCommon
  11. try:
  12. from scoop import futures, _control, shared
  13. except ImportError, e:
  14. import logging as logging
  15. logging.debug("Could not properly import SCOOP.")
  16. from .util import *
  17. def boom():
  18. return 0 / 0
  19. class WorkerWrapperTest(unittest.TestCase):
  20. def test_WorkerWrapper(self):
  21. """
  22. Test that the WorkerWrapper correctly redirects the error
  23. message.
  24. """
  25. f = WorkerWrapper(boom)
  26. with self.assertRaises(ZeroDivisionError):
  27. f()
  28. def funcBroadcast():
  29. """
  30. Broadcast the data with the given key,
  31. and retrieve it again by querying the key again.
  32. """
  33. data = 'foo'
  34. key = 'bar'
  35. broadcast(data, key)
  36. result = True
  37. try:
  38. assert data == shared.getConst(key)
  39. except AssertionError:
  40. return False
  41. return True
  42. def funcRetrieve():
  43. """
  44. Broadcast the data with the given key,
  45. retrieve it again by querying the key again.
  46. """
  47. data = 'foo'
  48. key = 'bar'
  49. broadcast(data, key)
  50. try:
  51. assert data == get(key)
  52. except AssertionError:
  53. return False
  54. return True
  55. @work_in_progress
  56. class BroadcastTest(TestScoopCommon):
  57. def __init__(self, *args, **kwargs):
  58. # Parent initialization
  59. super(self.__class__, self).__init__(*args, **kwargs)
  60. # Only setup the scoop framework once, and not in every test method:
  61. super(self.__class__, self).setUp()
  62. @unittest.skipUnless(sys.platform.startswith("linux"),
  63. "test currently only runs on linux")
  64. def test_generic(self):
  65. """
  66. Test that we can broadcast a simple string.
  67. """
  68. result = futures._startup(funcBroadcast)
  69. self.assertEquals(result, True)
  70. @work_in_progress
  71. class GetTest(TestScoopCommon):
  72. def __init__(self, *args, **kwargs):
  73. # Parent initialization
  74. super(self.__class__, self).__init__(*args, **kwargs)
  75. # Only setup the scoop framework once, and not in every test method:
  76. super(self.__class__, self).setUp()
  77. def test_generic(self):
  78. """
  79. Test that we can retrieve a simple shared string.
  80. """
  81. result = futures._startup(funcRetrieve)
  82. self.assertEquals(result, True)
  83. if __name__ == '__main__' and os.environ.get('IS_ORIGIN', "1") == "1":
  84. unittest.main()