Best Python code snippet using tempest_python
link_checker.py
Source: link_checker.py
...118 if not urlparse(url).scheme:119 normalized_links[i] = urljoin("http:/​/​", "/​/​" + url)120 return normalized_links121 @staticmethod122 def _wait_for_validation(url):123 """Return the status of a url as dict {`url`, `status`, `reason`}"""124 host, path = urlsplit(url)[1:3]125 connection = httplib.HTTPConnection(host)126 status, reason = None, None127 try:128 connection.request("HEAD", path) 129 except gaierror: # bad host130 pass131 else: 132 response = connection.getresponse() # wait for response133 status, reason = response.status, response.reason134 return {'url': url, 'status': status, 'reason': reason}135 @staticmethod136 def _check_links_threaded(url_list, timeout):137 """Employeer which starts worker threads to check urls."""138 url_queue = Queue()139 result_hash = {} 140 map(url_queue.put_nowait, url_list)141 num_urls = len(url_list)142 timer = _WorkerTimer(num_urls, timeout)143 num_threads = max(min(NUM_WORKER_THREADS, num_urls), 1)144 for _ in xrange(num_threads):145 LinkChecker._start_link_worker(url_queue, result_hash, timer)146 timer.start_workers_and_wait()147 for url in set(url_list).difference(result_hash.keys()):148 # if the url timedout then give None for `status` and `reason`149 result_hash[url] = result_hash.get(url, {'url': url, 150 'status': None,151 'reason':None })152 return result_hash 153 @staticmethod154 def _start_link_worker(url_queue, result_hash, timer):155 """Worker thread which does work on elements of `url_queue` and places156 results on `done_queue` using `timer` for synchronization and timing."""157 def hard_worker():158 """Contionusly waits for work and performs work if available and159 time left."""160 timer.worker_wait()161 while True:162 try:163 url = url_queue.get_nowait()164 except EmptyQueue: 165 break 166 ret_val = LinkChecker._wait_for_validation(url)167 if not timer.work_has_finished(): 168 timer.worker_task_done()169 result_hash[ret_val['url']] = ret_val170 else: 171 break172 thread = Thread(target=hard_worker)173 thread.setDaemon(True)174 thread.start()175if __name__ == '__main__':176 from time import time as now177 lc = LinkChecker()178 # short list179 url_list = ["http:/​/​thinkgeek.com", "http:/​/​sonothere.com", "http:/​/​gmail.com"]180 print "testing list of length %s" % len(url_list)...
Check out the latest blogs from LambdaTest on this topic:
ChatGPT broke all Internet records by going viral in the first week of its launch. A million users in 5 days are unprecedented. A conversational AI that can answer natural language-based questions and create poems, write movie scripts, write social media posts, write descriptive essays, and do tons of amazing things. Our first thought when we got access to the platform was how to use this amazing platform to make the lives of web and mobile app testers easier. And most importantly, how we can use ChatGPT for automated testing.
Hey LambdaTesters! We’ve got something special for you this week. ????
API (Application Programming Interface) is a set of definitions and protocols for building and integrating applications. It’s occasionally referred to as a contract between an information provider and an information user establishing the content required from the consumer and the content needed by the producer.
People love to watch, read and interact with quality content — especially video content. Whether it is sports, news, TV shows, or videos captured on smartphones, people crave digital content. The emergence of OTT platforms has already shaped the way people consume content. Viewers can now enjoy their favorite shows whenever they want rather than at pre-set times. Thus, the OTT platform’s concept of viewing anything, anytime, anywhere has hit the right chord.
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!!