A Python parser for MediaWiki wikicode https://mwparserfromhell.readthedocs.io/
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

test_string_mixin.py 4.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright (C) 2012-2013 Ben Kurtovic <ben.kurtovic@verizon.net>
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a copy
  6. # of this software and associated documentation files (the "Software"), to deal
  7. # in the Software without restriction, including without limitation the rights
  8. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. # copies of the Software, and to permit persons to whom the Software is
  10. # furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. # SOFTWARE.
  22. from __future__ import unicode_literals
  23. import unittest
  24. from mwparserfromhell.compat import py3k, str
  25. from mwparserfromhell.string_mixin import StringMixIn
  26. class _FakeString(StringMixIn):
  27. def __init__(self, data):
  28. self._data = data
  29. def __unicode__(self):
  30. return self._data
  31. class TestStringMixIn(unittest.TestCase):
  32. """Test cases for the StringMixIn class."""
  33. def test_docs(self):
  34. """make sure the various functions of StringMixIn have docstrings"""
  35. methods = [
  36. "capitalize", "center", "count", "encode", "endswith",
  37. "expandtabs", "find", "format", "index", "isalnum", "isalpha",
  38. "isdecimal", "isdigit", "islower", "isnumeric", "isspace",
  39. "istitle", "isupper", "join", "ljust", "lstrip", "partition",
  40. "replace", "rfind", "rindex", "rjust", "rpartition", "rsplit",
  41. "rstrip", "split", "splitlines", "startswith", "strip", "swapcase",
  42. "title", "translate", "upper", "zfill"]
  43. if not py3k:
  44. methods.append("decode")
  45. for meth in methods:
  46. expected = getattr(str, meth).__doc__
  47. actual = getattr(StringMixIn, meth).__doc__
  48. self.assertEquals(expected, actual)
  49. def test_types(self):
  50. """make sure StringMixIns convert to different types correctly"""
  51. pass
  52. def test_comparisons(self):
  53. """make sure comparison operators work"""
  54. str1 = _FakeString("this is a fake string")
  55. str2 = _FakeString("this is a fake string")
  56. str3 = _FakeString("fake string, this is")
  57. str4 = "this is a fake string"
  58. str5 = "fake string, this is"
  59. self.assertFalse(str1 > str2)
  60. self.assertTrue(str1 >= str2)
  61. self.assertTrue(str1 == str2)
  62. self.assertFalse(str1 != str2)
  63. self.assertFalse(str1 < str2)
  64. self.assertTrue(str1 <= str2)
  65. self.assertTrue(str1 > str3)
  66. self.assertTrue(str1 >= str3)
  67. self.assertFalse(str1 == str3)
  68. self.assertTrue(str1 != str3)
  69. self.assertFalse(str1 < str3)
  70. self.assertFalse(str1 <= str3)
  71. self.assertFalse(str1 > str4)
  72. self.assertTrue(str1 >= str4)
  73. self.assertTrue(str1 == str4)
  74. self.assertFalse(str1 != str4)
  75. self.assertFalse(str1 < str4)
  76. self.assertTrue(str1 <= str4)
  77. self.assertTrue(str1 > str5)
  78. self.assertTrue(str1 >= str5)
  79. self.assertFalse(str1 == str5)
  80. self.assertTrue(str1 != str5)
  81. self.assertFalse(str1 < str5)
  82. self.assertFalse(str1 <= str5)
  83. def test_operators(self):
  84. """make sure string addition and multiplication work"""
  85. pass
  86. def test_other_magics(self):
  87. """test other magically implemented features, like len() and iter()"""
  88. pass
  89. def test_other_methods(self):
  90. """test the remaining non-magic methods of StringMixIn"""
  91. pass
  92. if __name__ == "__main__":
  93. unittest.main(verbosity=2)