Skip to content

Commit

Permalink
Merge pull request #3 from pharmaverse/ci-tests
Browse files Browse the repository at this point in the history
Add GitHub Actions workflow for CI tests
  • Loading branch information
nanxstats authored Jan 10, 2025
2 parents 81158fe + c92592f commit 8c9567c
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 16 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
on:
push:
branches:
- main
pull_request:
branches:
- main

name: CI Tests

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13"]
fail-fast: false

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 dependencies
run: |
# we are using the -e flag, so that code cov finds the source.
# this is not ideal, since installing an editable can technically
# differ from a normal install in surprising ways.
pip install -e '.[all]'
- name: Test with pytest
run: |
pip install pytest pytest-cov
pytest --cov=pkglite --cov-report=xml
# - name: Upload coverage reports to Codecov
# uses: codecov/codecov-action@v4
# with:
# name: "py${{ matrix.python-version }}"
# token: ${{ secrets.CODECOV_TOKEN }}

test-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Install dependencies
run: |
pip install -e '.[all]'
- name: Test with pytest
run: |
pip install pytest pytest-cov
pytest --cov=pkglite --cov-report=xml
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.12.6
3.13.1
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
]

requires-python = ">= 3.10"
Expand Down
4 changes: 3 additions & 1 deletion src/pkglite/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ def read_binary_content(file_path: str) -> str:
"""
with open(file_path, "rb") as f:
content = f.read().hex()
return "".join(f" {content[i:i + 128]}\n" for i in range(0, len(content), 128))
return "".join(
f" {content[i : i + 128]}\n" for i in range(0, len(content), 128)
)


def read_file_content(file_path: str, file_type: str) -> str:
Expand Down
45 changes: 32 additions & 13 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from pathlib import Path
from unittest.mock import patch, Mock

Expand Down Expand Up @@ -152,9 +153,11 @@ def test_use_command_multiple_dirs_with_force(mock_use, tmp_path):

def test_quiet_flag_propagation():
"""Test quiet flag propagation across all commands"""
with patch("pkglite.main.pack_impl") as mock_pack, patch(
"pkglite.main.unpack_impl"
) as mock_unpack, patch("pkglite.main.use_pkglite_impl") as mock_use:
with (
patch("pkglite.main.pack_impl") as mock_pack,
patch("pkglite.main.unpack_impl") as mock_unpack,
patch("pkglite.main.use_pkglite_impl") as mock_use,
):
runner.invoke(app, ["pack", "dir", "--quiet"])
assert mock_pack.call_args[1]["quiet"] is True

Expand All @@ -178,26 +181,42 @@ def test_quiet_flag_propagation():
assert mock_use.call_args[1]["quiet"] is True


def strip_ansi(text):
"""Remove ANSI escape codes from text"""
ansi_escape = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])")
return ansi_escape.sub("", text)


def test_help_messages():
"""Test help messages for all commands"""
result = runner.invoke(app, ["--help"])
clean_output = strip_ansi(result.stdout)
assert result.exit_code == 0
assert "pkglite" in result.stdout
assert "pkglite" in clean_output

result = runner.invoke(app, ["pack", "--help"])
clean_output = strip_ansi(result.stdout)
assert result.exit_code == 0
assert "Pack files" in result.stdout
assert "--output-file -o" in result.stdout
assert "--quiet -q" in result.stdout
assert "Pack files" in clean_output
assert "--output-file" in clean_output
assert "-o" in clean_output
assert "--quiet" in clean_output
assert "-q" in clean_output

result = runner.invoke(app, ["unpack", "--help"])
clean_output = strip_ansi(result.stdout)
assert result.exit_code == 0
assert "Unpack files" in result.stdout
assert "--output-dir -o" in result.stdout
assert "--quiet -q" in result.stdout
assert "Unpack files" in clean_output
assert "--output-dir" in clean_output
assert "-o" in clean_output
assert "--quiet" in clean_output
assert "-q" in clean_output

result = runner.invoke(app, ["use", "--help"])
clean_output = strip_ansi(result.stdout)
assert result.exit_code == 0
assert "pkgliteignore" in result.stdout
assert "--force -f" in result.stdout
assert "--quiet -q" in result.stdout
assert "pkgliteignore" in clean_output
assert "--force" in clean_output
assert "-f" in clean_output
assert "--quiet" in clean_output
assert "-q" in clean_output
2 changes: 1 addition & 1 deletion tests/test_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ def test_load_ignore_matcher(tmp_path):
matcher = load_ignore_matcher(str(test_dir))

assert matcher(str(test_dir / "test.pyc")) is True
assert matcher(str(test_dir / "__pycache__/module.py")) is True
assert matcher(str(test_dir / "__pycache__" / "module.py")) is True
assert matcher(str(test_dir / ".git/")) is False

0 comments on commit 8c9567c

Please sign in to comment.