blob: f4c758e7602554f2861aa77ba0ec7b0f023aba23 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#!/usr/bin/env python
"""Unit tests for M2Crypto.Rand.
Copyright (C) 2006 Open Source Applications Foundation (OSAF).
All Rights Reserved.
"""
from M2Crypto import six
from tests import unittest
class UtilTestCase(unittest.TestCase):
def test_py3bytes(self):
self.assertIsInstance(six.ensure_binary('test'), six.binary_type)
def test_py3str(self):
self.assertIsInstance(six.ensure_text('test'), six.text_type)
def test_py3bytes_str(self):
self.assertIsInstance(six.ensure_binary(u'test'), six.binary_type)
def test_py3str_str(self):
self.assertIsInstance(six.ensure_text(u'test'), six.string_types)
def test_py3bytes_bytes(self):
self.assertIsInstance(six.ensure_binary(b'test'), six.binary_type)
def test_py3str_bytes(self):
self.assertIsInstance(six.ensure_text(b'test'), six.text_type)
def test_py3bytes_None(self):
with self.assertRaises(TypeError):
six.ensure_binary(None)
def test_py3str_None(self):
with self.assertRaises(TypeError):
six.ensure_text(None)
def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(UtilTestCase))
return suite
if __name__ == '__main__':
unittest.TextTestRunner().run(suite())
|