Beispiel #1
0
 def test_stanza(self):
     """Construct rio stanza in memory"""
     s = Stanza(number='42', name="fred")
     self.assertTrue('number' in s)
     self.assertFalse('color' in s)
     self.assertFalse('42' in s)
     self.assertEqual(list(s.iter_pairs()), [('name', 'fred'),
                                             ('number', '42')])
     self.assertEqual(s.get('number'), '42')
     self.assertEqual(s.get('name'), 'fred')
Beispiel #2
0
 def test_rio_unicode(self):
     uni_data = u'\N{KATAKANA LETTER O}'
     s = Stanza(foo=uni_data)
     self.assertEqual(s.get('foo'), uni_data)
     raw_lines = s.to_lines()
     self.assertEqual(raw_lines,
                      [b'foo: ' + uni_data.encode('utf-8') + b'\n'])
     new_s = read_stanza(raw_lines)
     self.assertEqual(new_s.get('foo'), uni_data)
Beispiel #3
0
 def test_rio_surrogateescape(self):
     raw_bytes = b'\xcb'
     self.assertRaises(UnicodeDecodeError, raw_bytes.decode, 'utf-8')
     try:
         uni_data = raw_bytes.decode('utf-8', 'surrogateescape')
     except LookupError:
         self.skipTest('surrogateescape is not available on Python < 3')
     s = Stanza(foo=uni_data)
     self.assertEqual(s.get('foo'), uni_data)
     raw_lines = s.to_lines()
     self.assertEqual(raw_lines,
                      [b'foo: ' + uni_data.encode('utf-8', 'surrogateescape') + b'\n'])
     new_s = read_stanza(raw_lines)
     self.assertEqual(new_s.get('foo'), uni_data)