Best Python code snippet using Testify_python
PRESUBMIT.py
Source:PRESUBMIT.py
1# Copyright (c) 2012 The Chromium 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"""Top-level presubmit script for cc.5See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for6details on the presubmit API built into gcl.7"""8import re9CC_SOURCE_FILES=(r'^cc/.*\.(cc|h)$',)10def CheckAsserts(input_api, output_api, white_list=CC_SOURCE_FILES, black_list=None):11 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST)12 source_file_filter = lambda x: input_api.FilterSourceFile(x, white_list, black_list)13 assert_files = []14 notreached_files = []15 for f in input_api.AffectedSourceFiles(source_file_filter):16 contents = input_api.ReadFile(f, 'rb')17 # WebKit ASSERT() is not allowed.18 if re.search(r"\bASSERT\(", contents):19 assert_files.append(f.LocalPath())20 # WebKit ASSERT_NOT_REACHED() is not allowed.21 if re.search(r"ASSERT_NOT_REACHED\(", contents):22 notreached_files.append(f.LocalPath())23 if assert_files:24 return [output_api.PresubmitError(25 'These files use ASSERT instead of using DCHECK:',26 items=assert_files)]27 if notreached_files:28 return [output_api.PresubmitError(29 'These files use ASSERT_NOT_REACHED instead of using NOTREACHED:',30 items=notreached_files)]31 return []32def CheckChangeOnUpload(input_api, output_api):33 results = []34 results += CheckAsserts(input_api, output_api)35 return results36def GetPreferredTrySlaves(project, change):37 return [38 'linux_layout_rel',...
assertions.py
Source:assertions.py
...9 callable_obj(*args, **kwargs)10 except expected_exception_class as e:11 # we got the expected exception12 return e13 assert_not_reached("No exception was raised (expected %s)" % expected_exception_class,)14def assert_length(sequence, expected, msg=None):15 """Assert that a sequence or iterable has an expected length."""16 msg = msg or "%(sequence)s has length %(length)s expected %(expected)s"17 length = len(list(sequence))18 assert length == expected, msg % locals()19def assert_call(mock, call_idx, *args, **kwargs):20 """Assert that a function was called on mock with the correct args."""21 actual = mock.mock_calls[call_idx] if mock.mock_calls else None22 msg = f"Call {call_idx} expected {(args, kwargs)}, was {actual}"23 assert actual == (args, kwargs), msg24def assert_mock_calls(expected, mock_calls):25 """Assert that all expected calls are in the list of mock_calls."""26 for expected_call in expected:27 assert_in(expected_call, mock_calls)
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!!