test_cursesmon.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from case import skip
  2. class MockWindow:
  3. def getmaxyx(self):
  4. return self.y, self.x
  5. @skip.unless_module('curses', import_errors=(ImportError, OSError))
  6. class test_CursesDisplay:
  7. def setup(self):
  8. from celery.events import cursesmon
  9. self.monitor = cursesmon.CursesMonitor(object(), app=self.app)
  10. self.win = MockWindow()
  11. self.monitor.win = self.win
  12. def test_format_row_with_default_widths(self):
  13. self.win.x, self.win.y = 91, 24
  14. row = self.monitor.format_row(
  15. '783da208-77d0-40ca-b3d6-37dd6dbb55d3',
  16. 'task.task.task.task.task.task.task.task.task.tas',
  17. 'workerworkerworkerworkerworkerworkerworkerworker',
  18. '21:13:20',
  19. 'SUCCESS')
  20. assert ('783da208-77d0-40ca-b3d6-37dd6dbb55d3 '
  21. 'workerworker... task.task.[.]tas 21:13:20 SUCCESS ' == row)
  22. def test_format_row_with_truncated_uuid(self):
  23. self.win.x, self.win.y = 80, 24
  24. row = self.monitor.format_row(
  25. '783da208-77d0-40ca-b3d6-37dd6dbb55d3',
  26. 'task.task.task.task.task.task.task.task.task.tas',
  27. 'workerworkerworkerworkerworkerworkerworkerworker',
  28. '21:13:20',
  29. 'SUCCESS')
  30. expected = ('783da208-77d0-40ca-b3d... workerworker... '
  31. 'task.task.[.]tas 21:13:20 SUCCESS ')
  32. assert row == expected
  33. def test_format_title_row(self):
  34. self.win.x, self.win.y = 80, 24
  35. row = self.monitor.format_row('UUID', 'TASK',
  36. 'WORKER', 'TIME', 'STATE')
  37. assert ('UUID WORKER '
  38. 'TASK TIME STATE ' == row)
  39. def test_format_row_for_wide_screen_with_short_uuid(self):
  40. self.win.x, self.win.y = 140, 24
  41. row = self.monitor.format_row(
  42. '783da208-77d0-40ca-b3d6-37dd6dbb55d3',
  43. 'task.task.task.task.task.task.task.task.task.tas',
  44. 'workerworkerworkerworkerworkerworkerworkerworker',
  45. '21:13:20',
  46. 'SUCCESS')
  47. assert len(row) == 136
  48. assert ('783da208-77d0-40ca-b3d6-37dd6dbb55d3 '
  49. 'workerworkerworkerworkerworkerworker... '
  50. 'task.task.task.task.task.task.task.[.]tas '
  51. '21:13:20 SUCCESS ' == row)