githrun

A CLI tool to run Python scrip...
Log | Files | Refs | README | LICENSE

test_githrun.py (4517B)


      1 import os
      2 import sys
      3 import shutil
      4 import githrun
      5 from rich.console import Console
      6 from rich.panel import Panel
      7 
      8 console = Console()
      9 
     10 # --- CONFIGURATION ---
     11 # We use the repo you mentioned in the chat for testing
     12 TEST_REPO = "https://github.com/notamitgamer/adpkg"
     13 TEST_FILE = "https://github.com/notamitgamer/adpkg/blob/main/test1.py"
     14 TEST_FOLDER = "https://github.com/notamitgamer/adpkg/tree/main/"
     15 DOWNLOAD_TARGET = "test_download_artifact.py"
     16 
     17 def print_header(title):
     18     console.print(Panel(f"[bold white]{title}[/bold white]", style="bold blue"))
     19 
     20 def test_cli_command(cmd, description):
     21     console.print(f"\n[bold cyan]🔹 Testing CLI: {description}[/bold cyan]")
     22     console.print(f"[dim]Command: {cmd}[/dim]")
     23     
     24     exit_code = os.system(cmd)
     25     
     26     if exit_code == 0:
     27         console.print("[bold green]✔ Passed[/bold green]")
     28         return True
     29     else:
     30         console.print("[bold red]✘ Failed[/bold red]")
     31         return False
     32 
     33 def test_python_api():
     34     print_header("Testing Python Source Code API")
     35     
     36     # 1. Search Repository
     37     console.print("\n[bold cyan]🔹 API: githrun.search_repository()[/bold cyan]")
     38     try:
     39         results = githrun.search_repository(TEST_REPO, "test1.py")
     40         if results:
     41             console.print(f"[green]✔ Success: Found {len(results)} matches.[/green]")
     42             for item in results[:1]: # Show first match
     43                 console.print(f"   Found: {item['path']} ({item['raw_url']})")
     44         else:
     45             console.print("[yellow]âš  Warning: No results found (API limit might be hit).[/yellow]")
     46     except Exception as e:
     47         console.print(f"[bold red]✘ Error:[/bold red] {e}")
     48 
     49     # 2. Get Folder Contents
     50     console.print("\n[bold cyan]🔹 API: githrun.get_folder_contents()[/bold cyan]")
     51     try:
     52         items = githrun.get_folder_contents(TEST_FOLDER)
     53         if items:
     54             console.print(f"[green]✔ Success: Fetched {len(items)} items from folder.[/green]")
     55         else:
     56             console.print("[yellow]âš  Warning: Folder appears empty or API error.[/yellow]")
     57     except Exception as e:
     58         console.print(f"[bold red]✘ Error:[/bold red] {e}")
     59 
     60     # 3. Download File
     61     console.print("\n[bold cyan]🔹 API: githrun.download_file()[/bold cyan]")
     62     try:
     63         path = githrun.download_file(TEST_FILE, output_path="api_download_test.py")
     64         if os.path.exists(path):
     65             console.print(f"[green]✔ Success: File downloaded to {path}[/green]")
     66             os.remove(path) # Cleanup
     67         else:
     68             console.print("[bold red]✘ Failed: File not found after download call.[/bold red]")
     69     except Exception as e:
     70         console.print(f"[bold red]✘ Error:[/bold red] {e}")
     71 
     72 def main():
     73     # Ensure we are in the right directory or package is installed
     74     if not shutil.which("githrun"):
     75         console.print("[bold red]CRITICAL: 'githrun' command not found.[/bold red]")
     76         console.print("Please run [bold]pip install .[/bold] in the root directory first.")
     77         return
     78 
     79     print_header("Starting githrun Feature Tests")
     80 
     81     # --- CLI TESTS ---
     82     
     83     # 1. Help Command
     84     test_cli_command("githrun --help", "Help Menu")
     85 
     86     # 2. Run Command (Non-interactive)
     87     # --yes skips the confirmation prompt
     88     test_cli_command(f"githrun run {TEST_FILE} --yes", "Run Remote Script")
     89 
     90     # 3. Inspect Mode
     91     # Should print code but not run it
     92     test_cli_command(f"githrun run {TEST_FILE} --inspect", "Inspect Code")
     93 
     94     # 4. Show Folder
     95     test_cli_command(f"githrun show {TEST_FOLDER}", "Show Folder Contents")
     96 
     97     # 5. Find File (Non-interactive)
     98     # Typer converts `interactive=True` to a flag `--no-interactive`
     99     test_cli_command(f"githrun find {TEST_REPO} test --no-interactive", "Find File")
    100 
    101     # 6. Download
    102     test_cli_command(f"githrun download {TEST_FILE} -o {DOWNLOAD_TARGET}", "Download File")
    103     if os.path.exists(DOWNLOAD_TARGET):
    104         console.print("[dim]   Verifying file existence... OK (Deleting now)[/dim]")
    105         os.remove(DOWNLOAD_TARGET)
    106 
    107     # 7. Bookmarks
    108     test_cli_command(f"githrun bookmark add test-bm {TEST_FILE}", "Add Bookmark")
    109     test_cli_command("githrun bookmark list", "List Bookmarks")
    110     test_cli_command("githrun run test-bm --yes", "Run from Bookmark")
    111 
    112     # --- API TESTS ---
    113     test_python_api()
    114 
    115     print_header("Test Suite Completed")
    116 
    117 if __name__ == "__main__":
    118     try:
    119         main()
    120     except KeyboardInterrupt:
    121         console.print("\n[bold red]Tests aborted by user.[/bold red]")
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror