Best Python code snippet using localstack_python
28DecoratorChaining2DecorsCallOriginal.py
Source:28DecoratorChaining2DecorsCallOriginal.py
1def decor1(func):2 def inner1():3 print('decor1 execution')4 f()5 return inner16def decor2(func):7 def inner2():8 print('decor2 execution')9 func()10 return inner211@decor212@decor113def f():14 print('Original function')15f()16# /usr/bin/python3.6 /Code/venv/decorators/28DecoratorChaining2DecorsCallOriginal.py...
test_paths.py
Source:test_paths.py
1# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).2# Licensed under the Apache License, Version 2.0 (see LICENSE).3from pants.backend.graph_info.tasks.paths import Path, Paths4from pants.base.exceptions import TaskError5from pants_test.task_test_base import ConsoleTaskTestBase6class PathsTest(ConsoleTaskTestBase):7 @classmethod8 def task_type(cls):9 return Paths10 def test_only_one_target(self):11 target_a = self.make_target('a')12 with self.assertRaises(TaskError) as cm:13 self.execute_console_task(targets=[target_a])14 self.assertIn('Specify two targets please', str(cm.exception))15 self.assertIn('found 1', str(cm.exception))16 def test_three_targets(self):17 target_a = self.make_target('a')18 target_b = self.make_target('b')19 target_c = self.make_target('c')20 with self.assertRaises(TaskError) as cm:21 self.execute_console_task(targets=[target_a, target_b, target_c])22 self.assertIn('Specify two targets please', str(cm.exception))23 self.assertIn('found 3', str(cm.exception))24 def test_path_dependency_first_finds_no_paths(self):25 # Not sure if I like this behavior, but adding to document it26 target_b = self.make_target('b')27 target_a = self.make_target('a', dependencies=[target_b])28 self.assert_console_output('Found 0 paths', targets=[target_b, target_a])29 def test_single_edge_path(self):30 target_b = self.make_target('b')31 target_a = self.make_target('a', dependencies=[target_b])32 self.assert_console_output('Found 1 path',33 '',34 '\t[a, b]',35 targets=[target_a, target_b])36 def test_same_target_path(self):37 target_b = self.make_target('b')38 self.assert_console_output('Found 1 path',39 '',40 '\t[b]',41 targets=[target_b, target_b])42 def test_two_paths(self):43 target_b = self.make_target('b')44 target_inner_1 = self.make_target('inner1', dependencies=[target_b])45 target_inner_2 = self.make_target('inner2', dependencies=[target_b])46 target_a = self.make_target('a', dependencies=[target_inner_1, target_inner_2])47 self.assert_console_output('Found 2 paths',48 '',49 '\t[a, inner1, b]',50 '\t[a, inner2, b]',51 targets=[target_a, target_b])52 def test_cycle_no_path(self):53 target_b = self.make_target('b')54 target_inner_1 = self.make_target('inner1')55 target_inner_2 = self.make_target('inner2', dependencies=[target_inner_1])56 target_a = self.make_target('a', dependencies=[target_inner_1])57 target_inner_1.inject_dependency(target_inner_2.address)58 self.assert_console_output('Found 0 paths',59 targets=[target_a, target_b])60 def test_cycle_path(self):61 target_b = self.make_target('b')62 target_inner_1 = self.make_target('inner1', dependencies=[target_b])63 target_inner_2 = self.make_target('inner2', dependencies=[target_inner_1, target_b])64 target_inner_1.inject_dependency(target_inner_2.address)65 target_a = self.make_target('a', dependencies=[target_inner_1])66 self.assert_console_output('Found 3 paths',67 '',68 '\t[a, inner1, b]',69 '\t[a, inner1, inner2, b]',70 '\t[a, inner1, inner2, inner1, b]',71 targets=[target_a, target_b])72 def test_overlapping_paths(self):73 target_b = self.make_target('b')74 target_inner_1 = self.make_target('inner1', dependencies=[target_b])75 target_inner_2 = self.make_target('inner2', dependencies=[target_inner_1])76 target_a = self.make_target('a', dependencies=[target_inner_1, target_inner_2])77 self.assert_console_output('Found 2 paths',78 '',79 '\t[a, inner1, b]',80 '\t[a, inner2, inner1, b]',81 targets=[target_a, target_b])82class PathTest(ConsoleTaskTestBase):83 @classmethod84 def task_type(cls):85 return Path86 def test_only_returns_first_path(self):87 target_b = self.make_target('b')88 target_inner_1 = self.make_target('inner1', dependencies=[target_b])89 target_inner_2 = self.make_target('inner2', dependencies=[target_inner_1])90 target_a = self.make_target('a', dependencies=[target_inner_1, target_inner_2])91 self.assert_console_output('[a, inner1, b]',92 targets=[target_a, target_b])93 def test_when_no_path(self):94 target_b = self.make_target('b')95 target_a = self.make_target('a')96 self.assert_console_output('No path found from a to b!',...
Testsample2.py
Source:Testsample2.py
1#2# Vortex OpenSplice3#4# This software and documentation are Copyright 2006 to TO_YEAR ADLINK5# Technology Limited, its affiliated companies and licensors. All rights6# reserved.7#8# Licensed under the Apache License, Version 2.0 (the "License");9# you may not use this file except in compliance with the License.10# You may obtain a copy of the License at11#12# http://www.apache.org/licenses/LICENSE-2.013#14# Unless required by applicable law or agreed to in writing, software15# distributed under the License is distributed on an "AS IS" BASIS,16# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.17# See the License for the specific language governing permissions and18# limitations under the License.19#20'''21Created on Dec 8, 201722@author: prismtech23'''24import unittest25import struct26import countTest27if countTest.count_test == False:28 from sample2.basic import Inner29 from sample2.basic.test import Type130class Testsample2(unittest.TestCase):31 def testCopyInCopyOut(self):32 data = Type1(33 long1 = '\x13',34 inner1 = [35 Inner(long1=11,double1=1.1,array1=[11,12,13],str1='One'),36 Inner(long1=21,double1=2.1,array1=[21,22,23],str1='Two'),37 Inner(long1=31,double1=3.1,array1=[31,32,33],str1='Three'),38 ],39 mylong1 = 2340 )41 print('data: ' + str(data))42 43 print('data._get_packing_fmt(): ', data._get_packing_fmt())44 print('data._get_packing_args(): ', data._get_packing_args())45 buffer = data._serialize()46 print('buffer: ', buffer)47 48 values = struct.unpack(data._get_packing_fmt(), buffer)49 data1 = Type1()50 data1._deserialize(list(values))51 52 self.assertEqual(data.long1, data1.long1)53 self.assertEqual(data.mylong1, data.mylong1)54 self.assertEqual(len(data.inner1),len(data1.inner1))55 for i in range(len(data.inner1)):56 self.assertEqual(data.inner1[i].long1,data1.inner1[i].long1,'inner1[%d].long1'%i)57 self.assertEqual(data.inner1[i].double1,data1.inner1[i].double1,'inner1[%d].double1'%i)58 self.assertEqual(len(data.inner1[i].array1),len(data1.inner1[i].array1),'len(inner1[%d].array1)'%i)59 for j in range(len(data.inner1[i].array1)):60 self.assertEqual(data.inner1[i].array1[j],data1.inner1[i].array1[j],'inner1[%d].array1[%d]'%(i,j))61if __name__ == "__main__":62 #import sys;sys.argv = ['', 'Testsample2.testCopyInCopyOut']...
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!!