test_utils_info.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import unittest
  2. from celery.utils import info
  3. RANDTEXT = """\
  4. The quick brown
  5. fox jumps
  6. over the
  7. lazy dog\
  8. """
  9. RANDTEXT_RES = """\
  10. The quick brown
  11. fox jumps
  12. over the
  13. lazy dog\
  14. """
  15. ROUTE = {"queue1": {
  16. "exchange": "exchange1",
  17. "exchange_type": "type1",
  18. "binding_key": "bind1"},
  19. "queue2": {
  20. "exchange": "exchange2",
  21. "exchange_type": "type2",
  22. "binding_key": "bind2"}}
  23. ROUTE_FORMAT = """
  24. . queue1 -> exchange:exchange1 (type1) binding:bind1
  25. . queue2 -> exchange:exchange2 (type2) binding:bind2
  26. """.strip()
  27. class TestInfo(unittest.TestCase):
  28. def test_humanize_seconds(self):
  29. t = ((4 * 60 * 60 * 24, "4 days"),
  30. (1 * 60 * 60 * 24, "1 day"),
  31. (4 * 60 * 60, "4 hours"),
  32. (1 * 60 * 60, "1 hour"),
  33. (4 * 60, "4 minutes"),
  34. (1 * 60, "1 minute"),
  35. (4, "4.00 seconds"),
  36. (1, "1.00 second"),
  37. (4.3567631221, "4.36 seconds"),
  38. (0, "now"))
  39. for seconds, human in t:
  40. self.assertEquals(info.humanize_seconds(seconds), human)
  41. self.assertEquals(info.humanize_seconds(4, prefix="about "),
  42. "about 4.00 seconds")
  43. def test_textindent(self):
  44. self.assertEquals(info.textindent(RANDTEXT, 4), RANDTEXT_RES)
  45. def test_format_routing_table(self):
  46. self.assertEquals(info.format_routing_table(ROUTE), ROUTE_FORMAT)
  47. def test_broker_info(self):
  48. info.format_broker_info()