-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_report.py
53 lines (39 loc) · 1.58 KB
/
test_report.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
import os
from report import __version__, create_html, OrderedList
from report.create_report import _save_figure, insert_report_figure
def test_version():
assert __version__ == "0.1.0"
def test_create_html():
title = "Report Name"
sections = {"header": ["image.png"]}
html = create_html(title=title, sections=sections)
assert '<img src="image.png"' in html
class MockFig:
# use this so that the package doesnt require matplotlib
# dependency just for testing
def __init__(self, content: str = "This is a test."):
self.content = content
def savefig(self, path):
with open(path, "w") as f:
print(self.content, file=f)
def test_insert_figure(tmpdir):
fig = MockFig()
report_sections = {}
section_name = "Awesome Results Section"
filename = "test.txt"
insert_report_figure(
report_sections, fig, filename, section_name, output_dir=tmpdir
)
filepath_relative_to_report = os.path.join(section_name.replace(" ", "_"), filename)
assert report_sections == {section_name: [filepath_relative_to_report]}
def test__save_figure(tmpdir):
fig = MockFig()
output_dir = tmpdir
filepath_relative_to_report = "section_dir/test.txt"
_save_figure(fig, filepath_relative_to_report, output_dir)
with open(os.path.join(output_dir, filepath_relative_to_report), "r") as f:
saved_data = f.read()
assert saved_data.replace("\n", "") == fig.content
def test_OrderedList_repr():
result = str(OrderedList("item1", "item2"))
assert result == "<ol>\n<li>item1</li>\n<li>item2</li>\n</ol>"