Exemplo n.º 1
0
 def test_is_text(self):
     """
     Verifies what text means, basically that they can represent
     extended set of characters and can be encoded into "bytes"
     """
     binary = b''
     text = u''
     self.assertTrue(astring.is_text(text))
     self.assertFalse(astring.is_text(binary))
     self.assertTrue(hasattr(text, 'encode'))
     self.assertTrue(astring.is_bytes(text.encode()))
Exemplo n.º 2
0
 def test_is_text(self):
     """
     Verifies what text means, basically that they can represent
     extended set of characters and can be encoded into "bytes"
     """
     binary = b''
     text = u''
     self.assertTrue(astring.is_text(text))
     self.assertFalse(astring.is_text(binary))
     self.assertTrue(hasattr(text, 'encode'))
     self.assertTrue(astring.is_bytes(text.encode()))
Exemplo n.º 3
0
 def test_to_text(self):
     text_1 = astring.to_text(b'\xc3\xa1', 'utf-8')
     text_2 = astring.to_text(u'\u00e1', 'utf-8')
     self.assertTrue(astring.is_text(text_1))
     self.assertEqual(text_1, text_2)
     self.assertEqual(astring.to_text(Exception(u'\u00e1')), u"\xe1")
     # For tuple, dict and others astring.to_text is equivalent of str()
     # because on py3 it's unicode and on py2 it uses __repr__ (is encoded)
     self.assertEqual(astring.to_text({u'\xe1': 1}), str({u'\xe1': 1}))
Exemplo n.º 4
0
 def test_to_text(self):
     text_1 = astring.to_text(b'\xc3\xa1', 'utf-8')
     text_2 = astring.to_text(u'\u00e1', 'utf-8')
     self.assertTrue(astring.is_text(text_1))
     self.assertEqual(text_1, text_2)
     self.assertEqual(astring.to_text(Exception(u'\u00e1')),
                      u"\xe1")
     # For tuple, dict and others astring.to_text is equivalent of str()
     # because on py3 it's unicode and on py2 it uses __repr__ (is encoded)
     self.assertEqual(astring.to_text({u'\xe1': 1}), str({u'\xe1': 1}))
Exemplo n.º 5
0
 def test_is_bytes(self):
     """
     Verifies what bytes means, basically that they are the same
     thing across Python 2 and 3 and can be decoded into "text"
     """
     binary = b''
     text = u''
     self.assertTrue(astring.is_bytes(binary))
     self.assertFalse(astring.is_bytes(text))
     self.assertTrue(hasattr(binary, 'decode'))
     self.assertTrue(astring.is_text(binary.decode()))
     self.assertFalse(astring.is_bytes(str('')))
Exemplo n.º 6
0
 def test_is_bytes(self):
     """
     Verifies what bytes means, basically that they are the same
     thing across Python 2 and 3 and can be decoded into "text"
     """
     binary = b''
     text = u''
     self.assertTrue(astring.is_bytes(binary))
     self.assertFalse(astring.is_bytes(text))
     self.assertTrue(hasattr(binary, 'decode'))
     self.assertTrue(astring.is_text(binary.decode()))
     # on Python 2, each str member is also a single byte char
     if sys.version_info[0] < 3:
         self.assertTrue(astring.is_bytes(str('')))
     else:
         self.assertFalse(astring.is_bytes(str('')))
Exemplo n.º 7
0
 def test_is_bytes(self):
     """
     Verifies what bytes means, basically that they are the same
     thing across Python 2 and 3 and can be decoded into "text"
     """
     binary = b''
     text = u''
     self.assertTrue(astring.is_bytes(binary))
     self.assertFalse(astring.is_bytes(text))
     self.assertTrue(hasattr(binary, 'decode'))
     self.assertTrue(astring.is_text(binary.decode()))
     # on Python 2, each str member is also a single byte char
     if sys.version_info[0] < 3:
         self.assertTrue(astring.is_bytes(str('')))
     else:
         self.assertFalse(astring.is_bytes(str('')))
Exemplo n.º 8
0
 def test_to_text_decode_is_text(self):
     self.assertTrue(astring.is_text(astring.to_text(b'', 'ascii')))
     self.assertTrue(astring.is_text(astring.to_text('', 'ascii')))
     self.assertTrue(astring.is_text(astring.to_text(u'', 'ascii')))
Exemplo n.º 9
0
 def test_to_text_is_text(self):
     self.assertTrue(astring.is_text(astring.to_text(b'')))
     self.assertTrue(astring.is_text(astring.to_text('')))
     self.assertTrue(astring.is_text(astring.to_text(u'')))
Exemplo n.º 10
0
 def test_to_text_decode_is_text(self):
     self.assertTrue(astring.is_text(astring.to_text(b'', 'ascii')))
     self.assertTrue(astring.is_text(astring.to_text('', 'ascii')))
     self.assertTrue(astring.is_text(astring.to_text(u'', 'ascii')))
Exemplo n.º 11
0
 def test_to_text_is_text(self):
     self.assertTrue(astring.is_text(astring.to_text(b'')))
     self.assertTrue(astring.is_text(astring.to_text('')))
     self.assertTrue(astring.is_text(astring.to_text(u'')))
Exemplo n.º 12
0
 def test_to_text_decode_is_text(self):
     self.assertTrue(astring.is_text(astring.to_text(b"", "ascii")))
     self.assertTrue(astring.is_text(astring.to_text("", "ascii")))
     self.assertTrue(astring.is_text(astring.to_text("", "ascii")))
Exemplo n.º 13
0
 def test_to_text_is_text(self):
     self.assertTrue(astring.is_text(astring.to_text(b"")))
     self.assertTrue(astring.is_text(astring.to_text("")))
     self.assertTrue(astring.is_text(astring.to_text("")))
Exemplo n.º 14
0
 def test_to_text_decode_utf_8(self):
     text_1 = astring.to_text(b'\xc3\xa1', 'utf-8')
     text_2 = astring.to_text(u'\u00e1', 'utf-8')
     self.assertTrue(astring.is_text(text_1))
     self.assertTrue(astring.is_text(text_1))
     self.assertEqual(text_1, text_2)