How to use hook_failure method in Selene

Best Python code snippet using selene_python

errors.py

Source:errors.py Github

copy

Full Screen

1# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file.4"""Common errors thrown when repo presubmit checks fail."""5from __future__ import print_function6import re7import sys8class VerifyException(Exception):9 """Basic sanity checks failed."""10class HookFailure(object):11 """Contains an error message and a list of error details."""12 def __init__(self, msg, items=None):13 self.msg = msg14 self.items = items15 def __str__(self):16 return _FormatHookFailure(self)17_INDENT = ' ' * 418_PROJECT_INFO = 'Errors in PROJECT *%s*!'19def _PrintWithIndent(msg, indent_level):20 """Print a block of text with a specified indent level to stderr.21 Args:22 msg: A string to print (may contain newlines).23 indent_level: The number of indents to prefix each line with. Each indent24 is four characters wide.25 """26 regex = re.compile(r'^', re.M)27 msg = regex.sub(_INDENT * indent_level, msg)28 print(msg, file=sys.stderr)29def _FormatCommitDesc(desc):30 """Returns the properly prefixed commit description."""31 regex = re.compile(r'^', re.M)32 return regex.sub('>', desc)33def _FormatHookFailure(hook_failure):34 """Returns the properly formatted VerifyException as a string."""35 item_prefix = '\n%s* ' % _INDENT36 formatted_items = ''37 if hook_failure.items:38 formatted_items = item_prefix + item_prefix.join(hook_failure.items)39 return '* ' + hook_failure.msg + formatted_items40def PrintErrorForProject(project, error):41 """Prints the project and its error.42 Args:43 project: project name44 error: An instance of the HookFailure class45 """46 _PrintWithIndent(_PROJECT_INFO % project, 0)47 _PrintWithIndent(_FormatHookFailure(error), 1)48 print('', file=sys.stderr)49def PrintErrorsForCommit(project, commit, commit_desc, error_list):50 """Prints the hook error to stderr with project and commit context51 A sample error output for a project would be:52 ----------------------------------------------------------------------------53 Errors in PROJECT *chromiumos/repohooks*!54 COMMIT 10041758:55 Description:56 >staged57 >58 >TEST=some59 >Change-Id: I2c4f545a20a659541c02be16aa9dc440c876a60460 >61 Errors:62 * Changelist description needs BUG field (after first line)63 * Found line ending with white space in:64 * src/repohooks/pre-upload.py, line 30765 * Found lines longer than 80 characters (first 5 shown):66 * src/repohooks/pre-upload.py, line 335, 85 chars67 ----------------------------------------------------------------------------68 Args:69 project: project name70 commit: the commit hash the errors belong to71 commit_desc: a string containing the commit message72 error_list: a list of HookFailure instances73 """74 _PrintWithIndent(_PROJECT_INFO % project, 0)75 formatted_desc = _FormatCommitDesc(commit_desc)76 _PrintWithIndent('COMMIT %s:' % commit[:8], 1)77 _PrintWithIndent('Description:', 2)78 _PrintWithIndent(formatted_desc, 3)79 _PrintWithIndent('Errors:', 2)80 for error in error_list:81 _PrintWithIndent(_FormatHookFailure(error), 3)...

Full Screen

Full Screen

wait.py

Source:wait.py Github

copy

Full Screen

...36 self, hook_failure: Optional[Callable[[TimeoutException], Exception]]37 ) -> Wait[E]:38 return Wait(self._entity, self._timeout, hook_failure)39 @property40 def hook_failure(41 self,42 ) -> Optional[Callable[[TimeoutException], Exception]]:43 return self._hook_failure44 def for_(self, fn: Callable[[E], R]) -> R:45 finish_time = time.time() + self._timeout46 while True:47 try:48 return fn(self._entity)49 except Exception as reason:50 if time.time() > finish_time:51 reason_message = str(reason)52 reason_string = '{name}: {message}'.format(53 name=reason.__class__.__name__, message=reason_message54 )55 timeout = self._timeout56 entity = self._entity57 failure = TimeoutException(58 f'''59Timed out after {timeout}s, while waiting for:60{entity}.{fn}61Reason: {reason_string}'''62 )63 raise self._hook_failure(failure)64 def until(self, fn: Callable[[E], R]) -> bool:65 try:66 self.for_(fn)67 return True68 except TimeoutException:69 return False70 def command(self, description: str, fn: Callable[[E], None]) -> None:71 self.for_(Command(description, fn))72 def query(self, description: str, fn: Callable[[E], R]) -> R:...

Full Screen

Full Screen

environment.js

Source:environment.js Github

copy

Full Screen

1/**2 * External dependencies3 */4const PuppeteerEnvironment = require( 'jest-environment-puppeteer' );5const { addAttach } = require( 'jest-html-reporters/helper' );6class E2EEnvironment extends PuppeteerEnvironment {7 async handleTestEvent( event ) {8 if (9 event.name === 'test_fn_failure' ||10 event.name === 'hook_failure'11 ) {12 const attach = await this.global.page.screenshot( {13 fullPage: event.name !== 'hook_failure',14 } );15 await addAttach( {16 attach,17 description: 'Full Page Screenshot',18 context: this.global,19 bufferFormat: 'png',20 } );21 }22 }23}24// This code is helpful for tracing every test that is executed.25// You should use this code if your test fails, but Jest doesn't give you a significant error, and you need to debug.26// async handleTestEvent( event ) {27// const ignoredEvents = [28// 'setup',29// 'add_hook',30// 'start_describe_definition',31// 'add_test',32// 'finish_describe_definition',33// 'run_start',34// 'run_describe_start',35// 'test_start',36// 'hook_start',37// 'hook_success',38// 'test_fn_start',39// 'test_fn_success',40// 'test_done',41// 'run_describe_finish',42// 'run_finish',43// 'teardown',44// ];45// if ( ! ignoredEvents.includes( event.name ) ) {46// // eslint-disable-next-line no-console47// console.log(48// new Date().toString() +49// ' Unhandled event(' +50// event.name +51// '): ' +52// util.inspect( event )53// );54// }55// }...

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 Selene 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