Best Python code snippet using localstack_python
test_helper.py
Source: test_helper.py
...30 os.remove('/tmp/docker_helper_test_config')31 os.remove('/tmp/docker_helper_test_config_multi')32 @unittest.skipUnless(os.path.exists('/proc/self/cgroup'), 'Not running in a container')33 def test_container_id(self):34 self.assertIsNotNone(helper.get_current_container_id())35 36 for digit in helper.get_current_container_id():37 self.assertIn(digit, 'abcdef0123456789')38 def test_mock_container_id(self):39 with tempfile.NamedTemporaryFile(mode='w') as tmp:40 tmp.write("""4110:perf_event:/docker/0aefd0c98f1af9b7fd5c09d576e5840ee9e798136b4a953b001587b1f0496adf429:cpuset:/docker/0aefd0c98f1af9b7fd5c09d576e5840ee9e798136b4a953b001587b1f0496adf438:pids:/docker/0aefd0c98f1af9b7fd5c09d576e5840ee9e798136b4a953b001587b1f0496adf447:devices:/docker/0aefd0c98f1af9b7fd5c09d576e5840ee9e798136b4a953b001587b1f0496adf456:net_cls,net_prio:/docker/0aefd0c98f1af9b7fd5c09d576e5840ee9e798136b4a953b001587b1f0496adf465:blkio:/docker/0aefd0c98f1af9b7fd5c09d576e5840ee9e798136b4a953b001587b1f0496adf474:freezer:/docker/0aefd0c98f1af9b7fd5c09d576e5840ee9e798136b4a953b001587b1f0496adf483:memory:/docker/0aefd0c98f1af9b7fd5c09d576e5840ee9e798136b4a953b001587b1f0496adf492:cpu,cpuacct:/docker/0aefd0c98f1af9b7fd5c09d576e5840ee9e798136b4a953b001587b1f0496adf501:name=systemd:/docker/0aefd0c98f1af9b7fd5c09d576e5840ee9e798136b4a953b001587b1f0496adf51 """)52 tmp.flush()53 self.assertEqual(54 helper.get_current_container_id(read_from=tmp.name),55 '0aefd0c98f1af9b7fd5c09d576e5840ee9e798136b4a953b001587b1f0496adf'56 )57 def test_mock_container_id_with_cgroup_parent(self):58 with tempfile.NamedTemporaryFile(mode='w') as tmp:59 tmp.write("""6010:perf_event:/custom-cgroup/48b20f6cb5ea9d19407984994b312e85cfa4fce2fe5aac7d0b9e38ce86d9bd53619:cpuset:/custom-cgroup/48b20f6cb5ea9d19407984994b312e85cfa4fce2fe5aac7d0b9e38ce86d9bd53628:pids:/system.slice/docker.service/custom-cgroup/48b20f6cb5ea9d19407984994b312e85cfa4fce2fe5aac7d0b9e38ce86d9bd53637:devices:/system.slice/docker.service/custom-cgroup/48b20f6cb5ea9d19407984994b312e85cfa4fce2fe5aac7d0b9e38ce86d9bd53646:net_cls,net_prio:/custom-cgroup/48b20f6cb5ea9d19407984994b312e85cfa4fce2fe5aac7d0b9e38ce86d9bd53655:blkio:/system.slice/docker.service/custom-cgroup/48b20f6cb5ea9d19407984994b312e85cfa4fce2fe5aac7d0b9e38ce86d9bd53664:freezer:/custom-cgroup/48b20f6cb5ea9d19407984994b312e85cfa4fce2fe5aac7d0b9e38ce86d9bd53673:memory:/system.slice/docker.service/custom-cgroup/48b20f6cb5ea9d19407984994b312e85cfa4fce2fe5aac7d0b9e38ce86d9bd53682:cpu,cpuacct:/system.slice/docker.service/custom-cgroup/48b20f6cb5ea9d19407984994b312e85cfa4fce2fe5aac7d0b9e38ce86d9bd53691:name=systemd:/system.slice/docker.service/custom-cgroup/48b20f6cb5ea9d19407984994b312e85cfa4fce2fe5aac7d0b9e38ce86d9bd5370 """)71 tmp.flush()72 self.assertEqual(73 helper.get_current_container_id(read_from=tmp.name),74 '48b20f6cb5ea9d19407984994b312e85cfa4fce2fe5aac7d0b9e38ce86d9bd53'75 )76 def test_configuration(self):77 os.environ['CONF_B'] = 'env=value=B'78 os.environ['CONF_C'] = 'env=value=C'79 os.environ['TEST_ENV'] = 'testing'80 81 rc = helper.read_configuration82 self.assertEqual(rc('CONF_A', '/tmp/docker_helper_test_config_multi'), 'config-A')83 self.assertEqual(rc('CONF_B', '/tmp/docker_helper_test_config_multi'), 'config=B')84 self.assertEqual(rc('CONF_C', '/tmp/docker_helper_test_config_multi'), 'env=value=C')85 self.assertEqual(rc('CONF_C', '/tmp/docker_helper_test_config_multi', fallback_to_env=False), None)86 self.assertEqual(rc('CONF_C', '/tmp/docker_helper_test_config_multi', default='default', fallback_to_env=False), 'default')87 self.assertEqual(rc('CONF_D', default='x'), 'x')...
resources.py
Source: resources.py
...53 matching.append(container)54 return matching55 @property56 def self(self):57 self_id = get_current_container_id()58 if self_id:59 return self.matching(self_id).first_value60class ServiceList(ResourceList):61 def _matching(self, target):62 for matching_resource in super(ServiceList, self)._matching(target):63 yield matching_resource64 for service in self:65 if 'com.docker.stack.namespace' in service.labels:66 if service.name == '%s_%s' % (service.labels['com.docker.stack.namespace'], target):67 yield service68 @property69 def self(self):70 self_id = get_current_container_id()71 for service in self:72 if service.tasks.matching(self_id):73 return service74class TaskList(ResourceList):75 def _matching(self, target):76 for matching_resource in super(TaskList, self)._matching(target):77 yield matching_resource78 for task in self:79 if target == task.container_id:80 yield task81 # check swarm services82 if target == task.service_id:83 yield task84 service_name = task.labels.get('com.docker.swarm.service.name')85 if service_name:86 if target == service_name:87 yield task88 if 'com.docker.stack.namespace' in task.labels:89 if service_name == '%s_%s' % (task.labels['com.docker.stack.namespace'], target):90 yield task91 def with_status(self, status):92 return type(self)(task for task in self if task.status.lower() == status.lower())93 @property94 def self(self):95 self_id = get_current_container_id()96 if self_id:97 return self.matching(self_id).first_value98class NetworkList(ResourceList):99 def _matching(self, target):100 for matching_resource in super(NetworkList, self)._matching(target):101 yield matching_resource102 if isinstance(target, NetworkList):103 target_network_ids = set(n.id for n in target)104 elif hasattr(target, 'networks') and target.networks:105 target_network_ids = set(n.id for n in target.networks)106 elif hasattr(target, 'id'):107 target_network_ids = {target.id}108 else:109 return...
docker_utils.py
Source: docker_utils.py
...30 config.LEGACY_DOCKER_CLIENT,31 is_docker_sdk_installed(),32 )33 return SdkDockerClient()34def get_current_container_id() -> str:35 """36 Returns the ID of the current container, or raises a ValueError if we're not in docker.37 :return: the ID of the current container38 """39 if not config.is_in_docker:40 raise ValueError("not in docker")41 container_id = platform.node()42 if not container_id:43 raise OSError("no hostname returned to use as container id")44 return container_id45def inspect_current_container_mounts() -> List[VolumeInfo]:46 return DOCKER_CLIENT.inspect_container_volumes(get_current_container_id())47@functools.lru_cache()48def get_default_volume_dir_mount() -> Optional[VolumeInfo]:49 """50 Returns the volume information of LocalStack's DEFAULT_VOLUME_DIR (/var/lib/localstack), if mounted,51 else it returns None. If we're not currently in docker a VauleError is raised. in a container, a ValueError is52 raised.53 :return: the volume info of the default volume dir or None54 """55 for volume in inspect_current_container_mounts():56 if volume.destination.rstrip("/") == DEFAULT_VOLUME_DIR:57 return volume58 return None...
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!!