A Python parser for MediaWiki wikicode https://mwparserfromhell.readthedocs.io/
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

70 linhas
2.6 KiB

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