class_docstr: Specify package indexes/Python package sources using Airflow connections.
class_docstr_tok: ["Specify","package","indexes\/Python","package","sources","using","Airflow","connections","."]
docstr: Test connection to package index url.
docstr_tok: ["Test","connection","to","package","index","url","."]
code: def test_connection(self) -> tuple[bool, str]:
      """Test connection to package index url."""
      conn_url = self.get_connection_url()
      proc = subprocess.run(
          [
              "pip",
              "search",
              "not-existing-test-package",
              "--no-input",
              "--index",
              conn_url,
          ],
          check=False,
          capture_output=True,
      )
      conn = self.get_connection(self.pi_conn_id)
      if proc.returncode not in [
          0,  # executed successfully, found package
          23,  # executed successfully, didn't find any packages
          #      (but we do not expect it to find 'not-existing-test-package')
      ]:
          return (
              False,
              f"Connection test to {conn.host} failed. Error: {str(proc.stderr)}",
          )
  
      return True, f"Connection to {conn.host} tested successfully!"
  
file_path: airflow/airflow/hooks/package_index.py
imports: from __future__ import annotations
  import subprocess
  from typing import Any
  from urllib.parse import quote, urlparse
  from airflow.hooks.base import BaseHook
label_desc: Use image node_id 6 for calling the PackageIndexHook obj's underlying member method code with example usage: obj.test_connection() and returns: True,  str, conn, str, False,  str, conn, str, str