-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_rita.py
91 lines (65 loc) · 2.37 KB
/
test_rita.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from datetime import time
from functools import partial
import pytest
import rita_heallis as rita
class MockOut:
"""Captures output."""
def __init__(self):
self.outputs = []
def __call__(self, resp):
self.outputs.append(resp)
def mock_input(responses):
"""Warning: be careful how many times you run this."""
r = iter(responses)
def inner():
return next(r)
return inner
def test_pause_for_help():
mout = MockOut()
resp = rita.pause_for_help(mock_input(['never']), 'help message', out=mout)
assert resp == 'never'
assert mout.outputs == []
def test_pause_for_help_got_help():
mout = MockOut()
resp = rita.pause_for_help(mock_input(['h', 'help', 'never']), 'help message', out=mout)
assert resp == 'never'
assert mout.outputs == ['help message', 'help message']
def test_help_requested():
# standard inputs
assert rita.help_requested("help") == True
assert rita.help_requested("h") == True
assert rita.help_requested("help!") == True
assert rita.help_requested("") == False
assert rita.help_requested("bob") == False
# booleans should all be false
assert rita.help_requested(True) == False
assert rita.help_requested(False) == False
# edge cases
with pytest.raises(TypeError):
rita.help_requested(None)
with pytest.raises(TypeError):
rita.help_requested(0)
with pytest.raises(TypeError):
rita.help_requested(4.5)
with pytest.raises(TypeError):
rita.help_requested([1, 2])
with pytest.raises(TypeError):
rita.help_requested({1: 2})
def test_parse_intervals():
assert rita.parse_intervals('never') == []
assert rita.parse_intervals('always') == [(9, 19)]
with pytest.raises(rita.RitaInputError):
rita.parse_intervals("1 2 3")
assert rita.parse_intervals("10 15") == [(10, 15)]
assert rita.parse_intervals("10 15 16 20") == [(10, 15), (16, 20)]
def test_parse_dates():
assert rita.parse_dates("None") == []
assert rita.parse_dates("All") == slice(None)
assert rita.parse_dates("1") == [1]
assert rita.parse_dates("1 22") == [1, 22]
assert rita.parse_dates("1-4 22") == [1, 2, 3, 4, 22]
with pytest.raises(ValueError):
rita.parse_dates("test")
def test_extract_dates():
assert rita.extract_dates("1-4") == [1, 2, 3, 4]
assert rita.extract_dates("1") == [1]