test_window.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. """
  2. Tests for the insults windowing module, L{twisted.conch.insults.window}.
  3. """
  4. from twisted.trial.unittest import TestCase
  5. from twisted.conch.insults.window import TopWindow, ScrolledArea, TextOutput
  6. class TopWindowTests(TestCase):
  7. """
  8. Tests for L{TopWindow}, the root window container class.
  9. """
  10. def test_paintScheduling(self):
  11. """
  12. Verify that L{TopWindow.repaint} schedules an actual paint to occur
  13. using the scheduling object passed to its initializer.
  14. """
  15. paints = []
  16. scheduled = []
  17. root = TopWindow(lambda: paints.append(None), scheduled.append)
  18. # Nothing should have happened yet.
  19. self.assertEqual(paints, [])
  20. self.assertEqual(scheduled, [])
  21. # Cause a paint to be scheduled.
  22. root.repaint()
  23. self.assertEqual(paints, [])
  24. self.assertEqual(len(scheduled), 1)
  25. # Do another one to verify nothing else happens as long as the previous
  26. # one is still pending.
  27. root.repaint()
  28. self.assertEqual(paints, [])
  29. self.assertEqual(len(scheduled), 1)
  30. # Run the actual paint call.
  31. scheduled.pop()()
  32. self.assertEqual(len(paints), 1)
  33. self.assertEqual(scheduled, [])
  34. # Do one more to verify that now that the previous one is finished
  35. # future paints will succeed.
  36. root.repaint()
  37. self.assertEqual(len(paints), 1)
  38. self.assertEqual(len(scheduled), 1)
  39. class ScrolledAreaTests(TestCase):
  40. """
  41. Tests for L{ScrolledArea}, a widget which creates a viewport containing
  42. another widget and can reposition that viewport using scrollbars.
  43. """
  44. def test_parent(self):
  45. """
  46. The parent of the widget passed to L{ScrolledArea} is set to a new
  47. L{Viewport} created by the L{ScrolledArea} which itself has the
  48. L{ScrolledArea} instance as its parent.
  49. """
  50. widget = TextOutput()
  51. scrolled = ScrolledArea(widget)
  52. self.assertIs(widget.parent, scrolled._viewport)
  53. self.assertIs(scrolled._viewport.parent, scrolled)