Best Python code snippet using selene_python
errors.py
Source: errors.py
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)...
wait.py
Source: wait.py
...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:...
environment.js
Source: environment.js
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/โ/โ }...
Check out the latest blogs from LambdaTest on this topic:
There are times when developers get stuck with a problem that has to do with version changes. Trying to run the code or test without upgrading the package can result in unexpected errors.
Automating testing is a crucial step in the development pipeline of a software product. In an agile development environment, where there is continuous development, deployment, and maintenance of software products, automation testing ensures that the end software products delivered are error-free.
Web applications continue to evolve at an unbelievable pace, and the architecture surrounding web apps get more complicated all of the time. With the growth in complexity of the web application and the development process, web application testing also needs to keep pace with the ever-changing demands.
โTest frequently and early.โ If youโve been following my testing agenda, youโre probably sick of hearing me repeat that. However, it is making sense that if your tests detect an issue soon after it occurs, it will be easier to resolve. This is one of the guiding concepts that makes continuous integration such an effective method. Iโve encountered several teams who have a lot of automated tests but donโt use them as part of a continuous integration approach. There are frequently various reasons why the team believes these tests cannot be used with continuous integration. Perhaps the tests take too long to run, or they are not dependable enough to provide correct results on their own, necessitating human interpretation.
Hey LambdaTesters! Weโve got something special for you this week. ????
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!