Best Python code snippet using localstack_python
test_config.py
Source: test_config.py
...12 os.environ.clear()13 os.environ.update(old)14class TestParseServicePorts:15 def test_returns_default_service_ports(self):16 result = config.parse_service_ports()17 assert result == config.DEFAULT_SERVICE_PORTS18 def test_with_service_subset(self):19 with temporary_env({"SERVICES": "s3,sqs"}):20 result = config.parse_service_ports()21 assert len(result) == 222 assert "s3" in result23 assert "sqs" in result24 assert result["s3"] == 456625 assert result["sqs"] == 456626 def test_custom_service_default_port(self):27 with temporary_env({"SERVICES": "foobar"}):28 result = config.parse_service_ports()29 assert len(result) == 130 assert "foobar" not in config.DEFAULT_SERVICE_PORTS31 assert "foobar" in result32 # foobar is not a default service so it is assigned 033 assert result["foobar"] == 034 def test_custom_port_mapping(self):35 with temporary_env({"SERVICES": "foobar", "FOOBAR_PORT": "1234"}):36 result = config.parse_service_ports()37 assert len(result) == 138 assert "foobar" not in config.DEFAULT_SERVICE_PORTS39 assert "foobar" in result40 assert result["foobar"] == 123441 def test_custom_illegal_port_mapping(self):42 with temporary_env({"SERVICES": "foobar", "FOOBAR_PORT": "asdf"}):43 result = config.parse_service_ports()44 assert len(result) == 145 assert "foobar" not in config.DEFAULT_SERVICE_PORTS46 assert "foobar" in result47 # FOOBAR_PORT cannot be parsed48 assert result["foobar"] == 049 def test_custom_port_mapping_in_services_env(self):50 with temporary_env({"SERVICES": "foobar:1235"}):51 result = config.parse_service_ports()52 assert len(result) == 153 assert "foobar" not in config.DEFAULT_SERVICE_PORTS54 assert "foobar" in result55 # FOOBAR_PORT cannot be parsed56 assert result["foobar"] == 123557class TestLoadConfigFile:58 def test_with_existing_file(self, tmp_path):59 test_config = '{"foo": "bar", "why": 42}'60 tmp_file = tmp_path / "config.json"61 tmp_file.write_text(test_config)62 cfg = config.load_config_file(str(tmp_file))63 assert len(cfg) == 264 assert "foo" in cfg65 assert "why" in cfg...
test_service_ports.py
Source: test_service_ports.py
1import pytest2from ai.backend.common.service_ports import parse_service_ports3def test_parse_service_ports():4 result = parse_service_ports('')5 assert len(result) == 06 result = parse_service_ports('a:http:1230')7 assert len(result) == 18 assert result[0] == {9 'name': 'a', 'protocol': 'http',10 'container_ports': (1230,),11 'host_ports': (None,),12 }13 result = parse_service_ports('a:tcp:[5000,5005]')14 assert len(result) == 115 assert result[0] == {16 'name': 'a', 'protocol': 'tcp',17 'container_ports': (5000, 5005),18 'host_ports': (None, None),19 }20 result = parse_service_ports('a:tcp:[1230,1240,9000],x:http:3000,t:http:[5000,5001]')21 assert len(result) == 322 assert result[0] == {23 'name': 'a', 'protocol': 'tcp',24 'container_ports': (1230, 1240, 9000),25 'host_ports': (None, None, None),26 }27 assert result[1] == {28 'name': 'x', 'protocol': 'http',29 'container_ports': (3000,),30 'host_ports': (None,),31 }32 assert result[2] == {33 'name': 't', 'protocol': 'http',34 'container_ports': (5000, 5001),35 'host_ports': (None, None),36 }37def test_parse_service_ports_invalid_values():38 with pytest.raises(ValueError, match="Unsupported"):39 parse_service_ports('x:unsupported:1234')40 with pytest.raises(ValueError, match="smaller than"):41 parse_service_ports('x:http:65536')42 with pytest.raises(ValueError, match="larger than"):43 parse_service_ports('x:http:1000')44 with pytest.raises(ValueError, match="Invalid format"):45 parse_service_ports('x:http:-1')46 with pytest.raises(ValueError, match="Invalid format"):47 parse_service_ports('abcdefg')48 with pytest.raises(ValueError, match="Invalid format"):49 parse_service_ports('x:tcp:1234,abcdefg')50 with pytest.raises(ValueError, match="Invalid format"):51 parse_service_ports('abcdefg,x:tcp:1234')52 with pytest.raises(ValueError, match="already used"):53 parse_service_ports('x:tcp:1234,y:tcp:1234')54 with pytest.raises(ValueError, match="reserved"):55 parse_service_ports('y:tcp:7711,x:tcp:2200')56def test_parse_service_ports_custom_exception():57 with pytest.raises(ZeroDivisionError):58 parse_service_ports('x:unsupported:1234', ZeroDivisionError)59def test_parse_service_ports_ignore_pty():60 result = parse_service_ports('x:pty:1234,y:tcp:1235')61 assert len(result) == 1...
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!!