Best Python code snippet using autotest_python
override.py
Source:override.py
...38 self._override = override_value39 def __repr__(self):40 return "Override %s" % str(self.override_value)41 @property42 def override_value(self):43 return self._override44 def __eq__(self, other):45 return self.override_value == other.override_value46 def as_float(self):47 assert self.is_float_like()48 value = self.override_value49 if value in override_dict.keys():50 return override_dict[value]51 else:52 return value53 def as_numeric_value(self):54 value = self.override_value55 if value in override_dict.keys():56 return override_dict[value]...
test_config.py
Source:test_config.py
1import os2from contextlib import contextmanager3from typing import Any, Dict4from localstack import config5@contextmanager6def temporary_env(env: Dict[str, Any]):7 old = os.environ.copy()8 try:9 os.environ.update(env)10 yield os.environ11 finally:12 os.environ.clear()13 os.environ.update(old)14class TestProviderConfig:15 def test_provider_default_value(self):16 default_value = "default_value"17 override_value = "override_value"18 provider_config = config.ServiceProviderConfig(default_value=default_value)19 assert provider_config.get_provider("ec2") == default_value20 provider_config.set_provider("ec2", override_value)21 assert provider_config.get_provider("ec2") == override_value22 def test_provider_set_if_not_exists(self):23 default_value = "default_value"24 override_value = "override_value"25 provider_config = config.ServiceProviderConfig(default_value=default_value)26 provider_config.set_provider("ec2", default_value)27 provider_config.set_provider_if_not_exists("ec2", override_value)28 assert provider_config.get_provider("ec2") == default_value29 def test_provider_config_overrides(self, monkeypatch):30 default_value = "default_value"31 override_value = "override_value"32 provider_config = config.ServiceProviderConfig(default_value=default_value)33 monkeypatch.setenv("PROVIDER_OVERRIDE_EC2", override_value)34 provider_config.load_from_environment()35 assert provider_config.get_provider("ec2") == override_value36 assert provider_config.get_provider("sqs") == default_value37 monkeypatch.setenv("PROVIDER_OVERRIDE_SQS", override_value)38 provider_config.load_from_environment()39 assert provider_config.get_provider("sqs") == override_value40 def test_bulk_set_if_not_exists(self):41 default_value = "default_value"42 custom_value = "custom_value"43 override_value = "override_value"44 override_services = ["sqs", "sns", "lambda", "ec2"]45 provider_config = config.ServiceProviderConfig(default_value=default_value)46 provider_config.set_provider("ec2", default_value)47 provider_config.set_provider("lambda", custom_value)48 provider_config.bulk_set_provider_if_not_exists(override_services, override_value)49 assert provider_config.get_provider("sqs") == override_value50 assert provider_config.get_provider("sns") == override_value51 assert provider_config.get_provider("lambda") == custom_value52 assert provider_config.get_provider("ec2") == default_value53 assert provider_config.get_provider("kinesis") == default_value54class TestParseServicePorts:55 def test_returns_default_service_ports(self):56 result = config.parse_service_ports()57 assert result == config.DEFAULT_SERVICE_PORTS58 def test_with_service_subset(self):59 with temporary_env({"SERVICES": "s3,sqs"}):60 result = config.parse_service_ports()61 assert len(result) == 262 assert "s3" in result63 assert "sqs" in result64 assert result["s3"] == 456665 assert result["sqs"] == 456666 def test_custom_service_default_port(self):67 with temporary_env({"SERVICES": "foobar"}):68 result = config.parse_service_ports()69 assert len(result) == 170 assert "foobar" not in config.DEFAULT_SERVICE_PORTS71 assert "foobar" in result72 # foobar is not a default service so it is assigned 073 assert result["foobar"] == 074 def test_custom_port_mapping(self):75 with temporary_env({"SERVICES": "foobar", "FOOBAR_PORT": "1234"}):76 result = config.parse_service_ports()77 assert len(result) == 178 assert "foobar" not in config.DEFAULT_SERVICE_PORTS79 assert "foobar" in result80 assert result["foobar"] == 123481 def test_custom_illegal_port_mapping(self):82 with temporary_env({"SERVICES": "foobar", "FOOBAR_PORT": "asdf"}):83 result = config.parse_service_ports()84 assert len(result) == 185 assert "foobar" not in config.DEFAULT_SERVICE_PORTS86 assert "foobar" in result87 # FOOBAR_PORT cannot be parsed88 assert result["foobar"] == 089 def test_custom_port_mapping_in_services_env(self):90 with temporary_env({"SERVICES": "foobar:1235"}):91 result = config.parse_service_ports()92 assert len(result) == 193 assert "foobar" not in config.DEFAULT_SERVICE_PORTS94 assert "foobar" in result95 # FOOBAR_PORT cannot be parsed...
workers.py
Source:workers.py
1import os2import psutil3def get_worker_connections_count(worker_kind_name, default=50):4 """5 Returns the worker connections count for the gunicorn workers.6 """7 # Check for an override via an environment variable.8 override_value = os.environ.get("WORKER_CONNECTION_COUNT_" + worker_kind_name.upper())9 if override_value is not None:10 override_value = int(override_value)11 return override_value12 override_value = os.environ.get("WORKER_CONNECTION_COUNT")13 if override_value is not None:14 override_value = int(override_value)15 return override_value16 return default17def get_worker_count(worker_kind_name, multiplier, minimum=None, maximum=None):18 """19 Returns the number of gunicorn workers to run for the given worker kind, based on a combination20 of environment variable, multiplier, minimum (if any), and number of accessible CPU cores.21 """22 minimum = minimum or multiplier23 maximum = maximum or (multiplier * multiplier)24 # Check for a process-specific override via an environment variable.25 override_value = os.environ.get("WORKER_COUNT_" + worker_kind_name.upper())26 if override_value is not None:27 override_value = int(override_value)28 return max(override_value, minimum)29 # Check for a generic override via an environment variables30 override_value = os.environ.get("WORKER_COUNT")31 if override_value is not None:32 override_value = int(override_value)33 return max(override_value, minimum)34 # Load the number of CPU cores via affinity, and use that to calculate the35 # number of workers to run.36 p = psutil.Process(os.getpid())37 try:38 cpu_count = len(p.cpu_affinity())39 except AttributeError:40 # cpu_affinity isn't supported on this platform. Assume 2.41 cpu_count = 2...
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!!