Best Python code snippet using localstack_python
test_objects.py
Source: test_objects.py
1from unittest.mock import MagicMock2import pytest3from localstack.utils.objects import SubtypesInstanceManager, singleton_factory4def test_subtypes_instance_manager():5 class BaseClass(SubtypesInstanceManager):6 def foo(self):7 pass8 class C1(BaseClass):9 @staticmethod10 def impl_name() -> str:11 return "c1"12 def foo(self):13 return "bar"14 instance1 = BaseClass.get("c1")15 assert instance116 assert BaseClass.get("c1") == instance117 assert instance1.foo() == "bar"18 with pytest.raises(Exception):19 assert BaseClass.get("c2")20 class C2(BaseClass):21 @staticmethod22 def impl_name() -> str:23 return "c2"24 def foo(self):25 return "baz"26 instance2 = BaseClass.get("c2")27 assert BaseClass.get("c2") == instance228 assert instance2.foo() == "baz"29class TestSingletonFactory:30 def test_call_and_clear(self):31 mock = MagicMock()32 mock.return_value = "foobar"33 @singleton_factory34 def my_singleton():35 return mock()36 assert my_singleton() == mock.return_value37 mock.assert_called_once()38 assert my_singleton() == mock.return_value39 mock.assert_called_once()40 my_singleton.clear()41 assert my_singleton() == mock.return_value42 mock.assert_has_calls([(), ()])43 assert my_singleton() == mock.return_value44 mock.assert_has_calls([(), ()])45 def test_exception_does_not_set_a_value(self):46 mock = MagicMock()47 @singleton_factory48 def my_singleton():49 mock()50 raise ValueError("oh noes")51 with pytest.raises(ValueError):52 my_singleton()53 mock.assert_has_calls([()])54 with pytest.raises(ValueError):55 my_singleton()56 mock.assert_has_calls([(), ()])57 def test_set_none_value_does_not_set_singleton(self):58 mock = MagicMock()59 mock.return_value = None60 @singleton_factory61 def my_singleton():62 return mock()63 assert my_singleton() is None64 mock.assert_has_calls([()])65 assert my_singleton() is None66 mock.assert_has_calls([(), ()])67 def test_set_falsy_value_sets_singleton(self):68 mock = MagicMock()69 mock.return_value = False70 @singleton_factory71 def my_singleton():72 return mock()73 assert my_singleton() is False74 mock.assert_called_once()75 assert my_singleton() is False...
singleton_decorator.py
Source: singleton_decorator.py
...18 ...class Demo:19 ... pass20 """21 _set_singleton_instance(original_class)22 def singleton_factory(cls):23 return singletons[original_class]24 original_class._instance_factory = classmethod(singleton_factory)25 return original_class26def _set_singleton_instance(original_class):27 lock.acquire()28 if original_class not in singletons:29 singletons[original_class] = original_class()...
Check out the latest blogs from LambdaTest on this topic:
The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.
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.
Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.
Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.
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!!