test_scripts.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. Tests for the command-line interfaces to conch.
  5. """
  6. from twisted.python.reflect import requireModule
  7. if requireModule('pyasn1'):
  8. pyasn1Skip = None
  9. else:
  10. pyasn1Skip = "Cannot run without PyASN1"
  11. if requireModule('cryptography'):
  12. cryptoSkip = None
  13. else:
  14. cryptoSkip = "can't run w/o cryptography"
  15. if requireModule('tty'):
  16. ttySkip = None
  17. else:
  18. ttySkip = "can't run w/o tty"
  19. try:
  20. import Tkinter
  21. except ImportError:
  22. tkskip = "can't run w/o Tkinter"
  23. else:
  24. try:
  25. Tkinter.Tk().destroy()
  26. except Tkinter.TclError as e:
  27. tkskip = "Can't test Tkinter: " + str(e)
  28. else:
  29. tkskip = None
  30. from twisted.trial.unittest import TestCase
  31. from twisted.scripts.test.test_scripts import ScriptTestsMixin
  32. from twisted.python.test.test_shellcomp import ZshScriptTestMixin
  33. class ScriptTests(TestCase, ScriptTestsMixin):
  34. """
  35. Tests for the Conch scripts.
  36. """
  37. skip = pyasn1Skip or cryptoSkip
  38. def test_conch(self):
  39. self.scriptTest("conch/conch")
  40. test_conch.skip = ttySkip or skip
  41. def test_cftp(self):
  42. self.scriptTest("conch/cftp")
  43. test_cftp.skip = ttySkip or skip
  44. def test_ckeygen(self):
  45. self.scriptTest("conch/ckeygen")
  46. def test_tkconch(self):
  47. self.scriptTest("conch/tkconch")
  48. test_tkconch.skip = tkskip or skip
  49. class ZshIntegrationTests(TestCase, ZshScriptTestMixin):
  50. """
  51. Test that zsh completion functions are generated without error
  52. """
  53. generateFor = [('conch', 'twisted.conch.scripts.conch.ClientOptions'),
  54. ('cftp', 'twisted.conch.scripts.cftp.ClientOptions'),
  55. ('ckeygen', 'twisted.conch.scripts.ckeygen.GeneralOptions'),
  56. ('tkconch', 'twisted.conch.scripts.tkconch.GeneralOptions'),
  57. ]