How to use _print_errors method in tavern

Best Python code snippet using tavern

bugs_cli.py

Source:bugs_cli.py Github

copy

Full Screen

...101 self._config = ConfigParser()102 self._config.read(config)103 self._console = Console()104 self._client = BugsClient(host=self._config["host"]["url"], port=self._config["host"]["port"])105 def _print_errors(self, errors):106 self._console.print("Something went wrong.", style="bold red")107 table = Table.grid()108 table.add_column()109 table.add_column()110 for error, description in errors.items():111 if isinstance(description, list):112 description = "\n".join(description)113 table.add_row(f"[bold]error:[/bold] ", str(description))114 self._console.print(table)115 def _guess_projectname(self):116 if projectname := os.environ.get("BUGSPROJECT"):117 self._console.print("[i]Note:[/i] No projectname was given, so I'm using projectname from the environment variable BUGSPROJECT")118 return projectname119 else:120 self._console.print("[i]Note:[/i] No projectname was given, so I'm using the current directory as projectname")121 return os.path.basename(os.getcwd())122 @connection_required123 def create(self, projectname: str=None):124 """create a new project.125 If no projectname is given, the name of the project will be taken from126 the environment variable BUGSPROJECT or, if not set, the current directory name.127 """128 if not projectname:129 projectname = self._guess_projectname()130 response = self._client.create_project(projectname)131 if "errors" in response:132 self._print_errors(response["errors"])133 else:134 self._console.print(f"[green]:heavy_check_mark:[/green] Created new project: {response['name']}")135 @connection_required136 def projects(self):137 """list all projects"""138 response = self._client.list_projects()139 if "errors" in response:140 self._print_errors(response["errors"])141 else:142 if not response:143 self._console.print("There are no projects.", style="italic")144 return145 table = Table(title="Projects", expand=True)146 table.add_column("Name", style="bold")147 table.add_column("Open issues")148 for project in response:149 table.add_row(project["name"], str(project["open_issues"]))150 if len(response) > self._config["bugs-cli"].getint("pager"):151 with self._console.pager(styles=True):152 self._console.print(table)153 else:154 self._console.print(table)155 @connection_required156 def ls(self, projectname: str=None, query: str="", closed: bool=False):157 """list issues in project.158 If no projectname is given, the name of the project will be taken from159 the environment variable BUGSPROJECT or, if not set, the current directory name.160 """161 if not projectname:162 projectname = self._guess_projectname()163 if closed:164 query += "&closed"165 response = self._client.list_issues(projectname, query=query)166 if "errors" in response:167 self._print_errors(response["errors"])168 else:169 if not response:170 self._console.print("There currently are no issues.", style="italic")171 return172 table = Table(title=f"Issues for [i]{projectname}[/i]", expand=True)173 table.add_column("ID", style="bold dim")174 table.add_column("Title", style="bold")175 table.add_column("Priority")176 table.add_column("Tags")177 table.add_column("Status")178 for issue in response:179 status = issue["status"]180 statuscolor = self._config["styles"][status.lower()]181 table.add_row(182 f'#{issue["id"]}',183 issue["title"],184 str(issue["priority"]),185 issue["tags"] or "-",186 f"[{statuscolor}]{status}[/{statuscolor}]",187 )188 if len(response) > self._config["bugs-cli"].getint("pager"):189 with self._console.pager(styles=True):190 self._console.print(table)191 else:192 self._console.print(table)193 @connection_required194 def show(self, issueid: int, projectname: str=None, nopager: bool=False):195 """show details of an issue.196 If no projectname is given, the name of the project will be taken from197 the environment variable BUGSPROJECT or, if not set, the current directory name.198 """199 if not projectname:200 projectname = self._guess_projectname()201 response = self._client.get_issue(projectname, issueid)202 if "errors" in response:203 self._print_errors(response["errors"])204 return205 # make pager optional206 with ExitStack() as stack:207 if not nopager:208 stack.enter_context(self._console.pager(styles=True))209 self._console.print(response["title"], style="underline bold")210 status = response["status"]211 statuscolor = self._config["styles"][status.lower()]212 self._console.print(f"Status: [{statuscolor}]{status}[/{statuscolor}]")213 self._console.print(f"Priority: {response['priority']}")214 self._console.print(f"Tags: {response['tags'] or '-'}")215 self._console.print(Panel(Markdown(response["body"] or "*no description*")))216 @connection_required217 def mark(self, issueid: int, status: str, projectname: str=None):218 """set the status for an issue.219 If no projectname is given, the name of the project will be taken from220 the environment variable BUGSPROJECT or, if not set, the current directory name.221 """222 if not projectname:223 projectname = self._guess_projectname()224 response = self._client.edit_issue(projectname, issueid, status=status)225 if "errors" in response:226 self._print_errors(response["errors"])227 return228 status = response["status"]229 statuscolor = self._config["styles"][status.lower()]230 self._console.print(f"[green]:heavy_check_mark:[/green] Set the status of '{response['title']}' to [{statuscolor}]{status}[/{statuscolor}]")231if __name__ == "__main__":...

Full Screen

Full Screen

Execute.py

Source:Execute.py Github

copy

Full Screen

...20 lexer_errors, parser_errors, virtual_machine_errors = [], [], []21 lexer = Lexer(source)22 tokens = lexer.scan_tokens()23 lexer_errors = lexer.get_errors()24 self._print_errors(lexer_errors)25 if lexer_errors:26 return lexer_errors + parser_errors, virtual_machine_errors27 parser = Parser(tokens)28 statements = parser.parse()29 parser_errors = parser.get_errors()30 self._print_errors(parser_errors)31 if parser_errors:32 return lexer_errors + parser_errors, virtual_machine_errors33 virtual_machine = VirtualMachine(34 statements, VirtualMachineConfig.get_registers(),35 VirtualMachineConfig.get_memory_capacity(), self._trace36 )37 virtual_machine.execute()38 virtual_machine_errors = virtual_machine.get_errors()39 self._print_errors(virtual_machine_errors)40 return lexer_errors + parser_errors, virtual_machine_errors41 def _print_errors(self, errors):42 for error in errors:43 if hasattr(error, "report"):44 print(error.report(), file=sys.stderr)45 else:...

Full Screen

Full Screen

validate.py

Source:validate.py Github

copy

Full Screen

...3import sys4from argparse import ArgumentParser5from pynwb.form.backends.hdf5 import HDF5IO6from pynwb import validate, load_namespaces, get_manager7def _print_errors(validation_errors):8 if validation_errors:9 print(' - found the following errors:', file=sys.stderr)10 for err in validation_errors:11 print('%s - %s' % (err.name, err.reason), file=sys.stderr)12 else:13 print(' - no errors found.')14def main():15 ep = """16 use --nspath to validate against an extension. If --ns is not specified,17 validate against all namespaces in namespace file.18 """19 parser = ArgumentParser(description="Validate an NWB file", epilog=ep)20 parser.add_argument("path", type=str, help="the path to the NWB file")21 parser.add_argument('-p', '--nspath', type=str, help="the path to the namespace file")22 parser.add_argument("-n", "--ns", type=str, help="the namespace to validate against")23 args = parser.parse_args()24 if not os.path.exists(args.path):25 print('%s not found' % args.path, file=sys.stderr)26 sys.exit(1)27 io = HDF5IO(args.path, get_manager())28 if args.nspath is not None:29 namespaces = load_namespaces(args.nspath)30 if args.ns is not None:31 print('Validating against %s from %s.' % (args.ns, args.ns_path))32 else:33 print('Validating using namespaces in %s.' % args.nspath)34 for ns in namespaces:35 print('Validating against %s' % ns)36 errors = validate(io, ns)37 _print_errors(errors)38 else:39 errors = validate(io)40 print('Validating against core namespace' % args.ns)41 _print_errors(errors)42if __name__ == '__main__': # pragma: no cover...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tavern automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful