Debian Codegraph @

tests/test_models_report_plotgroup.py

raw symbols SCIP
1 import logging
2 from pprint import pformat
3
4 import pytest
5
6 from pbcommand.models.report import PlotGroup, Plot, PbReportError
7
8 log = logging.getLogger(__name__)
9
10
11 class TestPlotGroup:
12
13 def test_init(self):
14 """Test constructor with kwargs"""
15 plot = Plot('a_plot', 'path/to/image.png', caption="My Image")
16 p = PlotGroup('my_pg', plots=[plot])
17 assert p is not None
18
19 def test_plotgroup_null_id(self):
20 """Can't create an plotGroup without an id."""
21 def _test():
22 p = PlotGroup(None)
23
24 with pytest.raises(PbReportError):
25 _test()
26
27 def test_plotgroup_add_duplicate_plot(self):
28 """Can't add plots with duplicate ids."""
29 def _test():
30 pg = PlotGroup('foo')
31 pg.add_plot(Plot('id', 'i1'))
32 pg.add_plot(Plot('id', 'i2'))
33
34 with pytest.raises(PbReportError):
35 _test()
36
37 def test_to_dict(self):
38 """Test plotGroup to_dict function."""
39 a = PlotGroup('123', title='foo title', legend='foo legend',
40 thumbnail='foo thumbnail')
41 a.add_plot(Plot('id', 'i1', caption='a caption'))
42
43 d = a.to_dict()
44 log.debug(pformat(d))
45
46 assert '123' == d['id']
47 assert 'foo title' == d['title']
48 assert 'foo legend' == d['legend']
49 assert 'foo thumbnail' == d['thumbnail']
50 assert 1 == len(d['plots'])
51 log.info(a)
52 assert repr(a) is not None
53
54 def test_adding_incorrect_type(self):
55 """Validate type when adding Plots."""
56 def _test():
57 plots = ['Not a plot instance', 'Another bad plot.']
58 p = PlotGroup('my_plotgroup', plots=plots)
59
60 with pytest.raises(TypeError):
61 _test()