Best Python code snippet using autotest_python
udp.py
Source:udp.py  
...30        self.__ns = ns31        self.__socket = None32        self.__sending = False33        self.__metrics = {}34        self.__endpoints = self._parse_hosts(hosts)35        self.__add_metric(metrics.HeartBeat)36    @staticmethod37    def _parse_hosts(hosts):38        endpoints = list()39        for host_str in hosts.split(","):40            if ":" in host_str:41                host, port = host_str.split(":", 1)42                port = int(port)43            else:44                host, port = host_str, 200345            if not isinstance(host, str):46                host = host.decode()47            endpoints.append((host, port))48        return frozenset(endpoints)49    @property50    def hosts(self):51        return self.__endpoints52    @hosts.setter53    @LOCK54    def hosts(self, hosts):55        self.__endpoints = self._parse_hosts(hosts)56    @property57    def ns(self):58        return self.__ns59    @ns.setter60    def ns(self, ns):61        if ns.startswith('.'):62            raise ValueError("NameSpace mustn't starts with the dot.")63        if ns.endswith('.'):64            raise ValueError("NameSpace mustn't ends with the dot.")65        if re.match('^[\w\d\._\-]+$', ns) is None:66            raise ValueError("NameSpace mustn't contain special chars (except '_', '-')")67        if bool(list(filter(lambda x: not x, ns.split('.')))):68            raise ValueError("Namespace must contain chars after dots.")69        self.__ns = ns...__init__.py
Source:__init__.py  
...62        except Exception as err:63            breakpoint() # get exception class64            raise NetmapParseError("", (err,))65        return host66    def _parse_hosts(hosts):67        if isinstance(hosts, (list, tuple, iter)):68            return [_parse_hosts(host)69                    for host in hosts]70        if isinstance(hosts, (str,)):71            pass72    def _coerce_ports(port_or_ports):73        ports = None74        if isinstance(port_or_ports, int):75            ports = [port_or_ports]76        if isinstance(port_or_ports, (list, tuple, set,)):77            ports = list(port_or_ports)78            if not all([isinstance(p, int) for p in ports]):79                raise NetmapParseError(80                    "recursive port coercion unimpl"81                )82        if ports is None:83            raise NetmapParseError()84        return ports85    single_host = None86    try:87        single_host = _parse_host(host_or_hosts)88    except NetmapParseError:89        pass90    if single_host is not None:91        hosts = [single_host]92    else:93        hosts = _parse_hosts(host_or_hosts)94    rv = {}95    for host in hosts:96        print("scanning host", host)97        single_host_res = _port_scan_single_host(host,98                                                 # ports,99                                                 _coerce_ports(ports),100                                                 )101        rv.update(**{str(host): single_host_res})102    breakpoint()...test_etcd_driver.py
Source:test_etcd_driver.py  
...15class TestEtcdDB(tests_base.BaseTestCase):16    def test_parse_none(self):17        fake_host = []18        expected = ()19        output = etcd_db_driver._parse_hosts(fake_host)20        self.assertEqual(expected, output)21    def test_parse_empty(self):22        fake_host = [""]23        expected = ()24        output = etcd_db_driver._parse_hosts(fake_host)25        self.assertEqual(expected, output)26    def test_parse_one_host(self):27        fake_host = ['127.0.0.1:80']28        expected = (('127.0.0.1', 80),)29        output = etcd_db_driver._parse_hosts(fake_host)30        self.assertEqual(expected, output)31    def test_parse_multiple_hosts(self):32        fake_host = ['127.0.0.1:80', '192.168.0.1:8080']33        expected = (('127.0.0.1', 80), ('192.168.0.1', 8080))34        output = etcd_db_driver._parse_hosts(fake_host)35        self.assertEqual(expected, output)36    def test_parse_multiple_hosts_invalid(self):37        fake_host = ['127.0.0.1:80', '192.168.0.1']38        expected = (('127.0.0.1', 80),)39        with mock.patch.object(etcd_db_driver.LOG, 'error') as log_err:40            output = etcd_db_driver._parse_hosts(fake_host)41            self.assertEqual(expected, output)42            log_err.assert_called_once_with(...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!!
