# coding=utf8"""Test cases for rendering in jupyter notebook"""from __future__ import unicode_literalsimport jsonfrom pyecharts import Bar, Line, Pie, Page, onlinefrom pyecharts import enable_nteract, configureimport pyecharts.constants as constantsfrom pyecharts.conf import CURRENT_CONFIGfrom test.constants import CLOTHES, WEEKTITLE = "柱状图数据堆叠示例"def create_a_bar(title):v1 = [5, 20, 36, 10, 75, 90]v2 = [10, 25, 8, 60, 20, 80]bar = Bar(title)bar.add("商家A", CLOTHES, v1, is_stack=True)bar.add("商家B", CLOTHES, v2, is_stack=True)return bardef test_single_chart():bar = create_a_bar(TITLE)html = bar._repr_html_()json_encoded_title = json.dumps(TITLE)assert json_encoded_title in htmlassert "require.config" in htmlassert "function(echarts)" in htmlassert "nbextensions/echarts" in htmlassert "width:800px" in htmlassert "height:400px" in htmlassert "<div" in htmlassert "myChart" in htmlassert bar.chart_id in htmldef test_page():page = Page()line = Line("折线图示例")line.chart_id = "id_my_cell_line"line.add("最高气温",WEEK,[11, 11, 15, 13, 12, 13, 10],mark_point=["max", "min"],mark_line=["average"],)line.add("最低气温",WEEK,[1, -2, 2, 5, 3, 2, 0],mark_point=["max", "min"],mark_line=["average"],)# piev1 = [11, 12, 13, 10, 10, 10]pie = Pie("饼图-圆环图示例", title_pos="center", width="600px")pie.add("",CLOTHES,v1,radius=[40, 75],label_text_color=None,is_label_show=True,legend_orient="vertical",legend_pos="left",)page.add([line, pie, create_a_bar(TITLE)])# Start render and testhtml = page._repr_html_()# Test base html structureassert html.count("<script>") == html.count("</script>") == 2assert html.count("<div") == html.count("</div>") == 3assert html.count("require.config") == html.count("function(echarts)") == 1# Test some chart attributesjson_encoded_title = json.dumps(TITLE)assert json_encoded_title in htmlassert "nbextensions/echarts" in html # default jshostassert html.count("height:400px") == 3assert html.count("width:600px") == 1assert html.count("width:800px") == 2assert html.count("id_my_cell_line") == 6def test_online_feature():online()bar = create_a_bar(TITLE)html = bar._repr_html_()expected_jshost = "https://pyecharts.github.io/jupyter-echarts/echarts"assert expected_jshost in htmlCURRENT_CONFIG.hosted_on_github = Falsedef test_online_with_custom_jshost():online(host="https://my-site.com/js")bar = create_a_bar(TITLE)html = bar._repr_html_()expected_jshost = "https://my-site.com/js"assert expected_jshost in htmlCURRENT_CONFIG.jshost = Nonedef test_nteract_feature():enable_nteract()bar = create_a_bar(TITLE)html = bar._repr_html_()assert "https://pyecharts.github.io/assets/js/echarts.min.js" in htmlassert "require" not in html# restore configurationconfigure(output_image=constants.DEFAULT_HTML)CURRENT_CONFIG.jshost = None
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。