/tests/test_utils.py

https://gitlab.com/mcepl/did · Python · 132 lines · 74 code · 37 blank · 21 comment · 0 complexity · 9f908f2debf8be85c3d77744c58c6c1b MD5 · raw file

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Author: "Chris Ward" <cward@redhat.com>
  4. from __future__ import unicode_literals, absolute_import
  5. def test_utils_import():
  6. # simple test that import works
  7. from did import utils
  8. assert utils
  9. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  10. # Constants
  11. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  12. def test_email_re():
  13. ''' Confirm regex works as we would expect for extracting
  14. name, login and email from standard email strings'''
  15. from did.utils import EMAIL_REGEXP
  16. # good
  17. x = '"Chris Ward" <cward@redhat.com>'
  18. groups = EMAIL_REGEXP.search(x).groups()
  19. assert len(groups) == 2
  20. assert groups[0] == 'Chris Ward'
  21. assert groups[1] == 'cward@redhat.com'
  22. x = 'cward@redhat.com'
  23. groups = EMAIL_REGEXP.search(x).groups()
  24. assert len(groups) == 2
  25. assert groups[0] is None
  26. assert groups[1] == 'cward@redhat.com'
  27. # bad
  28. x = 'cward'
  29. groups = EMAIL_REGEXP.search(x)
  30. assert groups is None
  31. # ugly
  32. x = '"" <>'
  33. groups = EMAIL_REGEXP.search(x)
  34. assert groups is None
  35. def test_log():
  36. from did.utils import log
  37. assert log
  38. log.name == 'did'
  39. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  40. # Utils
  41. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  42. def test_header():
  43. from did.utils import header
  44. assert header
  45. def test_shorted():
  46. from did.utils import shorted
  47. assert shorted
  48. def test_item():
  49. from did.utils import item
  50. assert item
  51. def test_pluralize():
  52. from did.utils import pluralize
  53. assert pluralize
  54. assert pluralize("word") == "words"
  55. assert pluralize("bounty") == "bounties"
  56. assert pluralize("mass") == "masses"
  57. def test_listed():
  58. from did.utils import listed
  59. assert listed
  60. assert listed(range(1)) == "0"
  61. assert listed(range(2)) == "0 and 1"
  62. assert listed(range(3), quote='"') == '"0", "1" and "2"'
  63. assert listed(range(4), max=3) == "0, 1, 2 and 1 more"
  64. assert listed(range(5), 'number', max=3) == "0, 1, 2 and 2 more numbers"
  65. assert listed(range(6), 'category') == "6 categories"
  66. assert listed(7, "leaf", "leaves") == "7 leaves"
  67. assert listed([], "item", max=0) == "0 items"
  68. def test_ascii():
  69. from did.utils import ascii
  70. assert ascii
  71. assert ascii("ěščřžýáíé") == "escrzyaie"
  72. assert ascii(0) == "0"
  73. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  74. # Logging
  75. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  76. def test_eprint():
  77. from did.utils import eprint
  78. assert eprint
  79. def test_info():
  80. from did.utils import info
  81. assert info
  82. info("something")
  83. info("no-new-line", newline=False)
  84. def test_Logging():
  85. from did.utils import Logging
  86. assert Logging
  87. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  88. # Coloring
  89. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  90. def test_Coloring():
  91. from did.utils import Coloring
  92. assert Coloring
  93. def test_color():
  94. from did.utils import color
  95. assert color