test_pollingfile.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. Tests for L{twisted.internet._pollingfile}.
  5. """
  6. from twisted.python.runtime import platform
  7. from twisted.trial.unittest import TestCase
  8. if platform.isWindows():
  9. from twisted.internet import _pollingfile
  10. else:
  11. _pollingfile = None
  12. class PollableWritePipeTests(TestCase):
  13. """
  14. Tests for L{_pollingfile._PollableWritePipe}.
  15. """
  16. def test_writeUnicode(self):
  17. """
  18. L{_pollingfile._PollableWritePipe.write} raises a C{TypeError} if an
  19. attempt is made to append unicode data to the output buffer.
  20. """
  21. p = _pollingfile._PollableWritePipe(1, lambda: None)
  22. self.assertRaises(TypeError, p.write, u"test")
  23. def test_writeSequenceUnicode(self):
  24. """
  25. L{_pollingfile._PollableWritePipe.writeSequence} raises a C{TypeError}
  26. if unicode data is part of the data sequence to be appended to the
  27. output buffer.
  28. """
  29. p = _pollingfile._PollableWritePipe(1, lambda: None)
  30. self.assertRaises(TypeError, p.writeSequence, [u"test"])
  31. self.assertRaises(TypeError, p.writeSequence, (u"test", ))
  32. if _pollingfile is None:
  33. PollableWritePipeTests.skip = "Test will run only on Windows."