How to use parse_service_ports method in localstack

Best Python code snippet using localstack_python

test_config.py

Source:test_config.py Github

copy

Full Screen

...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...

Full Screen

Full Screen

test_service_ports.py

Source:test_service_ports.py Github

copy

Full Screen

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...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful