Best Python code snippet using autotest_python
test_utils.py
Source: test_utils.py
...20import socket21import sys22import threading23import tensorflow as tf24def _do_redirect(handler, location):25 handler.send_response(301)26 handler.send_header("Location", location)27 handler.end_headers()28def _do_documentation(handler):29 handler.send_response(200)30 handler.end_headers()31 handler.wfile.write(b"Here is some documentation.")32def start_smart_module_server(download_url):33 """Serve documentation and module requests at the same URL."""34 # pylint:disable=g-import-not-at-top35 if sys.version_info[0] == 2:36 import BaseHTTPServer37 import SimpleHTTPServer38 import urlparse39 class HTTPServerV6(BaseHTTPServer.HTTPServer):40 address_family = socket.AF_INET641 class RequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):42 def do_GET(self):43 parsed_url = urlparse.urlparse(self.path)44 qs = urlparse.parse_qs(parsed_url.query)45 if qs["tf-hub-format"][0] == "compressed":46 _do_redirect(self, download_url)47 else:48 _do_documentation(self)49 server = HTTPServerV6(("", 0), RequestHandler)50 server_port = server.server_port51 else:52 import http.server53 import socketserver54 import urllib55 class RequestHandler(http.server.SimpleHTTPRequestHandler):56 def do_GET(self):57 parsed_url = urllib.parse.urlparse(self.path)58 qs = urllib.parse.parse_qs(parsed_url.query)59 if qs["tf-hub-format"][0] == "compressed":60 _do_redirect(self, download_url)61 else:62 _do_documentation(self)63 server = socketserver.TCPServer(("", 0), RequestHandler)64 _, server_port = server.server_address65 # pylint:disable=g-import-not-at-top66 thread = threading.Thread(target=server.serve_forever)67 thread.daemon = True68 thread.start()69 return server_port70def start_http_server(redirect=None):71 """Returns the port of the newly started HTTP server."""72 # Start HTTP server to serve TAR files.73 # pylint:disable=g-import-not-at-top74 if sys.version_info[0] == 2:75 import BaseHTTPServer76 import SimpleHTTPServer77 class HTTPServerV6(BaseHTTPServer.HTTPServer):78 address_family = socket.AF_INET679 class RedirectHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):80 def do_GET(self):81 _do_redirect(self, redirect)82 server = HTTPServerV6(("", 0), RedirectHandler if redirect else83 SimpleHTTPServer.SimpleHTTPRequestHandler)84 server_port = server.server_port85 else:86 import http.server87 import socketserver88 class RedirectHandler(http.server.SimpleHTTPRequestHandler):89 def do_GET(self):90 _do_redirect(self, redirect)91 server = socketserver.TCPServer(("", 0), RedirectHandler if redirect else92 http.server.SimpleHTTPRequestHandler)93 _, server_port = server.server_address94 # pylint:disable=g-import-not-at-top95 thread = threading.Thread(target=server.serve_forever)96 thread.daemon = True97 thread.start()98 return server_port99def test_srcdir():100 """Returns the path where to look for test data files."""101 if "test_srcdir" in tf.app.flags.FLAGS:102 return tf.app.flags.FLAGS["test_srcdir"].value103 elif "TEST_SRCDIR" in os.environ:104 return os.environ["TEST_SRCDIR"]...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.
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!!