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

68 行
2.3 KiB

  1. # Copyright (C) 2012-2020 Ben Kurtovic <ben.kurtovic@gmail.com>
  2. #
  3. # Permission is hereby granted, free of charge, to any person obtaining a copy
  4. # of this software and associated documentation files (the "Software"), to deal
  5. # in the Software without restriction, including without limitation the rights
  6. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. # copies of the Software, and to permit persons to whom the Software is
  8. # furnished to do so, subject to the following conditions:
  9. #
  10. # The above copyright notice and this permission notice shall be included in
  11. # all copies or substantial portions of the Software.
  12. #
  13. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  19. # SOFTWARE.
  20. """
  21. Test cases for the Text node.
  22. """
  23. import pytest
  24. from mwparserfromhell.nodes import Text
  25. def test_str():
  26. """test Text.__str__()"""
  27. node = Text("foobar")
  28. assert "foobar" == str(node)
  29. node2 = Text("fóóbar")
  30. assert "fóóbar" == str(node2)
  31. def test_children():
  32. """test Text.__children__()"""
  33. node = Text("foobar")
  34. gen = node.__children__()
  35. with pytest.raises(StopIteration):
  36. next(gen)
  37. def test_strip():
  38. """test Text.__strip__()"""
  39. node = Text("foobar")
  40. assert node is node.__strip__()
  41. def test_showtree():
  42. """test Text.__showtree__()"""
  43. output = []
  44. node1 = Text("foobar")
  45. node2 = Text("fóóbar")
  46. node3 = Text("𐌲𐌿𐍄")
  47. node1.__showtree__(output.append, None, None)
  48. node2.__showtree__(output.append, None, None)
  49. node3.__showtree__(output.append, None, None)
  50. res = ["foobar", r"f\xf3\xf3bar", "\\U00010332\\U0001033f\\U00010344"]
  51. assert res == output
  52. def test_value():
  53. """test getter/setter for the value attribute"""
  54. node = Text("foobar")
  55. assert "foobar" == node.value
  56. assert isinstance(node.value, str)
  57. node.value = "héhéhé"
  58. assert "héhéhé" == node.value
  59. assert isinstance(node.value, str)