test_cursesmon.py 2.4 KB

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