-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusingsix.py
More file actions
59 lines (40 loc) · 1.06 KB
/
usingsix.py
File metadata and controls
59 lines (40 loc) · 1.06 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
#!/usr/bin/env python
# coding=utf-8
"""common usage of the six library.
https://pythonhosted.org/six/
"""
import six
def test_string():
assert type(u"abc") is six.text_type
assert type(b"abc") is six.binary_type
assert type(six.u("abc")) is six.text_type
assert type(six.b("abc")) is six.binary_type
def test_stringio():
f = six.BytesIO()
f.write(b"abc\n")
assert f.getvalue() == b"abc\n"
f = six.StringIO()
f.write(u"abc\n")
assert f.getvalue() == u"abc\n"
def test_iteritem():
d = {
"a": 1,
"b": 2,
}
for k, v in six.iteritems(d):
print(k, v)
def test_range():
assert 2 in six.moves.range(3)
def test_pickle():
d = [1, 2, 3]
byte_str = six.moves.cPickle.dumps(d)
obj = six.moves.cPickle.loads(byte_str)
assert obj == d
def using_input():
r = six.moves.input("Install directory: ")
return r
def test_urlparse():
url = "http://www.example.com/foo?q=abc"
r = six.moves.urllib.parse.urlparse(url)
assert r.scheme == 'http'
assert r.path == '/foo'