def test_get_chart(self, monkeypatch): def get_point(self, b): return b.value monkeypatch.setattr(GroupedBarChart, 'get_point', get_point) # benchmarks = PyQuery([ DotMap(group='getattr', schema='capnpy', type='int16', value=1), DotMap(group='getattr', schema='capnpy', type='text', value=2), DotMap(group='getattr', schema='instance', type='int16', value=3), DotMap(group='getattr', schema='instance', type='text', value=4), DotMap(group='other'), ]) charter = MyCharter(benchmarks) chart = charter.get_chart(timeline=False, benchmarks=benchmarks, title='My title', filter=lambda b: b.group == 'getattr', series=lambda b: b.schema, group=lambda b: b.type) # assert chart.title == 'My title' assert chart.x_labels == ['int16', 'text'] assert chart.raw_series == [([1, 2], { 'title': 'capnpy' }), ([3, 4], { 'title': 'instance' })]
def test_timeline_sorted(self, monkeypatch): def get_point(self, b): return {'value': b.value} monkeypatch.setattr(TimelineChart, 'get_point', get_point) def commit(rev): return DotMap(commit_info=DotMap(id=rev)) # benchmarks = PyQuery([ DotMap(info=commit('aaa'), schema='capnpy', value=1), DotMap(info=commit('bbb'), schema='capnpy', value=2), DotMap(info=commit('bbb'), schema='instance', value=2), DotMap(info=commit('ccc'), schema='instance', value=3), DotMap(info=commit('ddd'), schema='capnpy', value=4), DotMap(info=commit('ddd'), schema='instance', value=4), ]) charter = MyCharter(benchmarks) chart = charter.get_chart(timeline=True, benchmarks=benchmarks, title='My title', filter=lambda b: True, series=lambda b: b.schema, group=lambda b: None) # assert chart.title == 'My title' chart.raw_series.sort(key=lambda s: s[1]['title']) assert chart.raw_series == [ ([{ 'value': 1 }, { 'value': 2 }, None, { 'value': 4 }], { 'title': 'capnpy' }), ([None, { 'value': 2 }, { 'value': 3 }, { 'value': 4 }], { 'title': 'instance' }) ]
def test_run_directive_content(self): benchmarks = PyQuery([ DotMap(value=1), DotMap(value=2), ]) charter = MyCharter(benchmarks) charter.get_chart = fake_get_chart options = { 'filter': 'myfilter(b)', 'series': 'b+2', 'group': 'b+3', } content = ['def myfilter(x):' ' return x*6'] charts = charter.run_directive('My title', options, content) ch = charts[0] assert ch.filter(7) == 42
def test_run_directive_foreach(self): benchmarks = PyQuery([ DotMap(impl='CPython', value=1), DotMap(impl='CPython', value=2), DotMap(impl='PyPy', value=3), DotMap(impl='PyPy', value=4), ]) charter = MyCharter(benchmarks) charter.get_chart = fake_get_chart options = { 'foreach': 'b.impl', } charts = charter.run_directive('My title', options, []) ch1, ch2 = charts assert ch1.title == 'My title [CPython]' assert ch1.b_values == [1, 2] assert ch2.title == 'My title [PyPy]' assert ch2.b_values == [3, 4]
def test_run_directive_simple(self): benchmarks = PyQuery([ DotMap(value=1), DotMap(value=2), ]) charter = MyCharter(benchmarks) charter.get_chart = fake_get_chart options = { 'filter': 'b+1', 'series': 'b+2', 'group': 'b+3', } charts = charter.run_directive('My title', options, []) assert len(charts) == 1 chart = charts[0] assert not chart.timeline assert chart.title == 'My title' assert chart.b_values == [1, 2] assert chart.filter(0) == 1 assert chart.series(0) == 2 assert chart.group(0) == 3
def test_call(self): lower_list = PyQuery(['hello', 'world']) upper_list = lower_list.upper() assert upper_list == ['HELLO', 'WORLD']
def test___getattr__(self): points = PyQuery([Point(x, x * 2) for x in range(5)]) assert points.x == [0, 1, 2, 3, 4] with pytest.raises(AttributeError): points.i_dont_exist
def test_getattr_strict(self): points = PyQuery([Point(1, 2), 'hello', Point(3, 4)]) assert points.getattr('x') == [1, 3] with pytest.raises(AttributeError): points.getattr('x', strict=True)
def test_getattr(self): points = PyQuery([Point(x, x * 2) for x in range(5)]) assert points.getattr('x') == [0, 1, 2, 3, 4] assert points.getattr('y') == [0, 2, 4, 6, 8]
def test_filter(self): all = PyQuery(range(10)) subset = all.filter(lambda x: x < 4) assert subset == [0, 1, 2, 3] assert isinstance(subset, PyQuery)
def __init__(self, benchmarks=PyQuery()): self.all = benchmarks self.latest = benchmarks self.latest_warning = None