Skip to content

Commit

Permalink
python: improve gh tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reyammer committed Nov 4, 2024
1 parent c4649f8 commit 70f3453
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
30 changes: 17 additions & 13 deletions .github/workflows/python-test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ jobs:
unit-testing:
strategy:
matrix:
python-version: [ "3.8.x", "3.9.x", "3.10.x", "3.11.x", "3.12.x" ]
os: [ "ubuntu-latest", "macos-latest" ]
# TODO: add windows, ubuntu:20.04
# python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
# os: [ "ubuntu-latest", "macos-latest", "windows-latest" ]
python-version: [ "3.8" ]
os: [ "ubuntu-latest" ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # pin@v4
Expand All @@ -39,38 +40,41 @@ jobs:

- name: Install all projects dependencies (with the requested python version)
working-directory: python
run: uv sync --python $(which python3) --all-extras --dev
run: uv sync --python ${{ matrix.python-version }} --all-extras --dev

- name: Print python version
working-directory: python
run: uv run --python ${{ matrix.python-version }} python --version

- name: Run ruff check
working-directory: python
run: uv run --python $(which python3) ruff check --verbose
run: uv run --python ${{ matrix.python-version }} ruff check --verbose

- name: Run ruff format --check
working-directory: python
run: uv run --python $(which python3) ruff format --check --verbose
run: uv run --python ${{ matrix.python-version }} ruff format --check --verbose

- name: Run mypy
working-directory: python
run: uv run --python $(which python3) mypy src/magika tests
run: uv run --python ${{ matrix.python-version }} mypy src/magika tests

- name: Run the python tests suite
working-directory: python
run: uv run --python $(which python3) pytest tests -m "not slow"
run: uv run --python ${{ matrix.python-version }} pytest tests -m "not slow"

- name: Run magika --version
working-directory: python
run: uv run magika --version
run: uv run --python ${{ matrix.python-version }} magika --version
shell: bash # Allows for cross-platform

- name: Run magika with tests_data
working-directory: python
# TODO(https://github.com/google/magika/issues/780): Remove "grep || exit 1" when fixed.
run: '(uv run magika -r ../tests_data/basic | grep "code\.asm.*Assembly") || exit 1'
run: uv run --python ${{ matrix.python-version }} magika -r ../tests_data/basic

- name: Run "magika cli" quick tests
working-directory: python
run: uv run scripts/run_quick_test_magika_cli.py
run: uv run --python ${{ matrix.python-version }} scripts/run_quick_test_magika_cli.py

- name: Run "magika module" quick tests
working-directory: python
run: uv run scripts/run_quick_test_magika_module.py
run: uv run --python ${{ matrix.python-version }} scripts/run_quick_test_magika_module.py
8 changes: 7 additions & 1 deletion python/scripts/run_quick_test_magika_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,20 @@ def main() -> None:
basic_tests_dir = (
Path(__file__).parent.parent.parent / "tests_data" / "basic"
).resolve()
assert basic_tests_dir.is_dir()

p = subprocess.run(
["magika", "-r", "--label", str(basic_tests_dir)],
capture_output=True,
check=True,
text=True,
)

if p.returncode != 0:
print("ERROR: magika CLI exited with non-zero status.")
print(f"stdout:\n{p.stdout}\n" + "-" * 20)
print(f"stderr:\n{p.stderr}\n" + "-" * 20)
sys.exit(1)

assert p.stderr == ""

with_error = False
Expand Down

0 comments on commit 70f3453

Please sign in to comment.