def execute_robot( kernel: DisplayKernel, code: str, data: TestCaseString, listeners: list, silent: bool, ): # Build builder = TestSuiteBuilder() data.source = os.getcwd() # allow Library and Resource from CWD work suite = builder._build_suite(data) suite._name = "Jupyter" # Run display_id = str(uuid.uuid4()) if suite.tests: with TemporaryDirectory() as path: reply = run_robot_suite(kernel, suite, listeners, silent, display_id, path) else: last_code = getattr(kernel, "_last_code", "") if code == last_code: setattr(kernel, "_last_code", "") else: inject_ipywidgets(kernel, code, data, listeners, silent, display_id) setattr(kernel, "_last_code", code) reply = {"status": "ok", "execution_count": kernel.execution_count} return reply
def execute_ipywidget( kernel: DisplayKernel, data: TestCaseString, listeners: list, silent: bool, display_id: str, name, arguments, values, ): header = getattr(data.testcase_table, "name", "Tasks") or "Tasks" table = f"""\ *** {header} *** {name} {name} {' '.join([values[a[1]] for a in arguments])} """ data.testcase_table.tests.clear() data.populate(table) # Build builder = TestSuiteBuilder() data.source = os.getcwd() # allow Library and Resource from CWD work suite = builder._build_suite(data) suite._name = "Jupyter" with TemporaryDirectory() as path: run_robot_suite(kernel, suite, listeners, silent, display_id, path, widget=True)
def do_execute(self, code, silent, store_history=True, user_expressions=None, allow_stdin=False): # Support %%python module ModuleName cell magic match = re.match('^%%python module ([a-zA-Z_]+)', code) if match is not None: module = match.groups()[0] return self.do_execute_python( code[len('%%python module {0:s}'.format(module)):], module, silent, store_history, user_expressions, allow_stdin) # Populate data = TestCaseString() try: for historical in self.robot_history: data.populate(historical) data.testcase_table.tests.clear() data.populate(code) except Exception as e: if not silent: self.send_error({ 'ename': e.__class__.__name__, 'evalue': str(e), 'traceback': list(format_exc().splitlines()), }) return { 'status': 'error', 'ename': e.__class__.__name__, 'evalue': str(e), 'traceback': list(format_exc().splitlines()), } # Build builder = TestSuiteBuilder() suite = builder._build_suite(data) suite._name = 'Jupyter' # Run if suite.tests: reply = self.run_robot_suite(suite, silent) else: reply = { 'status': 'ok', 'execution_count': self.execution_count, } # Save history if reply['status'] == 'ok': self.robot_history.append(code) return reply
def build_suite(code: str, cell_history: Dict[str, str]): # Init data = TestCaseString() data.source = os.getcwd() # allow Library and Resource from CWD work # Populate history, but ignore tests for historical in cell_history.values(): data.populate(historical) data.testcase_table.tests.clear() # Populate current data.populate(code) # Wrap up builder = TestSuiteBuilder() suite = builder._build_suite(data) suite._name = "Jupyter" return suite