def setUp(self): super(End2EndTest, self).setUp() # Set current directory to test temp directory where we can create # files and serve them through the HTTP server. os.chdir(self.get_temp_dir()) self.server_port = test_utils.start_http_server()
def test_load_v1(self): if (not hasattr(tf_v1.saved_model, "load_v2") or not tf_v1.executing_eagerly()): return # The test only applies when running V2 mode. full_module_path = self._full_module_path("half_plus_two_v1.tar.gz") os.chdir(os.path.dirname(full_module_path)) server_port = test_utils.start_http_server() handle = "http://localhost:%d/half_plus_two_v1.tar.gz" % server_port hub.load(handle)
def setUp(self): # Set current directory to test temp directory where we can create # files and serve them through the HTTP server. os.chdir(self.get_temp_dir()) # Create three temp files. self.files = ["file1", "file2", "file3"] for cur_file in self.files: with tf.gfile.GFile(cur_file, mode="w") as f: f.write(cur_file) # Write a dummy file so download server doesn't return 404. with tf.gfile.GFile("mock_module", mode="w") as f: f.write("module") # Create TAR files. tar = tarfile.open("mock_module.tar", "w") for name in self.files: tar.add(name) tar.close() # Create TGZ file tar = tarfile.open("mock_module.tar.gz", "w:gz") for name in self.files: tar.add(name) tar.close() self.server_port = test_utils.start_http_server() self.module_handle = ( "http://localhost:%d/mock_module.tar.gz" % self.server_port) self.redirect_server_port = test_utils.start_http_server( redirect="http://localhost:%d" % self.server_port) self.smart_server_port = test_utils.start_smart_module_server( self.module_handle) self.smart_handle = ( "http://localhost:%d/mock_module" % self.smart_server_port)
def setUp(self): # Set current directory to test temp directory where we can create # files and serve them through the HTTP server. os.chdir(self.get_temp_dir()) # Create three temp files. self.files = ["file1", "file2", "file3"] for cur_file in self.files: with tf.compat.v1.gfile.GFile(cur_file, mode="w") as f: f.write(cur_file) # Write a dummy file so download server doesn't return 404. with tf.compat.v1.gfile.GFile("mock_module", mode="w") as f: f.write("module") # Create TAR files. tar = tarfile.open("mock_module.tar", "w") for name in self.files: tar.add(name) tar.close() # Create TGZ file tar = tarfile.open("mock_module.tar.gz", "w:gz") for name in self.files: tar.add(name) tar.close() self.server_port = test_utils.start_http_server() self.module_handle = ("http://localhost:%d/mock_module.tar.gz" % self.server_port) self.redirect_server_port = test_utils.start_http_server( redirect="http://localhost:%d" % self.server_port) self.smart_server_port = test_utils.start_smart_module_server( self.module_handle) self.smart_handle = ("http://localhost:%d/mock_module" % self.smart_server_port)
def test_load_v1(self): if (not hasattr(tf_v1.saved_model, "load_v2") or not tf_v1.executing_eagerly()): return # The test only applies when running V2 mode. full_module_path = self._full_module_path("half_plus_two_v1.tar.gz") os.chdir(os.path.dirname(full_module_path)) server_port = test_utils.start_http_server() handle = "http://localhost:%d/half_plus_two_v1.tar.gz" % server_port try: hub.load(handle) self.fail("Loading v1 modules not support. Failure expected.") except NotImplementedError as e: self.assertEqual( str(e), "TF Hub module '%s' is stored using TF 1.x " "format. Loading of the module using hub.load() is not " "supported." % handle)
def setUp(self): # Set current directory to test temp directory where we can create # files and serve them through the HTTP server. os.chdir(self.get_temp_dir()) self.server_port = test_utils.start_http_server()