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)
Example #2
0
    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)