def get_table_dimensions(self, table): """Return table dimensions, as (rows, columns). :param table: table to inspect """ self.requires_table(table) notebook_print(text=table.dimensions) return table.dimensions
def get_table_column(self, table, column, as_list=False): """Get all column values from table. :param table: table to read :param column: column to read :param as_list: return list instead of dictionary """ self.requires_table(table) col = table.get_column(column, as_list=as_list) notebook_print(text=col) return col
def get_table_row(self, table, index, as_list=False): """Get a single row from table. :param table: table to read :param row: row to read :param as_list: return list instead of dictionary """ self.requires_table(table) row = table.get_row(index, as_list=as_list) notebook_print(text=row) return row
def _write_html_to_pdf(self, html, output_path, create_dirs, exists_ok): if create_dirs: Path(output_path).resolve().parent.mkdir(parents=True, exist_ok=True) if not exists_ok and Path(output_path).exists(): raise FileExistsError(output_path) notebook_print(link=str(output_path)) self.add_pages(1) self.write_html(html) pdf_content = self.output(dest="S").encode("latin-1") with open(output_path, "wb") as outfile: outfile.write(pdf_content) self.__init__()
def get_work_item_variable(self, name, default=None): """Return a single variable value from the work item, or default value if defined and key does not exist. If key does not exist and default is not defined, raises `KeyError`. :param key: Name of variable :param default: Default value if key does not exist """ variables = self.get_work_item_variables() value = variables.get(name, default) if value is None: raise KeyError(f"Undefined variable: {name}") notebook_print(text=f"**{name}** = **{value}**") return value
def test_notebook_print(obj, result): funcname = "test_notebook_print" out = notebook.notebook_print(**obj) if result: assert out == f"**KW** {funcname}: {result}" else: assert out is None
def template_html_to_pdf(self, template: str = None, filename: str = None, variables: dict = None) -> None: """Use HTML template file to generate PDF file. :param template: filepath to HTML template :param filename: filepath where to save PDF document :param variables: dictionary of variables to fill into template, defaults to {} """ required_param([template, filename], "template_html_to_pdf") variables = variables or {} with open(template, "r") as templatefile: html = templatefile.read() for key, value in variables.items(): html = html.replace("{{" + key + "}}", str(value)) target_path = self.output_directory / filename notebook_print(link=str(target_path)) self._write_html_to_pdf(html, target_path)
def get_work_item_variable(self, name, default=UNDEFINED): """Return a single variable value from the work item, or default value if defined and key does not exist. If key does not exist and default is not defined, raises `KeyError`. Example: .. code-block:: robotframework ${username}= Get work item variable username default=guest :param key: Name of variable :param default: Default value if key does not exist """ variables = self.get_work_item_variables() value = variables.get(name, default) if value is UNDEFINED: raise KeyError(f"Undefined variable: {name}") notebook_print(text=f"**{name}** = **{value}**") return value
def html_to_pdf( self, content: str = None, filename: str = None, variables: dict = None, ) -> None: """Use HTML content to generate PDF file. :param content: HTML content :param filename: filepath where to save PDF document :param variables: dictionary of variables to fill into template, defaults to {} """ required_param([content, filename], "html_to_pdf") variables = variables or {} html = content.encode("utf-8").decode("latin-1") for key, value in variables.items(): html = html.replace("{{" + key + "}}", str(value)) target_path = self.output_directory / filename notebook_print(link=str(target_path)) self._write_html_to_pdf(html, target_path)
def test_notebook_print_with_ipython(ipython_mock): out = notebook.notebook_print(text="my test") assert out is None