Best Python code snippet using avocado_python
example.py
Source:example.py
...74 }75 ]76 }77 basic_data = _get_basic_test_data()78 basic_test = _make_test(api, basic_data, 'basic')79 basic_test += api.step_data(80 'Waiting for revision 314015 and 1 other revision(s). (2)',81 stdout=api.json.output(wait_for_any_output))82 yield basic_test83 failed_build_test_data = _get_ref_range_only_test_data()84 failed_build_test = _make_test(85 api, failed_build_test_data, 'failed_build_test')86 failed_build_test_step_data = {87 'failed':88 [89 {90 'builder': 'linux_perf_tester',91 'job_name': 'a6298e4afedbf2cd461755ea6f45b0ad64222222-test',92 'master': 'tryserver.chromium.perf',93 'type': 'buildbot',94 'job_url': 'http://tempuri.org/log',95 }96 ],97 }98 failed_build_test += api.step_data(99 'Waiting for revision 314015 and 1 other revision(s). (2)',100 stdout=api.json.output(failed_build_test_step_data), retcode=1)101 yield failed_build_test102 basic_data = _get_basic_test_data()103 windows_test = _make_test(104 api, basic_data, 'windows_bisector', platform='windows')105 windows_test += api.step_data(106 'Waiting for revision 314015 and 1 other revision(s). (2)',107 stdout=api.json.output(wait_for_any_output))108 yield windows_test109 basic_data = _get_basic_test_data()110 winx64_test = _make_test(111 api, basic_data, 'windows_x64_bisector', platform='win_x64')112 winx64_test += api.step_data(113 'Waiting for revision 314015 and 1 other revision(s). (2)',114 stdout=api.json.output(wait_for_any_output))115 yield winx64_test116 basic_data = _get_basic_test_data()117 mac_test = _make_test(api, basic_data, 'mac_bisector', platform='mac')118 mac_test += api.step_data(119 'Waiting for revision 314015 and 1 other revision(s). (2)',120 stdout=api.json.output(wait_for_any_output))121 yield mac_test122 basic_data = _get_basic_test_data()123 android_test = _make_test(124 api, basic_data, 'android_bisector', platform='android')125 android_test += api.step_data(126 'Waiting for revision 314015 and 1 other revision(s). (2)',127 stdout=api.json.output(wait_for_any_output))128 yield android_test129 basic_data = _get_basic_test_data()130 android_arm64_test = _make_test(131 api, basic_data, 'android_arm64_bisector', platform='android_arm64')132 android_arm64_test += api.step_data(133 'Waiting for revision 314015 and 1 other revision(s). (2)',134 stdout=api.json.output(wait_for_any_output))135 yield android_arm64_test136 failed_data = _get_basic_test_data()137 failed_data[0].pop('DEPS')138 failed_data[1]['test_results']['results']['error'] = 'Dummy error.'139 failed_data[1]['test_results']['results'].pop('mean')140 failed_data[1]['test_results']['results'].pop('std_err')141 failed_data[1].pop('DEPS_change')142 failed_data[1].pop('DEPS')143 failed_data[1].pop('DEPS_interval')144 failed_data[0].pop('git_diff')145 yield _make_test(api, failed_data, 'failed_test')146 reversed_basic_data = _get_reversed_basic_test_data()147 yield _make_test(api, reversed_basic_data, 'reversed_basic')148 bad_git_hash_data = _get_basic_test_data()149 bad_git_hash_data[1]['interned_hashes'] = {'003': '12345', '002': 'Bad Hash'}150 yield _make_test(api, bad_git_hash_data, 'failed_git_hash_object')151 missing_dep_data = _get_basic_test_data()152 tricked_DEPS_file = ("vars={'v8_' + 'revision': '001'};"153 "deps = {'src/v8': 'v8.git@' + Var('v8_revision'),"154 "'src/third_party/WebKit': 'webkit.git@010'}")155 missing_dep_data[0]['DEPS'] = tricked_DEPS_file156 yield _make_test(api, missing_dep_data, 'missing_vars_entry')157 missing_dep_data = _get_basic_test_data()158 tricked_DEPS_file = ("vars={'v8_revision': '001'};"159 "deps = {'src/v8': 'v8.XXX@' + Var('v8_revision'),"160 "'src/third_party/WebKit': 'webkit.git@010'}")161 missing_dep_data[0]['DEPS'] = tricked_DEPS_file162 yield _make_test(api, missing_dep_data, 'missing_deps_entry')163 bad_deps_syntax_data = _get_basic_test_data()164 bad_deps_syntax_data[1]['DEPS'] = 'raise RuntimeError("")'165 yield _make_test(api, bad_deps_syntax_data, 'bad_deps_syntax')166 basic__data = _get_basic_test_data()167 bisect_script_test = _make_test(api, basic_data, 'basic_bisect_script')168 bisect_script_test += api.step_data(169 'Waiting for revision 314015 and 1 other revision(s). (2)',170 stdout=api.json.output(wait_for_any_output))171 bisect_script_test += api.properties(mastername='tryserver.chromium.perf',172 buildername='linux_perf_bisect',173 slavename='dummyslave')174 yield bisect_script_test175def _get_ref_range_only_test_data():176 return [177 {178 'refrange': True,179 'hash': 'a6298e4afedbf2cd461755ea6f45b0ad64222222',180 'commit_pos': '314015',181 },182 {183 'refrange': True,184 'hash': '00316c9ddfb9d7b4e1ed2fff9fe6d964d2111111',185 'commit_pos': '314017',186 'test_results': {187 'results': {188 'mean': 15,189 'std_err': 1,190 'values': [14, 15, 16],191 },192 'retcodes': [0],193 }194 },195 ]196def _get_basic_test_data():197 return [198 {199 'refrange': True,200 'hash': 'a6298e4afedbf2cd461755ea6f45b0ad64222222',201 'commit_pos': '314015',202 'test_results': {203 'results': {204 'mean': 20,205 'std_err': 1,206 'values': [19, 20, 21],207 },208 'retcodes': [0],209 },210 "DEPS": ("vars={'v8_revision': '001'};"211 "deps = {'src/v8': 'v8.git@' + Var('v8_revision'),"212 "'src/third_party/WebKit': 'webkit.git@010'}"),213 'git_diff': {214 '002': 'Dummy .diff contents 001 - 002',215 '003': 'Dummy .diff contents 001 - 003',216 },217 'cl_info': 'S3P4R4T0R'.join(['DummyAuthor', 'dummy@nowhere.com',218 'Some random CL', '01/01/2015',219 'A long description for a CL.\n'220 'Containing multiple lines']),221 },222 {223 'hash': 'dcdcdc0ff1122212323134879ddceeb1240b0988',224 'commit_pos': '314016',225 'test_results': {226 'results': {227 'mean': 15,228 'std_err': 1,229 'values': [14, 15, 16],230 },231 'retcodes': [0],232 },233 'DEPS_change': 'True',234 "DEPS": ("vars={'v8_revision': '004'};"235 "deps = {'src/v8': 'v8.git@' + Var('v8_revision'),"236 "'src/third_party/WebKit': 'webkit.git@010'}"),237 'DEPS_interval': {'v8': '004 003 002'.split()},238 },239 {240 'refrange': True,241 'hash': '00316c9ddfb9d7b4e1ed2fff9fe6d964d2111111',242 'commit_pos': '314017',243 'test_results': {244 'results': {245 'mean': 15,246 'std_err': 1,247 'values': [14, 15, 16],248 },249 'retcodes': [0],250 }251 },252 ]253def _get_reversed_basic_test_data():254 return [255 {256 'refrange': True,257 'hash': '00316c9ddfb9d7b4e1ed2fff9fe6d964d2111111',258 'commit_pos': '314015',259 'test_results': {260 'results': {261 'mean': 20,262 'std_err': 1,263 'values': [19, 20, 21],264 },265 'retcodes': [0],266 },267 'cl_info': 'S3P4R4T0R'.join(['DummyAuthor', 'dummy@nowhere.com',268 'Some random CL', '01/01/2015',269 'A long description for a CL.\n'270 'Containing multiple lines'])271 },272 {273 'hash': 'a6298e4afedbf2cd461755ea6f45b0ad64222222',274 'commit_pos': '314016',275 'test_results': {276 'results': {277 'mean': 20,278 'std_err': 1,279 'values': [19, 20, 21],280 },281 'retcodes': [0],282 },283 "DEPS": ("vars={'v8_revision': '001'};"284 "deps = {'src/v8': 'v8.git@' + Var('v8_revision'),"285 "'src/third_party/WebKit': 'webkit.git@010'}"),286 'git_diff': {287 '002': 'Dummy .diff contents 001 - 002',288 '003': 'Dummy .diff contents 001 - 003',289 },290 },291 {292 'refrange': True,293 'hash': 'dcdcdc0ff1122212323134879ddceeb1240b0988',294 'commit_pos': '314017',295 'test_results': {296 'results': {297 'mean': 15,298 'std_err': 1,299 'values': [14, 15, 16],300 },301 'retcodes': [0],302 },303 'DEPS_change': 'True',304 "DEPS": ("vars={'v8_revision': '004'};"305 "deps = {'src/v8': 'v8.git@' + Var('v8_revision'),"306 "'src/third_party/WebKit': 'webkit.git@010'}"),307 'DEPS_interval': {'v8': '004 003 002'.split()},308 },309 ]310def _make_test(api, test_data, test_name, platform='linux'):311 basic_test = api.test(test_name)312 basic_test += _get_revision_range_step_data(api, test_data)313 for revision_data in test_data:314 for step_data in _get_step_data_for_revision(api, revision_data):315 basic_test += step_data316 if 'win_x64' in platform:317 basic_test += api.properties(bisect_config=_get_config({318 'command': ('src/tools/perf/run_benchmark -v --browser=release_x64'319 ' smoothness.tough_scrolling_cases'),320 'recipe_tester_name': 'chromium_rel_win7_x64'}))321 elif 'win' in platform:322 basic_test += api.properties(bisect_config=_get_config(323 {'recipe_tester_name': 'chromium_rel_win7'}))324 elif 'mac' in platform:...
tests.py
Source:tests.py
...13 @staticmethod14 def _print_res(response: Response):15 print(json.dumps(response.json(enconding='utf-8'), indent=4,encoding='utf-8'))16 @staticmethod17 def _make_test(client: APIClient, method: str, path: str, data: dict = {}):18 method = method.lower()19 if method == 'get':20 response = client.get(path, data=data)21 elif method == 'post':22 response = client.post(path, data=data)23 elif method == 'patch':24 response = client.patch(path, data=data)25 elif method == 'put':26 response = client.put(path, data=data)27 else:28 response = client.delete(path, data=data)29 print(json.dumps(response.json(), indent=4))30 return response31 @classmethod32 def setUpClass(cls):33 super().setUpClass()34 call_command('loaddata', 'data.yaml', verbosity=0)35 def setUp(self) -> None:36 self.customer_client = APIClient()37 self.customer_client.login(username='rand1925', password='rand1925')38 self.admin_client = APIClient()39 self.admin_client.login(username='admin', password='admin123')40 def test_post_save(self):41 isbn = '7302244752'42 book = Book.objects.get(isbn=isbn)43 orders = Order.objects.filter(book=book)44 print(Order.objects.filter(book=book).first())45 response_post_save = self._make_test(self.admin_client, 'patch', f'/api/v1/book/{isbn}/', data={46 'new_total': 047 })48 book = Book.objects.get(isbn=isbn)49 print(Order.objects.filter(book=book).filter(status=Order.OrderStatus.OUT_OF_STOCK).all())50 def test_list_recycle(self):51 orders = Order.objects.filter(status=100)52 response_allow_true = self._make_test(self.admin_client, 'get', '/api/v1/order/?status=30')53 def test_list_recycle_saus(self):54 response_list_recycle = self._make_test(self.customer_client, 'get', '/api/v1/profile/')55 def test_retreive(self):56 r = self._make_test(self.customer_client, 'get', '/api/v1/config/')57 def test_list_recycle_satus(self):58 response_list_recycle = self._make_test(self.admin_client, 'get', '/api/v1/recycle/?status=100')59 def test_list_book(self):60 response_list_book = self._make_test(self.customer_client, 'get', '/api/v1/book/')61 def test_purchase(self):62 response_purchase = self._make_test(self.customer_client, 'post', '/api/v1/book/7302244752/purchase/', data={63 'old': False,64 'total': 165 })66 response_order_mine = self._make_test(self.customer_client, 'get', '/api/v1/order/')67 all_orders = response_order_mine.data68 order = all_orders[-1]69 order_id = order['id']70 response_order_detail = self._make_test(self.customer_client, 'get', f'/api/v1/order/{order_id}/')71 response_order_pay = self._make_test(self.customer_client, 'patch', f'/api/v1/order/{order_id}/pay/')72 response_list_paid = self._make_test(self.admin_client, 'get', f'/api/v1/order/?status=40')73 response_order_receive = self._make_test(self.customer_client, 'patch', f'/api/v1/order/{order_id}/receive/')74 response_order_recycle_request = self._make_test(self.customer_client, 'post',75 f'/api/v1/order/{order_id}/recycle/',76 data={"message": "ç³è¯·åæ¶"})77 response_order_recycle_check = self._make_test(self.admin_client, 'patch',78 f'/api/v1/order/{order_id}/recycle/check/',79 data={"allowed": True})80 response_order_recycle_receive = self._make_test(self.admin_client, 'patch',81 f'/api/v1/order/{order_id}/recycle/receive/')82 response_noti = self._make_test(self.customer_client, 'get', '/api/v1/notification/')83 response_noti = self._make_test(self.admin_client, 'get', '/api/v1/notification/')...
TestsArgumentsHash.py
Source:TestsArgumentsHash.py
...23 self.assertEqual(expected_result, result)24 self.assertEqual(counter, local_counter + 1)25 else:26 self.assertEqual(counter, local_counter)27 def _make_test(self, args):28 for f in [func1, func2]:29 self._test_single_case(f, args, True)30 self._test_single_case(f, args, False)31 def test_values(self):32 self._make_test([1, 1, 1])33 self._make_test([1, 2, 3])34 self._make_test([1, 2, 2])35 self._make_test([1, 2, 0])36 self._make_test([1, 2, False])37 self._make_test([1, 2, None])38 self._make_test([1, 0, 2])39 self._make_test([0, 2, 1])40 self._make_test([0, 1, 2])41 def test_list_and_tuple(self):42 self._make_test([[], 0, 0])43 self._make_test([(), 0, 0])44 self._make_test([(1,), 0, 0])45 self._make_test([0, (), 0])46 self._make_test([0, [], 0])47 self._make_test([0, [None], 0])48 self._make_test([0, [], []])49 self._make_test([0, [], ()])50 self._make_test(["fffff", [], 0])51 self._make_test([[], [], []])52 self._make_test([0, [4], 0])53 self._make_test([0, [4, 4], 0])54 self._make_test([0, [4, 4, 4], 0])55 self._make_test([[4, 4, 4], [4, 4, 4], [4, 4, 4]])56 self._make_test([[4, 4, 4], [4, 4, 4], [4, 4, 3]])57 def test_dic(self):58 self._make_test([{}, 0, 0])59 self._make_test([{}, {}, 0])60 self._make_test([0, {}, 0])61 self._make_test([0, 0, {}])62 self._make_test([{1: "a"}, 0, 0])63 self._make_test([{1: "b"}, 0, 0])64 self._make_test([{2: "a"}, 0, 0])65 self._make_test([{2: {}}, 0, 0])66 self._make_test([0, {1: "a"}, 0])67if __name__ == '__main__':...
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!!