#!/usr/bin/env python # coding=utf-8 from __future__ import unicode_literals import json import pandas as pd import numpy as np from pyecharts import Bar TITLE = "柱状图数据堆叠示例" def create_a_bar(title): attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"] v1 = [5, 20, 36, 10, 75, 90] v2 = [10, 25, 8, 60, 20, 80] bar = Bar(title) bar.add("商家A", attr, v1, is_stack=True) bar.add("商家B", attr, v2, is_stack=True) return bar def test_embed_option(): bar = create_a_bar(TITLE) html = bar.render_embed() json_encoded_title = json.dumps(TITLE) assert json_encoded_title in html assert "" not in html assert "" not in html def test_notebook_render(): bar = create_a_bar(TITLE) html = bar._repr_html_() json_encoded_title = json.dumps(TITLE) assert json_encoded_title in html assert "require.config" in html assert "function(ec)" in html def test_notebook_dom(): bar = create_a_bar(TITLE) html = bar._render_notebook_dom_() assert bar._chart_id in html assert str(bar._width) in html assert str(bar._height) in html assert "