Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/gpt_copy/gpt_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
from pathlib import Path
from typing import TextIO
import importlib.metadata

import click
import pygit2
Expand Down Expand Up @@ -701,6 +702,7 @@ def write_output(


@click.command()
@click.version_option(version=importlib.metadata.version("gpt_copy"))
@click.argument(
"root_path",
type=click.Path(
Expand Down
47 changes: 47 additions & 0 deletions tests/test_version_option.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python3

import subprocess
import importlib.metadata
import sys


def test_version_option_via_console_script():
"""Test that --version option works when called via the console script."""
# Get the expected version from package metadata
expected_version = importlib.metadata.version("gpt_copy")

# Test the --version option via console script
result = subprocess.run(
["gpt-copy", "--version"],
capture_output=True,
text=True
)

# Verify exit code is 0
assert result.returncode == 0, f"Expected exit code 0, got {result.returncode}"

# Verify the output contains the version
expected_output = f"gpt-copy, version {expected_version}\n"
assert result.stdout == expected_output, f"Expected '{expected_output}', got '{result.stdout}'"

# Verify stderr is empty
assert result.stderr == "", f"Expected empty stderr, got '{result.stderr}'"


def test_version_consistent_with_pyproject():
"""Test that the version matches what's defined in pyproject.toml."""
# Get the version from package metadata
package_version = importlib.metadata.version("gpt_copy")

# Read the version from pyproject.toml (simple check)
import tomllib
from pathlib import Path
pyproject_path = Path(__file__).parent.parent / "pyproject.toml"

with open(pyproject_path, "rb") as f:
pyproject_data = tomllib.load(f)

pyproject_version = pyproject_data["project"]["version"]

# Verify they match
assert package_version == pyproject_version, f"Package version '{package_version}' doesn't match pyproject.toml version '{pyproject_version}'"