1
- import os
2
- import random
1
+ # -*- coding: utf-8 -*-
3
2
import struct
4
3
import unittest2
5
4
import kafka .util
6
5
import kafka .common
7
6
7
+
8
8
class UtilTest (unittest2 .TestCase ):
9
9
@unittest2 .skip ("Unwritten" )
10
10
def test_relative_unpack (self ):
@@ -16,6 +16,14 @@ def test_write_int_string(self):
16
16
'\x00 \x00 \x00 \x0b some string'
17
17
)
18
18
19
+ def test_write_int_string__unicode (self ):
20
+ with self .assertRaises (TypeError ) as cm :
21
+ kafka .util .write_int_string (u'unicode' )
22
+ #: :type: TypeError
23
+ te = cm .exception
24
+ self .assertIn ('unicode' , te .message )
25
+ self .assertIn ('to be str' , te .message )
26
+
19
27
def test_write_int_string__empty (self ):
20
28
self .assertEqual (
21
29
kafka .util .write_int_string ('' ),
@@ -43,6 +51,14 @@ def test_write_short_string(self):
43
51
'\x00 \x0b some string'
44
52
)
45
53
54
+ def test_write_short_string__unicode (self ):
55
+ with self .assertRaises (TypeError ) as cm :
56
+ kafka .util .write_short_string (u'hello' )
57
+ #: :type: TypeError
58
+ te = cm .exception
59
+ self .assertIn ('unicode' , te .message )
60
+ self .assertIn ('to be str' , te .message )
61
+
46
62
def test_write_short_string__empty (self ):
47
63
self .assertEqual (
48
64
kafka .util .write_short_string ('' ),
@@ -64,21 +80,20 @@ def test_read_short_string(self):
64
80
self .assertEqual (kafka .util .read_short_string ('\x00 \x00 ' , 0 ), ('' , 2 ))
65
81
self .assertEqual (kafka .util .read_short_string ('\x00 \x0b some string' , 0 ), ('some string' , 13 ))
66
82
67
- def test_read_int_string__insufficient_data (self ):
83
+ def test_read_int_string__insufficient_data2 (self ):
68
84
with self .assertRaises (kafka .common .BufferUnderflowError ):
69
85
kafka .util .read_int_string ('\x00 \x02 1' , 0 )
70
86
71
- def test_relative_unpack (self ):
87
+ def test_relative_unpack2 (self ):
72
88
self .assertEqual (
73
89
kafka .util .relative_unpack ('>hh' , '\x00 \x01 \x00 \x00 \x02 ' , 0 ),
74
90
((1 , 0 ), 4 )
75
91
)
76
92
77
- def test_relative_unpack (self ):
93
+ def test_relative_unpack3 (self ):
78
94
with self .assertRaises (kafka .common .BufferUnderflowError ):
79
95
kafka .util .relative_unpack ('>hh' , '\x00 ' , 0 )
80
96
81
-
82
97
def test_group_by_topic_and_partition (self ):
83
98
t = kafka .common .TopicAndPartition
84
99
@@ -91,12 +106,12 @@ def test_group_by_topic_and_partition(self):
91
106
]
92
107
93
108
self .assertEqual (kafka .util .group_by_topic_and_partition (l ), {
94
- "a" : {
95
- 1 : t ("a" , 1 ),
96
- 2 : t ("a" , 2 ),
97
- 3 : t ("a" , 3 ),
109
+ "a" : {
110
+ 1 : t ("a" , 1 ),
111
+ 2 : t ("a" , 2 ),
112
+ 3 : t ("a" , 3 ),
98
113
},
99
- "b" : {
100
- 3 : t ("b" , 3 ),
114
+ "b" : {
115
+ 3 : t ("b" , 3 ),
101
116
}
102
117
})
0 commit comments