def run( diagram_id, src_dir, output_dir, ): file_path = "" diagram_prefix = f"{DIAGRAM_OUTPUT_PREFIX}-{diagram_id}-" for name in os.listdir(src_dir): if name.startswith(diagram_prefix) and name.endswith( DIAGRAM_CONFIG_OUTPUT_SUFFIX): file_path = os.path.join(src_dir, name) # if after all no files found raise an error if not file_path: raise BackendException("No diagram file found") diagram = dict() with open(file_path, "rt") as f: diagram_file_data = json.load(f) try: DiagramSchema().load(diagram_file_data) except ValidationError as e: message = json.dumps(e.messages, indent=4) raise BackendException( f"Invalid diagram schema in {file_path}\n\nErrors: \n{message}" ) from e diagram.update(**diagram_file_data) # if files have no diagrams data if not diagram: raise BackendException("No diagram found!") # Create outputs script_file_path = file_path.replace(DIAGRAM_CONFIG_OUTPUT_SUFFIX, DIAGRAM_SCRIPT_OUTPUT_SUFFIX) image_file_path = os.path.join( output_dir, os.path.basename(file_path).replace(DIAGRAM_CONFIG_OUTPUT_SUFFIX, DIAGRAM_IMAGE_OUTPUT_SUFFIX), ) text = create_script(diagram=diagram, temp_path=script_file_path, image_filename=image_file_path) if text is not None: with open(script_file_path, "w+t") as f: f.write(str(text)) exec(text) return text
def _get_source(self, source_name): """ Get a particular source """ source = None try: source = self._sources[source_name] except KeyError: raise BackendException(f"source {source_name} not found in engine") return source
def run(filenames=None, output=None, directory=None): filenames = filenames or [] # searching testcase files in given directory if no files provided if not filenames and directory: for name in os.listdir(directory): if name.endswith(TESTCASE_EXT): filenames.append(os.path.join(directory, name)) # if after all no files found raise an error if not filenames: raise BackendException("No testcase files found!") # merging casefiles cases = dict() for filename in filenames: if not filename.endswith(TESTCASE_EXT): raise BackendException( f"Invalid extension for {filename}. Must be {TESTCASE_EXT}" ) with open(filename, "rt") as f: testcase_file_data = json.load(f) for name, testcase in testcase_file_data.items(): try: TestcaseSchema().load(testcase) except ValidationError as e: message = json.dumps(e.messages, indent=4) raise BackendException( f'Invalid testcase schema in {filename}, testcase "{name}". \n\nErrors: \n{message}' ) from e cases.update(**testcase_file_data) # if files have no testcases data if not cases: raise BackendException("No testcases found!") text = testcases_template.render(cases) if output is not None: with open(output, "wt") as f: f.write(text) return "" return text
def run(FilePath, env={}): """ read the content of a given filepath and return it as the result """ content = "" try: with open(FilePath, "r") as file: content = file.read() except FileNotFoundError as e: raise BackendException(str(e)) return {"Properties": {"result": content}}
def run(testpaths=None, root_dir=None, pytest_args=None, silent=True): testpaths = testpaths or [] # Do not use pytest.main because it can't correctly work with the files changed in runtime if shutil.which("bash") is None: raise BackendException("Could not find bash installation") try: args = [ "pytest", "-vvs" if not silent else "", "--cache-clear", ] if root_dir is not None: args.append(f"--rootdir={root_dir}") if pytest_args is not None: args.append(pytest_args) args += [ *testpaths, ] cmd = " ".join(args) stdin = subprocess.PIPE stderr = subprocess.PIPE process = subprocess.Popen( [shutil.which("bash"), "-c", cmd], stdin=stdin, stderr=stderr, start_new_session=True, cwd=root_dir, ) process.wait() if process.returncode in [ec.OK, ec.NO_TESTS_COLLECTED]: return True if process.returncode == ec.TESTS_FAILED: raise Exception("Tests Failed") if process.returncode in [ ec.INTERNAL_ERROR, ec.USAGE_ERROR, ec.TESTS_FAILED ]: raise Exception(process.stderr) else: raise Exception("Unknown exit code: %s" % process.returncode) finally: process.kill()
def cookiecutter(template_package, output_dir, **kwargs): with tempfile.TemporaryDirectory() as template_dir: if importlib_resources.is_resource(template_package, "cookiecutter.json"): with importlib_resources.path( template_package, "cookiecutter.json" ) as path: extract_package_to_temp( template_package, template_dir, os.path.dirname(path), "" ) else: raise BackendException( f"Provided template package does not contain cookiecutter.json config: {template_package}" ) replace_parameters_values(kwargs, [[None, ""], [True, "yes"], [False, "no"]]) cookiecutter_main( template_dir, no_input=True, output_dir=output_dir, extra_context=kwargs )
def sources(self, source_name): try: del self._sources[source_name] except KeyError: raise BackendException(f"source {source_name} not found")
def parts(self, type): try: del self._parts[type] except KeyError: raise BackendException(f"part {type} not found")