Best Python code snippet using autotest_python
test_registry.py
Source: test_registry.py
...33 registry_namespace=registry_namespace,34 )35 assert target.registry_namespace == registry_namespace36 def test_function_name_without_override(self):37 def stub_function():38 pass39 target = Target(40 function=stub_function,41 registry_namespace='namespace',42 )43 assert target.function_name == 'stub_function'44 def test_function_name_with_override(self):45 def stub_function():46 pass47 stub_name_override = 'name_override'48 target = Target(49 function=stub_function,50 registry_namespace='namespace',51 name_override=stub_name_override,52 )53 assert target.function_name == stub_name_override54 def test_execute(self):55 mock_function = mock.Mock()56 mock_function.__name__ = 'mock_function'57 mock_target = Target(58 function=mock_function,59 registry_namespace='namespace',60 )61 return_value = mock_target.execute()62 # Target.execute should return None63 assert return_value is None64 options = {'key_1': 'val_1', 'key_2': 'val_2'}65 return_value = mock_target.execute(**options)66 assert return_value is None67 # Target.execute should defer to Target._function68 assert mock_function.call_args_list == [mock.call(), mock.call(**options)]69 def test_repr(self):70 def stub_function():71 pass72 stub_namespace = 'stub_namespace'73 target = Target(function=stub_function, registry_namespace=stub_namespace)74 assert repr(target) == '<begin.registry.Target(registry_namespace=stub_namespace,function_name=stub_function)>'75 def test_hash(self):76 def stub_function():77 pass78 stub_namespace = 'stub_namespace'79 target_1 = Target(function=stub_function, registry_namespace=stub_namespace)80 target_1_repr = '<begin.registry.Target(registry_namespace=stub_namespace,function_name=stub_function)>'81 # target.__hash__ should defer to the hash of its on repr82 assert hash(target_1) == hash(target_1_repr)83 # different target instances with the same function name and namespace should have the same hash84 target_2 = Target(function=stub_function, registry_namespace=stub_namespace)85 assert hash(target_1) == hash(target_2)86class TestTargetMap:87 def test_initialisation(self, resource_factory):88 registry_list = resource_factory.registry.create_multi()89 target_map = TargetMap(registry_list)90 assert target_map._registries is registry_list...
test_doubles.py
Source: test_doubles.py
...30 stub_function.add_route(31 condition={'kwarg' : 3},32 stub_type='value',33 stub_value=4)34 self.assertEqual(2, stub_function(arg=1, kwarg=1))35 self.assertEqual(4, stub_function(arg=1, kwarg=3))36 def test_arg_routing(self):37 stub_function = doubles.RoutableStubFunction()38 stub_function.add_route(39 condition=(1,),40 stub_type='value',41 stub_value=2)42 stub_function.add_route(43 condition=(3,),44 stub_type='value',45 stub_value=4)46 self.assertEqual(2, stub_function(1))47 self.assertEqual(4, stub_function(3))48 def test_self_routing(self):49 stub_function = doubles.RoutableStubFunction()50 stub_function.add_route(51 condition={52 'self': {'a': 1}},53 stub_type='value',54 stub_value=1)55 stub_function.add_route(56 condition={57 'self': {'a': 2}},58 stub_type='value',59 stub_value=2)60 self.safe_swap.swap(61 Host,62 'test',63 stub_function,64 default_original=True)65 host1 = Host(a=1)66 host2 = Host(a=2)67 self.assertEqual(68 1,69 host1.test())70 self.assertEqual(71 2,72 host2.test())73 def test_arg_and_kwarg_routing(self):74 stub_function = doubles.RoutableStubFunction()75 stub_function.add_route(76 condition={'args' : (1,),77 'kwargs' : {'kwarg' : 1}},78 stub_type='value',79 stub_value=2)80 stub_function.add_route(81 condition={'args' : (3,),82 'kwargs' : {'kwarg' : 3}},83 stub_type='value',84 stub_value=4)85 self.assertEqual(2, stub_function(1, kwarg=1))86 self.assertEqual(4, stub_function(3, kwarg=3))87 def test_kwarg_with_pattern(self):88 stub_function = doubles.RoutableStubFunction()89 stub_function.add_route(90 condition={'kwarg' : re.compile('.*pattern1.*')},91 stub_type='value',92 stub_value=1)93 self.assertEqual(1, stub_function('_', kwarg='something_with_pattern1'))94 self.assertRaises(95 doubles.StubRoutingException,96 stub_function,97 arg='_',98 kwarg='something_without_the_pattern')99 def test_arg_with_pattern(self):100 stub_function = doubles.RoutableStubFunction()101 stub_function.add_route(102 condition=(re.compile('.*pattern1.*'),),103 stub_type='value',104 stub_value=1)105 self.assertEqual(1, stub_function('something_with_pattern1', kwarg='_'))106 self.assertRaises(107 doubles.StubRoutingException,108 stub_function,109 'something_without_the_pattern',110 kwarg='_')111 def test_arg_is_dict(self):112 stub_function = doubles.RoutableStubFunction()113 stub_function.add_route(114 condition=({'a': 1},),115 stub_type='value',116 stub_value=1)117 self.assertEqual(1, stub_function({'a': 1}))118 def test_rotate(self):119 stub_function = doubles.RoutableStubFunction()120 route = doubles.RotatingRoute(121 condition=('a',),122 routes=[123 ('value', 1),124 ('value', 2)])125 126 stub_function.add_route(route=route)127 self.assertEqual(1, stub_function('a'))128 self.assertEqual(2, stub_function('a'))129class TestStubFunction(unittest.TestCase):130 def test_raises(self):131 e = TestException()132 stub_function = doubles.StubFunction(raises=e)133 self.assertRaises(134 TestException,135 stub_function)136 def test_calls(self):137 stub_function = doubles.StubFunction(calls=test_function)138 self.assertEqual('test_function', stub_function())139 def test_returns(self):140 stub_function = doubles.StubFunction(returns=1)141 self.assertEqual(1, stub_function())142class TestSpyFunction(unittest.TestCase):143 def test_reset(self):144 spy_function = doubles.SpyFunction(returns=1)145 self.assertEqual(1, spy_function(1))146 self.assertEqual(1, spy_function("apple"))147 self.assertEqual(1, spy_function(keyword="orange"))148 spy_function.reset()149 self.assertEqual([],150 spy_function.calls)151 def test_spy(self):152 spy_function = doubles.SpyFunction(returns=1)153 self.assertEqual(1, spy_function(1))154 self.assertEqual(1, spy_function("apple"))155 self.assertEqual(1, spy_function(keyword="orange"))...
test_nfs.py
Source: test_nfs.py
...61 "nfs_mount_src": "127.0.0.1:/mnt/nfssrc",62 "setup_local_nfs": "yes",63 "export_options": "rw,no_root_squash"}64 self.god = mock.mock_god()65 self.god.stub_function(path, "find_command")66 self.god.stub_function(process, "system")67 self.god.stub_function(process, "system_output")68 self.god.stub_function(os.path, "isfile")69 self.god.stub_function(os, "makedirs")70 self.god.stub_function(utils_misc, "is_mounted")71 self.god.stub_function(utils_misc, "mount")72 self.god.stub_function(utils_misc, "umount")73 self.god.stub_function(service.Factory, "create_service")74 attr = getattr(nfs, "Exportfs")75 setattr(attr, "already_exported", False)76 mock_class = self.god.create_mock_class_obj(attr, "Exportfs")77 self.god.stub_with(nfs, "Exportfs", mock_class)78 def tearDown(self):79 self.god.unstub_all()80 def test_nfs_setup(self):81 self.setup_stubs_init()82 nfs_local = nfs.Nfs(self.nfs_params)83 self.setup_stubs_setup(nfs_local)84 nfs_local.setup()85 self.setup_stubs_is_mounted(nfs_local)86 self.assertTrue(nfs_local.is_mounted())87 self.setup_stubs_cleanup(nfs_local)...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.
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!!