diff options
| author | Stefan Behnel <stefan_ml@behnel.de> | 2020-06-14 11:02:54 +0200 |
|---|---|---|
| committer | Stefan Behnel <stefan_ml@behnel.de> | 2020-06-14 11:02:54 +0200 |
| commit | 6b7e5ecb1faf28df62984c66f356c1b8b768c4d1 (patch) | |
| tree | 951eabbc436b6efd42bad27ebda0e1223416aa77 /src/lxml | |
| parent | dd2d80a416e0aa5e177a723bcd571acf83a4c06a (diff) | |
| download | python-lxml-6b7e5ecb1faf28df62984c66f356c1b8b768c4d1.tar.gz | |
Extend C14N2 tests to cover comment handling and "strip_text" together.
Diffstat (limited to 'src/lxml')
| -rw-r--r-- | src/lxml/tests/test_etree.py | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/src/lxml/tests/test_etree.py b/src/lxml/tests/test_etree.py index 105c59b8..9cf70604 100644 --- a/src/lxml/tests/test_etree.py +++ b/src/lxml/tests/test_etree.py @@ -4933,22 +4933,27 @@ class ETreeC14NTestCase(HelperTestCase): s) def test_c14n2_with_comments(self): - tree = self.parse(_bytes('<!--hi--><a><!--ho--><b/></a><!--hu-->')) - f = BytesIO() - tree.write(f, method='c14n2') - s = f.getvalue() - self.assertEqual(_bytes('<!--hi-->\n<a><!--ho--><b></b></a>\n<!--hu-->'), - s) - f = BytesIO() - tree.write(f, method='c14n2', with_comments=True) - s = f.getvalue() - self.assertEqual(_bytes('<!--hi-->\n<a><!--ho--><b></b></a>\n<!--hu-->'), - s) - f = BytesIO() - tree.write(f, method='c14n2', with_comments=False) - s = f.getvalue() - self.assertEqual(_bytes('<a><b></b></a>'), - s) + tree = self.parse(b'<!--hi--> <a> <!-- ho --> <b/> </a> <!-- hu -->') + self.assertEqual( + b'<!--hi-->\n<a> <!-- ho --> <b></b> </a>\n<!-- hu -->', + etree.tostring(tree, method='c14n2')) + + self.assertEqual( + b'<!--hi-->\n<a> <!-- ho --> <b></b> </a>\n<!-- hu -->', + etree.tostring(tree, method='c14n2', with_comments=True)) + + self.assertEqual( + b'<a> <b></b> </a>', + etree.tostring(tree, method='c14n2', with_comments=False)) + + def test_c14n2_with_comments_strip_text(self): + tree = self.parse(b'<!--hi--> <a> <!-- ho --> <b/> </a> <!-- hu -->') + self.assertEqual( + b'<!--hi-->\n<a><!-- ho --><b></b></a>\n<!-- hu -->', + etree.tostring(tree, method='c14n2', with_comments=True, strip_text=True)) + self.assertEqual( + b'<a><b></b></a>', + etree.tostring(tree, method='c14n2', with_comments=False, strip_text=True)) def test_c14n_tostring_with_comments(self): tree = self.parse(_bytes('<!--hi--><a><!--ho--><b/></a><!--hu-->')) |
