From 18aeecb91e1c1addd2c6d27e447fa20e9bced93b Mon Sep 17 00:00:00 2001 From: phernandez Date: Sun, 24 Nov 2024 15:17:55 -0600 Subject: [PATCH] add github actions to run tests --- .github/workflows/test.yml | 36 ++++++++++++++++++++++++++++++++++++ pyproject.toml | 3 +++ tests/test_git.py | 16 +++++++++++++--- tests/test_github.py | 1 + tests/test_integration.py | 1 + 5 files changed, 54 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e69de29..7b26a3f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -0,0 +1,36 @@ +# .github/workflows/test.yml +name: Tests + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.12'] + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install uv + run: | + curl -LsSf https://astral.sh/uv/install.sh | sh + echo "$HOME/.local/bin" >> $GITHUB_PATH + + - name: Install dependencies + run: | + uv pip install '.[dev]' + + - name: Run tests + run: | + pytest tests/ -v -m "not integration" \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 5dafcd9..90ed37c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,3 +56,6 @@ python_files = [ ] addopts = "-ra -q" +markers = [ + "integration: marks tests as integration tests" +] diff --git a/tests/test_git.py b/tests/test_git.py index c850a8b..a85a1ed 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -8,8 +8,14 @@ @pytest.fixture def git_repo(tmp_path): """Create a temporary git repository with initial commit.""" - # Create and init repo + # Create source and remote repo paths repo_path = tmp_path / "test_repo" + remote_path = tmp_path / "remote_repo" + + # Initialize remote repo first (bare repository) + remote_repo = pygit2.init_repository(str(remote_path), bare=True) + + # Create and init source repo repo_path.mkdir() repo = pygit2.init_repository(str(repo_path)) @@ -29,6 +35,9 @@ def git_repo(tmp_path): [] # No parent commits ) + # Add remote + repo.remotes.create("origin", str(remote_path)) + # Create and return Git instance config = GitConfig(repo_path) return Git(config) @@ -39,10 +48,11 @@ def test_create_hello_world(git_repo): from basic_factory.git import create_hello_world # Create hello world files - create_hello_world(git_repo) + create_hello_world(git_repo, stay_on_branch=True) # Stay on the new branch # Verify branch was created - assert git_repo.repo.head.shorthand == "feature/hello-world" + current_branch = git_repo.get_current_branch() + assert current_branch == "feature/hello-world" # Verify files exist hello_path = git_repo.config.repo_path / "src/basic_factory/hello.py" diff --git a/tests/test_github.py b/tests/test_github.py index c78c409..be01035 100644 --- a/tests/test_github.py +++ b/tests/test_github.py @@ -3,6 +3,7 @@ import pytest from basic_factory.github import GitHubConfig, GitHubOps +pytestmark = pytest.mark.integration @pytest.fixture def github_ops(): diff --git a/tests/test_integration.py b/tests/test_integration.py index 3a3795b..3351ed9 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -3,6 +3,7 @@ import pytest from basic_factory.git import Git, GitConfig +pytestmark = pytest.mark.integration @pytest.fixture def working_repo():