Best Python code snippet using grail_python
test_step.py
Source: test_step.py
1from unittest import TestCase, mock2from jasper.steps import Step, step3import time4import asyncio5class StepTestCase(TestCase):6 def setUp(self):7 self.slow_function_called = False8 self.slow_function_called_with = None9 def slow_function(context, sleep_time=0.5, fail=False):10 time.sleep(sleep_time)11 self.slow_function_called = True12 self.slow_function_called_with = {'context': context, 'sleep_time': sleep_time, 'fail': fail}13 if fail:14 raise Exception15 self.async_slow_function_called = False16 self.async_slow_function_called_with = None17 async def async_slow_function(context, sleep_time=0.5, fail=False):18 await asyncio.sleep(sleep_time)19 self.async_slow_function_called = True20 self.async_slow_function_called_with = {'context': context, 'sleep_time': sleep_time, 'fail': fail}21 if fail:22 raise Exception23 self.slow_function = slow_function24 self.async_slow_function = async_slow_function25 self.loop = asyncio.new_event_loop()26 def tearDown(self):27 self.loop.close()28 def test_init(self):29 some_step = Step(self.slow_function, sleep_time=0.1, fail=False)30 self.assertEqual(some_step.function, self.slow_function)31 self.assertEqual(some_step.kwargs, {'sleep_time': 0.1, 'fail': False})32 self.assertFalse(some_step.ran)33 self.assertFalse(some_step.passed)34 def test_successful_run(self):35 mock_context = mock.MagicMock()36 some_step = Step(self.slow_function, sleep_time=0.1, fail=False)37 try:38 self.loop.run_until_complete(some_step.run(mock_context))39 except Exception:40 raise AssertionError41 else:42 self.assertTrue(some_step.ran)43 self.assertTrue(some_step.passed)44 self.assertTrue(self.slow_function_called)45 self.assertEqual(46 self.slow_function_called_with, {'context': mock_context, 'sleep_time': 0.1, 'fail': False}47 )48 def test_failure_run(self):49 mock_context = mock.MagicMock()50 some_step = Step(self.slow_function, sleep_time=0.1, fail=True)51 with self.assertRaises(Exception):52 self.loop.run_until_complete(some_step.run(mock_context))53 self.assertTrue(some_step.ran)54 self.assertFalse(some_step.passed)55 self.assertTrue(self.slow_function_called)56 self.assertEqual(57 self.slow_function_called_with, {'context': mock_context, 'sleep_time': 0.1, 'fail': True}58 )59 def test_successful_async_run(self):60 mock_context = mock.MagicMock()61 some_step = Step(self.async_slow_function, sleep_time=0.1, fail=False)62 try:63 self.loop.run_until_complete(some_step.run(mock_context))64 except Exception:65 raise AssertionError66 else:67 self.assertTrue(some_step.ran)68 self.assertTrue(some_step.passed)69 self.assertTrue(self.async_slow_function_called)70 self.assertEqual(71 self.async_slow_function_called_with, {'context': mock_context, 'sleep_time': 0.1, 'fail': False}72 )73 def test_failure_async_run(self):74 mock_context = mock.MagicMock()75 some_step = Step(self.async_slow_function, sleep_time=0.1, fail=True)76 with self.assertRaises(Exception):77 self.loop.run_until_complete(some_step.run(mock_context))78 self.assertTrue(some_step.ran)79 self.assertFalse(some_step.passed)80 self.assertTrue(self.async_slow_function_called)81 self.assertEqual(82 self.async_slow_function_called_with, {'context': mock_context, 'sleep_time': 0.1, 'fail': True}83 )84 def test_step_decorator(self):85 some_step = step(self.slow_function)(sleep_time=0.1, fail=False)86 self.assertTrue(isinstance(some_step, Step))87 self.assertEqual(some_step.function, self.slow_function)88 self.assertEqual(some_step.kwargs, {'sleep_time': 0.1, 'fail': False})89 self.assertFalse(some_step.ran)...
taskINfunc.py
Source: taskINfunc.py
1# from functools import reduce2# task13# some_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]4# new_list = list(map(lambda x: x**2, some_list))5# print(new_list)6# task2 7# enter = list(input("введиÑе ÑиÑла: "))8# news = [int(x) for x in enter]9# print(sum(news))10# task3 11# nums = [1, 2, 3, 0, -1]12# print(nums)13# print(all(nums))14# task415# nums = [1, 2, 3, 0, -1]16# print(nums)17# print(any(nums))18# task519# nums = [1, 2, 3, 0, -1]20# negative = list(filter(lambda x: x < 0, nums))21# print(negative)22# task623# nums = [1, 2, 3, 0, -1, 4, 6]24# chet = list(filter(lambda x: x % 2 == 0, nums))25# print(chet)26# task727# slova = ['hello', 'world', 'incapsulation', 'inheritance']28# dlina = list(filter(lambda x: len(x) > 6, slova))29# print(dlina)30# task831# nums = [1, 2, 3, 4, 5, 6]32# umnoj = reduce(lambda a, b: a * b, nums)33# print(umnoj)34# task935# nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]36# nums1 = len(list(filter(lambda a: a % 2 == 0, nums)))37# nums2 = len(list(filter(lambda a: a % 2, nums)))38# print(f"колиÑеÑÑво ÑеÑнÑÑ
ÑиÑел {nums1}")39# print(f"колиÑеÑÑво не ÑеÑнÑÑ
ÑиÑел {nums2}")40# task1041# nums = [-2, 4, -3, 6, -5, 8]42# num_odd = list(map(lambda even: even, filter(lambda x: x < 0, nums)))43# num_even = list(map(lambda odd: odd, filter(lambda x: x >= 0, nums)))44# print(f'Ðе ÑÑÑнÑй:{num_odd}\nЧÑÑнÑй:{num_even}')45# task1146# def numbers(num):47# if num > 0:48# return 149# elif num < 0:50# return -151# else: 52# return 0 53# nums = [-1, 2, 3, 4, -5, 6, 7, -8, 9, 0]54# new_num = list(map(numbers, nums))55# print(new_num)56# task1257# some_list = list(input("введиÑе ÑпиÑок из ÑиÑел: "))58# some_step = int(input("введиÑе Ñаг: "))59# some_step %= len(some_list)60# new_list = list(some_list[some_step:] + some_list[:some_step])61# print(new_list)62# task1363# srez = int(input("введиÑе ÑиÑло ÑÑеза: "))64# mass = [x for x in input("введиÑе ÑиÑла ÑеÑез пÑобел: ").split()]65# for i in range(srez):66# print(mass[srez-1-i], end = " ")67# # Ñ
з какой из ниÑ
пÑавилÑнÑй (поÑÐµÐ¼Ñ Ñо не ÑабоÑÐ°ÐµÑ Ð² Ñ
акеÑÑанке)68# n = int(input("введиÑе ÑиÑло ÑÑеза: "))69# array = input("введиÑе ÑиÑла ÑеÑез пÑобел: ").split()70# def reversed(array):71 72# some_str = ""73# for i in range(n):74# some_str += array[n-1-i] + " "75 76# print(some_str.strip())77# reversed(array)78# task1479# # def balans(lit):80# # if lit == ')':81# # return '('82# # elif lit == '}':83# # return '{'84# # elif lit == ']':85# # return '['86# num = int(input("введиÑе ÑиÑло: "))87# for x in range(num):88# literals = input("введиÑе лиÑеÑалÑ: ").strip()89# flag = 190# new_list = []91# for lit in literals:92# if lit in ['{','[','(']:93# new_list.append(lit)94# elif new_list and new_list.pop() == lit:95# flag = 096# break97# if len(new_list) == 0:98# print("yes")99# else:...
test_producer_registry.py
Source: test_producer_registry.py
...8 registered types"""9 class MyFloatType(float):10 pass11 @step12 def some_step() -> MyFloatType:13 return MyFloatType(3.0)14 with does_not_raise():15 some_step()()16def test_producer_with_parameter_with_more_than_one_baseclass():17 """Tests if the producer selection work where the parameter has more18 than one baseclass, however only one of the types is registered"""19 class MyOtherType:20 pass21 class MyFloatType(float, MyOtherType):22 pass23 @step24 def some_step() -> MyFloatType:25 return MyFloatType(3.0)26 with does_not_raise():27 some_step()()28def test_producer_with_parameter_with_more_than_one_conflicting_baseclass():29 """Tests the case where the output parameter is inheriting from more than30 one baseclass which have different default producers"""31 class MyFirstType:32 pass33 class MySecondType:34 pass35 class MyFirstProducer(BaseProducer):36 TYPES = (MyFirstType,)37 class MySecondProducer(BaseProducer):38 TYPES = (MySecondType,)39 class MyConflictingType(MyFirstType, MySecondType):40 pass41 @step42 def some_step() -> MyConflictingType:43 return MyConflictingType()44 with pytest.raises(StepInterfaceError):45 some_step()()46def test_producer_with_conflicting_parameter_and_explicit_producer():47 """Tests the case where the output parameter is inheriting from more than48 one baseclass which have different default producers but the49 producer is explicitly defined"""50 class MyFirstType:51 pass52 class MySecondType:53 pass54 class MyFirstProducer(BaseProducer):55 TYPES = (MyFirstType,)56 class MySecondProducer(BaseProducer):57 TYPES = (MySecondType,)58 class MyConflictingType(MyFirstType, MySecondType):59 pass60 @step61 def some_step() -> MyConflictingType:62 return MyConflictingType()63 with does_not_raise():...
Check out the latest blogs from LambdaTest on this topic:
Automation frameworks enable automation testers by simplifying the test development and execution activities. A typical automation framework provides an environment for executing test plans and generating repeatable output. They are specialized tools that assist you in your everyday test automation tasks. Whether it is a test runner, an action recording tool, or a web testing tool, it is there to remove all the hard work from building test scripts and leave you with more time to do quality checks. Test Automation is a proven, cost-effective approach to improving software development. Therefore, choosing the best test automation framework can prove crucial to your test results and QA timeframes.
QA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.
Many theoretical descriptions explain the role of the Scrum Master as a vital member of the Scrum team. However, these descriptions do not provide an honest answer to the fundamental question: “What are the day-to-day activities of a Scrum Master?”
The web paradigm has changed considerably over the last few years. Web 2.0, a term coined way back in 1999, was one of the pivotal moments in the history of the Internet. UGC (User Generated Content), ease of use, and interoperability for the end-users were the key pillars of Web 2.0. Consumers who were only consuming content up till now started creating different forms of content (e.g., text, audio, video, etc.).
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!!