testing.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # -*- coding: utf-8 -*-
  2. """Shared testing code."""
  3. from plone.testing import Layer
  4. from unittest2 import TestCase
  5. import os
  6. import subprocess
  7. import sys
  8. class SearxTestLayer:
  9. __name__ = u'SearxTestLayer'
  10. def setUp(cls):
  11. pass
  12. setUp = classmethod(setUp)
  13. def tearDown(cls):
  14. pass
  15. tearDown = classmethod(tearDown)
  16. def testSetUp(cls):
  17. pass
  18. testSetUp = classmethod(testSetUp)
  19. def testTearDown(cls):
  20. pass
  21. testTearDown = classmethod(testTearDown)
  22. class SearxRobotLayer(Layer):
  23. """Searx Robot Test Layer"""
  24. def setUp(self):
  25. os.setpgrp() # create new process group, become its leader
  26. webapp = os.path.join(
  27. os.path.abspath(os.path.dirname(os.path.realpath(__file__))),
  28. 'webapp.py'
  29. )
  30. exe = os.path.abspath(os.path.dirname(__file__) + '/../bin/py')
  31. self.server = subprocess.Popen(
  32. [exe, webapp, 'settings_robot'],
  33. stdout=subprocess.PIPE,
  34. stderr=subprocess.STDOUT
  35. )
  36. def tearDown(self):
  37. # TERM all processes in my group
  38. os.killpg(os.getpgid(self.server.pid), 15)
  39. SEARXROBOTLAYER = SearxRobotLayer()
  40. class SearxTestCase(TestCase):
  41. layer = SearxTestLayer