-
Notifications
You must be signed in to change notification settings - Fork 217
Expand file tree
/
Copy pathtest_helper_csv.py
More file actions
40 lines (25 loc) · 1.16 KB
/
test_helper_csv.py
File metadata and controls
40 lines (25 loc) · 1.16 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
# coding: utf-8
from decouple import Csv
def test_csv():
csv = Csv()
assert ['127.0.0.1', '.localhost', '.herokuapp.com'] == \
csv('127.0.0.1, .localhost, .herokuapp.com')
csv = Csv(int)
assert [1, 2, 3, 4, 5] == csv('1,2,3,4,5')
csv = Csv(post_process=tuple)
assert ('HTTP_X_FORWARDED_PROTO', 'https') == \
csv('HTTP_X_FORWARDED_PROTO, https')
csv = Csv(cast=lambda s: s.upper(), delimiter='\t', strip=' %*')
assert ['VIRTUAL_ENV', 'IMPORTANT STUFF', 'TRAILING SPACES'] == \
csv('%virtual_env%\t *important stuff*\t trailing spaces ')
def test_csv_quoted_parse():
csv = Csv()
assert ['foo', 'bar, baz', 'qux'] == csv(""" foo ,'bar, baz', 'qux'""")
assert ['foo', 'bar, baz', 'qux'] == csv(''' foo ,"bar, baz", "qux"''')
assert ['foo', "'bar, baz'", "'qux"] == csv(''' foo ,"'bar, baz'", "'qux"''')
assert ['foo', '"bar, baz"', '"qux'] == csv(""" foo ,'"bar, baz"', '"qux'""")
def test_csv_backslash():
csv = Csv()
raw = r'first,^https://\w+\.example\.com$,third'
assert ['first', '^https://\\w+\\.example\\.com$', 'third'] == \
csv(raw), "Csv helper removed backslashes."