test_python_twisted.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from tests.package.test_python import TestPythonBase
  2. TEST_SCRIPT = """
  3. from twisted.internet import protocol, reactor, endpoints
  4. class F(protocol.Factory):
  5. pass
  6. endpoints.serverFromString(reactor, "tcp:1234").listen(F())
  7. reactor.run()
  8. """
  9. class TestPythonTwisted(TestPythonBase):
  10. def import_test(self):
  11. cmd = "printf '{}' > test.py".format(TEST_SCRIPT)
  12. _, exit_code = self.emulator.run(cmd)
  13. self.assertEqual(exit_code, 0)
  14. cmd = "netstat -ltn 2>/dev/null | grep 0.0.0.0:1234"
  15. _, exit_code = self.emulator.run(cmd)
  16. self.assertEqual(exit_code, 1)
  17. cmd = self.interpreter + " test.py &"
  18. # give some time to setup the server
  19. cmd += "sleep 30"
  20. _, exit_code = self.emulator.run(cmd, timeout=35)
  21. self.assertEqual(exit_code, 0)
  22. cmd = "netstat -ltn 2>/dev/null | grep 0.0.0.0:1234"
  23. _, exit_code = self.emulator.run(cmd)
  24. self.assertEqual(exit_code, 0)
  25. class TestPythonPy2Twisted(TestPythonTwisted):
  26. config = TestPythonBase.config + \
  27. """
  28. BR2_PACKAGE_PYTHON=y
  29. BR2_PACKAGE_PYTHON_TWISTED=y
  30. """
  31. def test_run(self):
  32. self.login()
  33. self.import_test()
  34. class TestPythonPy3Twisted(TestPythonTwisted):
  35. config = TestPythonBase.config + \
  36. """
  37. BR2_PACKAGE_PYTHON3=y
  38. BR2_PACKAGE_PYTHON_TWISTED=y
  39. """
  40. def test_run(self):
  41. self.login()
  42. self.import_test()