-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_prodder.py
73 lines (48 loc) · 1.68 KB
/
test_prodder.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
import pytest
from prodder import ProdderEvents, Prodder, EmptyTaskList, gen_fake_header
@pytest.fixture
def test_event():
return 1
@pytest.fixture
def empty_prodder():
"""Returns a default prodder instance with empty task list"""
return Prodder([])
@pytest.fixture
def prodder():
tasks = ['http://blak.la/{}'.format(i) for i in range(100)]
prodder = Prodder(tasks)
return prodder
@pytest.fixture
def default_prodder_events():
"""Returns a prodder event system with no registered events"""
return ProdderEvents()
@pytest.fixture
def prodder_events():
prodder_events = ProdderEvents()
prodder_events.on("test", test_event)
return prodder_events
def test_default_params(empty_prodder):
assert empty_prodder.tasks == []
assert empty_prodder.lifespan == 60
assert empty_prodder.high == 100
assert empty_prodder.rpm == (60 / 100)
def test_set_tasks(prodder):
tasks = ['http://blak.la/{}'.format(i) for i in range(100)]
assert prodder.tasks == tasks
def test_set_headers():
header = gen_fake_header()
prodder = Prodder([], header=header)
assert prodder.header == header
def test_set_lifespan():
lifespan = 60
prodder = Prodder([], lifespan=lifespan)
assert prodder.dd == (prodder.start + lifespan)
def test_prod_on_empty_prodder(empty_prodder):
with pytest.raises(EmptyTaskList):
empty_prodder.prod()
def test_prodder_events(default_prodder_events):
assert default_prodder_events.eventListeners == {}
def test_add_event(prodder_events):
assert prodder_events.eventListeners == {"test": [test_event]}
def test_trigger_event(prodder_events):
assert prodder_events.trigger("test") == 1