def test_layout_html_on_parent_first() -> None: p = Plot(x_range=Range1d(), y_range=Range1d()) with silenced(MISSING_RENDERERS): layout = row(p) bie.get_layout_html(layout) with silenced(MISSING_RENDERERS): bie.get_layout_html(p, height=100, width=100)
def test_get_screenshot_as_png(webdriver: WebDriver, dimensions: Tuple[int, int]) -> None: width, height = dimensions border = 5 layout = Plot(x_range=Range1d(), y_range=Range1d(), height=width, width=height, min_border=border, hidpi=False, toolbar_location=None, outline_line_color=None, background_fill_color="#00ff00", border_fill_color="#00ff00") with silenced(MISSING_RENDERERS): png = bie.get_screenshot_as_png(layout, driver=webdriver) # a WxHpx image of white pixels assert png.size == (width, height) data = png.tobytes() assert len(data) == 4 * width * height assert data == b"\x00\xff\x00\xff" * width * height
def test_get_svgs_with_svg_present(webdriver) -> None: def fix_ids(svg): svg = re.sub(r'id="\w{12}"', 'id="X"', svg) svg = re.sub(r'url\(#\w{12}\)', 'url(#X)', svg) return svg layout = Plot(x_range=Range1d(), y_range=Range1d(), plot_height=20, plot_width=20, toolbar_location=None, outline_line_color=None, border_fill_color=None, background_fill_color="red", output_backend="svg") with silenced(MISSING_RENDERERS): svg0 = fix_ids(bie.get_svgs(layout, driver=webdriver)[0]) svg1 = fix_ids(bie.get_svgs(layout, driver=webdriver)[0]) svg2 = ( '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ' 'width="20" height="20" style="width: 20px; height: 20px;">' '<defs/>' '<g transform="scale(1,1) translate(0.5,0.5)">' '<rect fill="red" stroke="none" x="5" y="5" width="10" height="10"/>' '<g/>' '</g>' '</svg>') assert svg0 == svg2 assert svg1 == svg2
def test_get_screenshot_as_png_with_unicode_unminified(webdriver) -> None: p = figure(title="유니 코드 지원을위한 작은 테스트") with silenced(MISSING_RENDERERS): png = bie.get_screenshot_as_png(p, driver=webdriver, resources=Resources(mode="inline", minified=False)) assert len(png.tobytes()) > 0
def test_get_svgs_with_svg_present(webdriver: WebDriver) -> None: plot = lambda color: Plot( x_range=Range1d(), y_range=Range1d(), height=20, width=20, toolbar_location=None, outline_line_color=None, border_fill_color=None, background_fill_color=color, output_backend="svg", ) layout = row([plot("red"), plot("blue")]) with silenced(MISSING_RENDERERS): svgs0 = bie.get_svgs(layout, driver=webdriver) svgs1 = bie.get_svgs(layout, driver=webdriver) svgs2 = [ '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="20" height="20">' '<defs/>' '<path fill="rgb(255,0,0)" stroke="none" paint-order="stroke" d="M 5.5 5.5 L 15.5 5.5 L 15.5 15.5 L 5.5 15.5 L 5.5 5.5" fill-opacity="1"/>' '</svg>', '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="20" height="20">' '<defs/>' '<path fill="rgb(0,0,255)" stroke="none" paint-order="stroke" d="M 5.5 5.5 L 15.5 5.5 L 15.5 15.5 L 5.5 15.5 L 5.5 5.5" fill-opacity="1"/>' '</svg>', ] assert svgs0 == svgs2 assert svgs1 == svgs2
def test_get_svgs_no_svg_present() -> None: layout = Plot(x_range=Range1d(), y_range=Range1d(), plot_height=20, plot_width=20, toolbar_location=None) with silenced(MISSING_RENDERERS): svgs = bie.get_svgs(layout) assert svgs == []
def test_get_layout_html_resets_plot_dims() -> None: initial_height, initial_width = 200, 250 layout = Plot(x_range=Range1d(), y_range=Range1d(), plot_height=initial_height, plot_width=initial_width) with silenced(MISSING_RENDERERS): bie.get_layout_html(layout, height=100, width=100) assert layout.plot_height == initial_height assert layout.plot_width == initial_width
def test_get_svg_no_svg_present() -> None: layout = Plot(x_range=Range1d(), y_range=Range1d(), plot_height=20, plot_width=20, toolbar_location=None) with silenced(MISSING_RENDERERS): svgs = bie.get_svg(layout) assert svgs == [ '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="20" height="20">' '<defs/>' '<image width="20" height="20" preserveAspectRatio="none" xlink:href="' 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAbElEQVQ4T2P8//+/AwMDAwhTBTD+//+/gYGBoZ4' 'qpjEwMIwaCAnJN2/eMPz69YtgsLKxsTGIiIigqMMahs+ePWOQkpIiaCA2daMGQoJtNAxxJp+BSzbE5hRmZuYL4uLiBsheGC1tCJYHBBUAAA7h' 'kkaBfwzpAAAAAElFTkSuQmCC"/>' '</svg>', ]
def test_get_svg_no_svg_present(webdriver: WebDriver) -> None: layout = Plot( x_range=Range1d(), y_range=Range1d(), height=20, width=20, toolbar_location=None, outline_line_color=None, border_fill_color=None, background_fill_color="red", output_backend="canvas", ) with silenced(MISSING_RENDERERS): svgs = bie.get_svg(layout, driver=webdriver) def output(data: str) -> List[str]: return [ '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="20" height="20">' '<defs/>' f'<image width="20" height="20" preserveAspectRatio="none" href="data:image/png;base64,{data}"/>' '</svg>' ] chrome_data = ( "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IArs4c6QAAAFNJ" "REFUOE9jZKAyYKSyeQyjBkJC9D8DgwMDBBMCBxgZGA4gK8Iahv8ZGBoYGBjqCZnGwMDQ" "yAhRCwejBsIjZTQMcSaggUs21M0pROQQnEpGYPEFALJrIRXAq4rZAAAAAElFTkSuQmCC") firefox_data = ( "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAUUlEQVQ4T2NkoDJgpLJ5D" "KMGQkL0PwODA5ACYULgADDMDiArwhqGQAMbgIrqCZkGlG8EGgBSCwejBsIjZTQMcSaggUs" "21M0pROQQnEpGYPEFALJrIRV3ULevAAAAAElFTkSuQmCC") if webdriver.name == "chrome": assert svgs == output(chrome_data) else: assert svgs == output(firefox_data)
def test_get_svg_no_svg_present(webdriver: WebDriver) -> None: layout = Plot( x_range=Range1d(), y_range=Range1d(), height=20, width=20, toolbar_location=None, outline_line_color=None, border_fill_color=None, background_fill_color="red", output_backend="canvas", ) with silenced(MISSING_RENDERERS): svgs = bie.get_svg(layout, driver=webdriver) def output(data: str) -> List[str]: return [ '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="20" height="20">' '<defs/>' f'<image width="20" height="20" preserveAspectRatio="none" href="data:image/png;base64,{data}"/>' '</svg>' ] chrome_data = ( "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IArs4c6QAAAFNJ" "REFUOE9jZKAyYKSyeQyjBkJC9D8DgwMDBBMCBxgZGA4gK8Iahv8ZGBoYGBjqCZnGwMDQ" "yAhRCwejBsIjZTQMcSaggUs21M0pROQQnEpGYPEFALJrIRXAq4rZAAAAAElFTkSuQmCC") firefox_data = ( "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAMUlEQVQ4jWNgGAVDA/xnY" "HD4z8DQQAR2INbAhv8MDP+JwA2jBo4aOJQMpG5OGQUkAQCAKdw3str/WgAAAABJRU5ErkJggg==" ) name = webdriver.name assert name == "chrome" and svgs == output( chrome_data) or name == "firefox" and svgs == output(firefox_data)