forked from allanlei/python-zipstream
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_pointerio.py
More file actions
80 lines (62 loc) · 2.23 KB
/
test_pointerio.py
File metadata and controls
80 lines (62 loc) · 2.23 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import unittest
import zipstream
class PointerIOTestCase(unittest.TestCase):
def test_init_no_args(self):
zipstream.PointerIO()
def test_init_mode(self):
try:
zipstream.PointerIO('wb')
except Exception as err:
self.fail(err)
for mode in ['w', 'r', 'rb', 'a', 'ab']:
self.assertRaises(Exception, zipstream.PointerIO, mode=mode)
for mode in ['w', 'wb''r', 'rb', 'a', 'ab']:
self.assertRaises(Exception, zipstream.PointerIO, mode=mode + '+')
def test_has_fileobj_attrs(self):
fileobj = zipstream.PointerIO()
self.assertTrue(hasattr(fileobj, 'write'))
self.assertTrue(hasattr(fileobj, 'close'))
self.assertTrue(hasattr(fileobj, 'tell'))
def test_write_bytes(self):
fileobj = zipstream.PointerIO()
data = b'Im a little tea pot'
try:
fileobj.write(data)
except Exception as err:
self.fail(err)
self.assertEqual(fileobj.tell(), 19)
def test_write_unicode(self):
fileobj = zipstream.PointerIO()
data = 'Im a little tea pot'
try:
fileobj.write(data)
except Exception as err:
self.fail(err)
self.assertEqual(fileobj.tell(), 19)
fileobj = zipstream.PointerIO()
data = '幋 儳鑤 寱懤擨 拻敁柧'
try:
fileobj.write(data)
except Exception as err:
self.fail(err)
self.assertEqual(fileobj.tell(), 30)
def test_write_non_string_type(self):
fileobj = zipstream.PointerIO()
data = None
self.assertRaises(TypeError, fileobj.write, data)
fileobj = zipstream.PointerIO()
data = []
self.assertRaises(TypeError, fileobj.write, data)
fileobj = zipstream.PointerIO()
data = tuple()
self.assertRaises(TypeError, fileobj.write, data)
fileobj = zipstream.PointerIO()
data = 1
self.assertRaises(TypeError, fileobj.write, data)
fileobj = zipstream.PointerIO()
data = 1.00
self.assertRaises(TypeError, fileobj.write, data)
if __name__ == '__main__':
unittest.main()