/
test_helpers.py
69 lines (53 loc) · 1.69 KB
/
test_helpers.py
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
import praw
from psraw.base import limit_chunk, coerce_kwarg_types
from psraw.endpoints import ENDPOINTS, sort_type
test_config = {
'params': {
'foo': str,
'bar': int
},
'return_type': praw.models.Comment,
'url': '/foo/bar'
}
def test_limit_chunk_1():
"""limit_chunk returns an array as expected with two positive arguments"""
chunks = limit_chunk(333, 100)
assert chunks == [100, 100, 100, 33]
def test_limit_chunk_2():
"""limit_chunk raises a ValueError when given a limit_max < 1"""
try:
limit_chunk(100, 0)
assert False
except ValueError:
pass
def test_limit_chunk_3():
"""limit_chunk returns an empty list if limit is < 1"""
chunks = limit_chunk(-1, 100)
assert chunks == []
def test_coerce_kwarg_types_1():
"""coerce_kwarg_types raises a ValueError when passed an unspecified argument"""
try:
kwargs = {'foobar': 24}
coerced_kwargs = coerce_kwarg_types(kwargs, test_config['params'])
assert False
except ValueError:
pass
def test_coerce_kwarg_types_2():
"""coerce_kwarg_types converts parameter types"""
kwargs = {
'foo': 24,
'bar': 25
}
coerced_kwargs = coerce_kwarg_types(kwargs, test_config['params'])
assert isinstance(coerced_kwargs['foo'], str)
assert isinstance(coerced_kwargs['bar'], int)
def test_sort_type_1():
"""sort_type returns the value passed in if it is a valid direction"""
assert sort_type('asc') == 'asc'
def test_sort_type_2():
"""sort_type raises a ValueError if the value passed in is not a direction"""
try:
sort_type('foobar')
assert False
except ValueError:
pass