forked from gorenje/office_weather
-
Notifications
You must be signed in to change notification settings - Fork 1
/
GraphCollector_test.py
59 lines (41 loc) · 1.81 KB
/
GraphCollector_test.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
# -*- coding: utf-8 -*-
from GraphCollector import GraphCollector, IMAGE_FILE_FORMAT
from HystereseNotifier_test import dummy_data, dummy_extractor, dummy_extractor2
from pathlib import Path
from shutil import copyfileobj
TEST_DATA_COUNT = 10
TEST_IMAGE_DIRECTORY = Path("test/images/GraphCollector/")
def fake_config():
return {
"plot_title": "Test plot",
"data_count": TEST_DATA_COUNT,
}
class FakeReporter:
def __init__(self):
self.fake_plot_titles = []
TEST_IMAGE_DIRECTORY.mkdir(parents=True, exist_ok=True)
def send_image_by_handle(self, image_file, title):
self.fake_plot_titles.append(title)
image_output_path = TEST_IMAGE_DIRECTORY / Path("{0}.{1}".format(title, IMAGE_FILE_FORMAT))
with open(str(image_output_path), "wb") as output_file:
copyfileobj(image_file, output_file)
class describe_GraphCollector:
def setup_collector(self):
reporter = FakeReporter()
config = fake_config()
collector = GraphCollector(reporter, [dummy_extractor, dummy_extractor2], config)
return reporter, collector
def it_does_not_generate_plots_on_insufficient_data(self):
reporter, collector = self.setup_collector()
for i in range(TEST_DATA_COUNT - 1):
collector.notify(dummy_data(0))
assert reporter.fake_plot_titles == []
def it_generates_plots_on_sufficient_data(self):
reporter, collector = self.setup_collector()
for i in range(10 * TEST_DATA_COUNT + 2):
collector.notify(dummy_data(1))
assert reporter.fake_plot_titles[0] == "Test plot"
assert len(reporter.fake_plot_titles) == 10
for i in range(TEST_DATA_COUNT - 2):
collector.notify(dummy_data(0.5 * i))
assert len(reporter.fake_plot_titles) == 11