-
Notifications
You must be signed in to change notification settings - Fork 3
/
icb_test.py
executable file
·45 lines (34 loc) · 1.5 KB
/
icb_test.py
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
#!/usr/bin/python3
import unittest
import icb
class IcbConnWrappingTests(unittest.TestCase):
def setUp(self):
self._ORIG_read_config_file = icb.IcbConn.read_config_file
icb.IcbConn.read_config_file = lambda self: None
self.conn = icb.IcbConn()
def tearDown(self):
icb.IcbConn.read_config_file = self._ORIG_read_config_file
def test_wrap_and_encode_empty(self):
self.assertRaises(ValueError, self.conn._wrap_and_encode, '', 99)
def test_wrap_and_encode_bad_max(self):
self.assertRaises(ValueError, self.conn._wrap_and_encode, 'line', 9)
def test_wrap_and_encode_1line(self):
self.assertEqual(self.conn._wrap_and_encode('simple line', 99),
[b'simple line'])
def test_wrap_and_encode_2line(self):
text = 'simple line with enough words to wrap into two.'
lines = self.conn._wrap_and_encode(text, 30)
rejoined = b' '.join(lines)
self.assertEqual(text.encode('ascii'), rejoined)
self.assertEqual(len(lines), 2)
def test_wrap_and_encode_with_encoding_expansion(self):
text = '✪' * 200
self.conn.codec = 'utf8' # Force a multibyte character encoding.
lines = self.conn._wrap_and_encode(text, 70)
rejoined = b''.join(lines)
self.assertEqual(self.conn._encode(text), rejoined)
self.assertGreater(len(lines), 3)
for line in lines:
self.assertLessEqual(len(line), 70)
if __name__ == '__main__':
unittest.main()