def expect_message(expected):
    actual = "; ".join(messages)
    if expected not in actual:
        raise RuntimeError(
            "Wrong error message received: EXPECTED '{}', GOT '{}'".format(
                expected, actual))

    # make empty file so that opp_charttool doesn't complain
    fname = utils.get_image_export_filepath(chart.get_properties())
    with open(fname, 'wt') as f:
        pass
Exemple #2
0
    def export_image(self,
                     chart,
                     wd,
                     workspace,
                     format="svg",
                     target_folder=None,
                     filename=None,
                     width=None,
                     height=None,
                     dpi=96,
                     enforce=True,
                     extra_props=dict()):
        """
        Runs a chart script for image export. This method just calls `run_chart()`
        with extra properties that instruct the chart script to perform image export.
        (It is assumed that the chart script invokes `utils.export_image_if_needed()`
        or implements equivalent functionality).
        """
        props = dict()
        props.update(chart.properties)
        props.update(extra_props)

        props['export_image'] = "true"
        if format:
            props['image_export_format'] = str(format)
        if target_folder:
            props['image_export_folder'] = str(target_folder)
        if filename:
            props['image_export_filename'] = str(filename)
        if width:
            props['image_export_width'] = str(width)
        if height:
            props['image_export_height'] = str(height)
        if dpi:
            props['image_export_dpi'] = str(dpi)

        self.run_chart(chart, wd, workspace, extra_props=props, show=False)

        fname = utils.get_image_export_filepath(props)
        return self._check_file_created(fname, "image", enforce)
Exemple #3
0
    def export_image(self, chart, wd, workspace, format="svg", target_folder=None, filename=None, width=None, height=None, dpi=96, enforce=True, extra_props=dict()):
        """
        Runs a chart script for image export. This method just calls `run_chart()`
        with extra properties that instruct the chart script to perform image export.
        (It is assumed that the chart script invokes `utils.export_image_if_needed()`
        or implements equivalent functionality).
        """
        props = dict()
        props.update(chart.properties)
        props.update(extra_props)

        props['export_image'] = "true"
        if format:
            props['image_export_format'] = str(format)
        if target_folder:
            props['image_export_folder'] = str(target_folder)
        if filename:
            props['image_export_filename'] = str(filename)
        if width:
            props['image_export_width'] = str(width)
        if height:
            props['image_export_height'] = str(height)
        if dpi:
            props['image_export_dpi'] = str(dpi)

        # have to reload these modules, otherwise some charts are not entirely
        # reproducible, elements can be shifted around by about 1 pixel
        importlib.reload(mpl)
        importlib.reload(plt)
        mpl.use(utils._get_mpl_backend_for_image_format(str(format)))

        self.run_chart(chart, wd, workspace, extra_props=props, show=False)

        fname = utils.get_image_export_filepath(props)
        fname = os.path.join(wd, fname)
        return self._check_file_created(fname, "image", enforce)
Exemple #4
0
def create_blank_image_file():
    # make empty file so that opp_charttool doesn't complain
    fname = utils.get_image_export_filepath(chart.get_properties())
    with open(fname, 'wt') as f:
        pass