Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_main.py 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. Test that twisted scripts can be invoked as modules.
  5. """
  6. import sys
  7. from io import StringIO
  8. from twisted.internet import defer, reactor
  9. from twisted.test.test_process import Accumulator
  10. from twisted.trial.unittest import TestCase
  11. class MainTests(TestCase):
  12. """Test that twisted scripts can be invoked as modules."""
  13. def test_twisted(self):
  14. """Invoking python -m twisted should execute twist."""
  15. cmd = sys.executable
  16. p = Accumulator()
  17. d = p.endedDeferred = defer.Deferred()
  18. reactor.spawnProcess(p, cmd, [cmd, "-m", "twisted", "--help"], env=None)
  19. p.transport.closeStdin()
  20. # Fix up our sys args to match the command we issued
  21. from twisted import __main__
  22. self.patch(sys, "argv", [__main__.__file__, "--help"])
  23. def processEnded(ign):
  24. f = p.outF
  25. output = f.getvalue()
  26. self.assertTrue(
  27. b"-m twisted [options] plugin [plugin_options]" in output, output
  28. )
  29. return d.addCallback(processEnded)
  30. def test_trial(self):
  31. """Invoking python -m twisted.trial should execute trial."""
  32. cmd = sys.executable
  33. p = Accumulator()
  34. d = p.endedDeferred = defer.Deferred()
  35. reactor.spawnProcess(p, cmd, [cmd, "-m", "twisted.trial", "--help"], env=None)
  36. p.transport.closeStdin()
  37. # Fix up our sys args to match the command we issued
  38. from twisted.trial import __main__
  39. self.patch(sys, "argv", [__main__.__file__, "--help"])
  40. def processEnded(ign):
  41. f = p.outF
  42. output = f.getvalue()
  43. self.assertTrue(b"-j, --jobs= " in output, output)
  44. return d.addCallback(processEnded)
  45. def test_twisted_import(self):
  46. """Importing twisted.__main__ does not execute twist."""
  47. output = StringIO()
  48. monkey = self.patch(sys, "stdout", output)
  49. import twisted.__main__
  50. self.assertTrue(twisted.__main__) # Appease pyflakes
  51. monkey.restore()
  52. self.assertEqual(output.getvalue(), "")