SF.net SVN: docutils:[9679 ] trunk/docutils/test/test _nodes.py
milde--- via Docutils-checkins <[email protected]>
| Newsgroups | gmane.text.docutils.cvs |
|---|---|
| Message-ID | <[email protected]> |
Revision: 9679
http://sourceforge.net/p/docutils/code/9679
Author: milde
Date: 2024-05-04 08:58:00 +0000 (Sat, 04 May 2024)
Log Message:
-----------
"nodes" unit tests update.
Merge `nodes.Text` tests for str and unicode (leftover from Py2 times).
Test string-related methods with non-ASCII letter.
Test correct handling of escaping:
Access the raw (null-escaped) text with `str(<instance>)`
and unescaped text with `<instance>.astext()`.
Test `whitespace_normalize_name()`
Modified Paths:
--------------
trunk/docutils/test/test_nodes.py
Modified: trunk/docutils/test/test_nodes.py
===================================================================
--- trunk/docutils/test/test_nodes.py 2024-05-03 20:31:31 UTC (rev 9678)
+++ trunk/docutils/test/test_nodes.py 2024-05-04 08:58:00 UTC (rev 9679)
@@ -24,8 +24,7 @@
class TextTests(unittest.TestCase):
def setUp(self):
- self.text = nodes.Text('Line 1.\nLine 2.')
- self.unicode_text = nodes.Text('Möhren')
+ self.text = nodes.Text('Line 1.\n\x00rad två.')
self.longtext = nodes.Text('Mary had a little lamb whose '
'fleece was white as snow and '
'everwhere that Mary went the '
@@ -32,26 +31,19 @@
'lamb was sure to go.')
def test_repr(self):
- self.assertEqual(repr(self.text), r"<#text: 'Line 1.\nLine 2.'>")
+ self.assertEqual(repr(self.text), r"<#text: 'Line 1.\n\x00rad två.'>")
self.assertEqual(self.text.shortrepr(),
- r"<#text: 'Line 1.\nLine 2.'>")
- self.assertEqual(repr(self.unicode_text), "<#text: 'Möhren'>")
+ r"<#text: 'Line 1.\n\x00rad två.'>")
def test_str(self):
- self.assertEqual(str(self.text), 'Line 1.\nLine 2.')
+ self.assertEqual(str(self.text), 'Line 1.\n\x00rad två.')
- def test_unicode(self):
- self.assertEqual(str(self.unicode_text), 'Möhren')
- self.assertEqual(str(self.unicode_text), 'M\xf6hren')
-
def test_astext(self):
- self.assertTrue(isinstance(self.text.astext(), str))
- self.assertEqual(self.text.astext(), 'Line 1.\nLine 2.')
- self.assertEqual(self.unicode_text.astext(), 'Möhren')
+ self.assertEqual(self.text.astext(), 'Line 1.\nrad två.')
def test_pformat(self):
self.assertTrue(isinstance(self.text.pformat(), str))
- self.assertEqual(self.text.pformat(), 'Line 1.\nLine 2.\n')
+ self.assertEqual(self.text.pformat(), 'Line 1.\nrad två.\n')
def test_strip(self):
text = nodes.Text(' was noch ')
@@ -73,8 +65,7 @@
def test_comparison(self):
# Text nodes are compared by value
- self.assertEqual(self.text, 'Line 1.\nLine 2.')
- self.assertEqual(self.text, nodes.Text('Line 1.\nLine 2.'))
+ self.assertEqual(self.text, nodes.Text('Line 1.\n\x00rad två.'))
def test_Text_rawsource_deprection_warning(self):
with self.assertWarnsRegex(DeprecationWarning,
@@ -348,10 +339,6 @@
self.assertEqual(child4['ids'], ['child4'])
self.assertEqual(len(parent), 5)
- def test_unicode(self):
- node = nodes.Element('Möhren', nodes.Text('Möhren'))
- self.assertEqual(str(node), '<Element>Möhren</Element>')
-
def test_set_class_deprecation_warning(self):
node = nodes.Element('test node')
with self.assertWarns(DeprecationWarning):
@@ -778,15 +765,24 @@
class MiscFunctionTests(unittest.TestCase):
- names = [('a', 'a'), ('A', 'a'), ('A a A', 'a a a'),
- ('A a A a', 'a a a a'),
- (' AaA\n\r\naAa\tAaA\t\t', 'aaa aaa aaa')]
+ names = [ # sample, whitespace_normalized, fully_normalized
+ ('a', 'a', 'a'),
+ ('A', 'A', 'a'),
+ ('A a A ', 'A a A', 'a a a'),
+ ('A a A a', 'A a A a', 'a a a a'),
+ (' AaA\n\r\naAa\tAaA\t\t', 'AaA aAa AaA', 'aaa aaa aaa')
+ ]
- def test_normalize_name(self):
- for input, output in self.names:
- normed = nodes.fully_normalize_name(input)
- self.assertEqual(normed, output)
+ def test_whitespace_normalize_name(self):
+ for (sample, ws, full) in self.names:
+ result = nodes.whitespace_normalize_name(sample)
+ self.assertEqual(result, ws)
+ def test_fully_normalize_name(self):
+ for (sample, ws, fully) in self.names:
+ result = nodes.fully_normalize_name(sample)
+ self.assertEqual(result, fully)
+
if __name__ == '__main__':
unittest.main()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
_______________________________________________
Docutils-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/docutils-checkins