comparison sat/test/test_plugin_misc_text_syntaxes.py @ 4037:524856bd7b19

massive refactoring to switch from camelCase to snake_case: historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a pre-PEP8 code, to use the same coding style as in Twisted. However, snake_case is more readable and it's better to follow PEP8 best practices, so it has been decided to move on full snake_case. Because Libervia has a huge codebase, this ended with a ugly mix of camelCase and snake_case. To fix that, this patch does a big refactoring by renaming every function and method (including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case. This is a massive change, and may result in some bugs.
author Goffi <goffi@goffi.org>
date Sat, 08 Apr 2023 13:54:42 +0200
parents be6d91572633
children
comparison
equal deleted inserted replaced
4036:c4464d7ae97b 4037:524856bd7b19
76 <a href="evil-site">spam spam SPAM!</a> 76 <a href="evil-site">spam spam SPAM!</a>
77 <img src="evil!"> 77 <img src="evil!">
78 </img></body> 78 </img></body>
79 </div>""" 79 </div>"""
80 80
81 d = self.text_syntaxes.cleanXHTML(self.EVIL_HTML1) 81 d = self.text_syntaxes.clean_xhtml(self.EVIL_HTML1)
82 d.addCallback(self.assertEqualXML, expected, ignore_blank=True) 82 d.addCallback(self.assert_equal_xml, expected, ignore_blank=True)
83 return d 83 return d
84 84
85 def test_styles_sanitise(self): 85 def test_styles_sanitise(self):
86 expected = """<p style="color: blue">test <strong>retest</strong><br/><span style="color: #cf2828; font-size: 3px; color: red; color: red !important; font-size: 100px !important; font-size: 100%; font-size: 100px; font-size: 100; font-size: 100 %; color: rgba(0, 0, 0, 0.1); color: rgb(35,79,255); background-color: no-repeat"> toto </span></p>""" 86 expected = """<p style="color: blue">test <strong>retest</strong><br/><span style="color: #cf2828; font-size: 3px; color: red; color: red !important; font-size: 100px !important; font-size: 100%; font-size: 100px; font-size: 100; font-size: 100 %; color: rgba(0, 0, 0, 0.1); color: rgb(35,79,255); background-color: no-repeat"> toto </span></p>"""
87 87
88 d = self.text_syntaxes.cleanXHTML(self.EVIL_HTML2) 88 d = self.text_syntaxes.clean_xhtml(self.EVIL_HTML2)
89 d.addCallback(self.assertEqualXML, expected) 89 d.addCallback(self.assert_equal_xml, expected)
90 return d 90 return d
91 91
92 def test_html2text(self): 92 def test_html2text(self):
93 """Check that html2text is not inserting \n in the middle of that link. 93 """Check that html2text is not inserting \n in the middle of that link.
94 By default lines are truncated after the 79th characters.""" 94 By default lines are truncated after the 79th characters."""
103 except plugin_misc_text_syntaxes.UnknownSyntax: 103 except plugin_misc_text_syntaxes.UnknownSyntax:
104 raise SkipTest("Markdown syntax is not available.") 104 raise SkipTest("Markdown syntax is not available.")
105 d.addCallback(self.assertEqual, expected) 105 d.addCallback(self.assertEqual, expected)
106 return d 106 return d
107 107
108 def test_removeXHTMLMarkups(self): 108 def test_remove_xhtml_markups(self):
109 expected = """ a link another link a paragraph secret EVIL! of EVIL! Password: annoying EVIL! spam spam SPAM! """ 109 expected = """ a link another link a paragraph secret EVIL! of EVIL! Password: annoying EVIL! spam spam SPAM! """
110 result = self.text_syntaxes._removeMarkups(self.EVIL_HTML1) 110 result = self.text_syntaxes._remove_markups(self.EVIL_HTML1)
111 self.assertEqual(re.sub(r"\s+", " ", result).rstrip(), expected.rstrip()) 111 self.assertEqual(re.sub(r"\s+", " ", result).rstrip(), expected.rstrip())
112 112
113 expected = """test retest toto""" 113 expected = """test retest toto"""
114 result = self.text_syntaxes._removeMarkups(self.EVIL_HTML2) 114 result = self.text_syntaxes._remove_markups(self.EVIL_HTML2)
115 self.assertEqual(re.sub(r"\s+", " ", result).rstrip(), expected.rstrip()) 115 self.assertEqual(re.sub(r"\s+", " ", result).rstrip(), expected.rstrip())