test_ucslevel.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. # coding: utf-8
  2. """Unicode version level tests for wcwidth."""
  3. # std imports
  4. import warnings
  5. # 3rd party
  6. import pytest
  7. # local
  8. import wcwidth
  9. def test_latest():
  10. """wcwidth._wcmatch_version('latest') returns tail item."""
  11. # given,
  12. expected = wcwidth.list_versions()[-1]
  13. # exercise,
  14. result = wcwidth._wcmatch_version('latest')
  15. # verify.
  16. assert result == expected
  17. def test_exact_410_str():
  18. """wcwidth._wcmatch_version('4.1.0') returns equal value (str)."""
  19. # given,
  20. given = expected = '4.1.0'
  21. # exercise,
  22. result = wcwidth._wcmatch_version(given)
  23. # verify.
  24. assert result == expected
  25. def test_exact_410_unicode():
  26. """wcwidth._wcmatch_version(u'4.1.0') returns equal value (unicode)."""
  27. # given,
  28. given = expected = u'4.1.0'
  29. # exercise,
  30. result = wcwidth._wcmatch_version(given)
  31. # verify.
  32. assert result == expected
  33. def test_nearest_505_str():
  34. """wcwidth._wcmatch_version('5.0.5') returns nearest '5.0.0'. (str)"""
  35. # given
  36. given, expected = '5.0.5', '5.0.0'
  37. # exercise
  38. result = wcwidth._wcmatch_version(given)
  39. # verify.
  40. assert result == expected
  41. def test_nearest_505_unicode():
  42. """wcwidth._wcmatch_version(u'5.0.5') returns nearest u'5.0.0'. (unicode)"""
  43. # given
  44. given, expected = u'5.0.5', u'5.0.0'
  45. # exercise
  46. result = wcwidth._wcmatch_version(given)
  47. # verify.
  48. assert result == expected
  49. def test_nearest_lowint40_str():
  50. """wcwidth._wcmatch_version('4.0') returns nearest '4.1.0'."""
  51. # given
  52. given, expected = '4.0', '4.1.0'
  53. warnings.resetwarnings()
  54. wcwidth._wcmatch_version.cache_clear()
  55. # exercise
  56. with pytest.warns(UserWarning):
  57. # warns that given version is lower than any available
  58. result = wcwidth._wcmatch_version(given)
  59. # verify.
  60. assert result == expected
  61. def test_nearest_lowint40_unicode():
  62. """wcwidth._wcmatch_version(u'4.0') returns nearest u'4.1.0'."""
  63. # given
  64. given, expected = u'4.0', u'4.1.0'
  65. warnings.resetwarnings()
  66. wcwidth._wcmatch_version.cache_clear()
  67. # exercise
  68. with pytest.warns(UserWarning):
  69. # warns that given version is lower than any available
  70. result = wcwidth._wcmatch_version(given)
  71. # verify.
  72. assert result == expected
  73. def test_nearest_800_str():
  74. """wcwidth._wcmatch_version('8') returns nearest '8.0.0'."""
  75. # given
  76. given, expected = '8', '8.0.0'
  77. # exercise
  78. result = wcwidth._wcmatch_version(given)
  79. # verify.
  80. assert result == expected
  81. def test_nearest_800_unicode():
  82. """wcwidth._wcmatch_version(u'8') returns nearest u'8.0.0'."""
  83. # given
  84. given, expected = u'8', u'8.0.0'
  85. # exercise
  86. result = wcwidth._wcmatch_version(given)
  87. # verify.
  88. assert result == expected
  89. def test_nearest_999_str():
  90. """wcwidth._wcmatch_version('999.0') returns nearest (latest)."""
  91. # given
  92. given, expected = '999.0', wcwidth.list_versions()[-1]
  93. # exercise
  94. result = wcwidth._wcmatch_version(given)
  95. # verify.
  96. assert result == expected
  97. def test_nearest_999_unicode():
  98. """wcwidth._wcmatch_version(u'999.0') returns nearest (latest)."""
  99. # given
  100. given, expected = u'999.0', wcwidth.list_versions()[-1]
  101. # exercise
  102. result = wcwidth._wcmatch_version(given)
  103. # verify.
  104. assert result == expected
  105. def test_nonint_unicode():
  106. """wcwidth._wcmatch_version(u'x.y.z') returns latest (unicode)."""
  107. # given
  108. given, expected = u'x.y.z', wcwidth.list_versions()[-1]
  109. warnings.resetwarnings()
  110. wcwidth._wcmatch_version.cache_clear()
  111. # exercise
  112. with pytest.warns(UserWarning):
  113. # warns that given version is not valid
  114. result = wcwidth._wcmatch_version(given)
  115. # verify.
  116. assert result == expected
  117. def test_nonint_str():
  118. """wcwidth._wcmatch_version(u'x.y.z') returns latest (str)."""
  119. # given
  120. given, expected = 'x.y.z', wcwidth.list_versions()[-1]
  121. warnings.resetwarnings()
  122. wcwidth._wcmatch_version.cache_clear()
  123. # exercise
  124. with pytest.warns(UserWarning):
  125. # warns that given version is not valid
  126. result = wcwidth._wcmatch_version(given)
  127. # verify.
  128. assert result == expected