File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ import io
2+ import tempfile
3+
4+ from crate .client .http import super_len
5+
6+
7+ def test_super_len_all ():
8+ assert super_len ([1 , 2 ]) == 2
9+ assert super_len ("abc" ) == 3
10+ assert super_len ((1 , 2 , 3 )) == 3
11+
12+ class len_obj :
13+ def __init__ (self , len ):
14+ self .len = len
15+
16+ assert super_len (len_obj (5 )) == 5
17+
18+ data = b"somedata"
19+ with tempfile .TemporaryFile () as f :
20+ f .write (data )
21+ f .flush ()
22+ assert super_len (f ) == len (data )
23+
24+ class bad_fileno :
25+ def fileno (self ):
26+ raise io .UnsupportedOperation
27+
28+ assert super_len (bad_fileno ()) is None
29+
30+ class bad_fileno_with_getvalue :
31+ def fileno (self ):
32+ raise io .UnsupportedOperation
33+
34+ def getvalue (self ):
35+ return b"abcde"
36+
37+ assert super_len (bad_fileno_with_getvalue ()) == 5
38+
39+ buf = io .BytesIO (b"123456" )
40+ assert super_len (buf ) == 6
41+
42+ class getvalue_obj :
43+ def getvalue (self ):
44+ return "abcdef"
45+
46+ assert super_len (getvalue_obj ()) == 6
47+
48+ class Empty :
49+ pass
50+ assert super_len (Empty ()) is None
You can’t perform that action at this time.
0 commit comments