Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add coverage in CI #92

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
35 changes: 19 additions & 16 deletions .github/workflows/ci-mac-os.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,48 +48,49 @@ jobs:
- name: Update $PATH
# run: echo ::add-path::/Library/TeX/texbin # depreciated
run: echo "/Library/TeX/texbin" >> $GITHUB_PATH

- name: Add fonts (required by moodle2amc tests)
run: |
# xstring is just required for testing --includestyles
sudo tlmgr update --self
sudo tlmgr install --verify-repo=none collection-fontsrecommended bophook xstring

sudo tlmgr install collection-fontsrecommended bophook xstring --verify-repo=none
- name: Test latexml
run: |
# add --strict flag to be more strict in error catching
latexml --noparse --nocomment --strict --path=./amc2moodle/amc2moodle --dest=./out.xml ./amc2moodle/tests/payload_test_amc2moodle/QCM.tex

latexml --noparse --nocomment --strict --path=./amc2moodle/amc2moodle --dest=./out.xml ./amc2moodle/tests/payload_test_amc2moodle/QCM.tex
- name: Install amc2moodle
run: |
# add -e to have write access for test. TODO : change with temp file
pip install -e .

pip install -e .[test]
- name: Test amc2moodle
run: |
python -m amc2moodle.tests.test_amc2moodle

pytest --pyargs amc2moodle.tests.test_amc2moodle
- name: Test moodle2amc
run: |
# add automultiplechoice.sty local copy to LaTeX PATH (for this step)
# export TEXINPUTS=.:./tests/payload_test_amc2moodle/:$TEXINPUTS (during tests, automultiplechoice.sty is copied in the temporary test folder )
python -m amc2moodle.tests.test_moodle2amc
pytest --pyargs amc2moodle.tests.test_moodle2amc
- name: Test text parser
run: |
python -m amc2moodle.tests.test_utils_text
pytest --pyargs amc2moodle.tests.test_utils_text
- name: Test calculated questions parsers
run: |
python -m amc2moodle.tests.test_utils_calculatedParser

pytest --pyargs amc2moodle.tests.test_utils_calculatedParser


# Store output files
# amc2moodle
- name: Archive XML test output of amc2moodle (without tikz)
if: ${{ always() }}
uses: actions/upload-artifact@main
with:
name: test_notikz_${{ matrix.python-version }}
path: output_tests/test_notikz.xml

path: output_tests/test_notikz.xml
- name: Archive XML test output of amc2moodle (with tikz)
if: ${{ always() }}
uses: actions/upload-artifact@main
Expand All @@ -102,10 +103,12 @@ jobs:
run: |
mkdir moodle-bank-exemple-output
mv output_tests/test_moodle-bank-exemple.* moodle-bank-exemple-output/

- name: Archive LaTeX test output (moodle2amc)
if: ${{ always() }}
uses: actions/upload-artifact@main
with:
name: test_moodle-bank-exemple_${{ matrix.python-version }}
path: moodle-bank-exemple-output


33 changes: 27 additions & 6 deletions .github/workflows/ci-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,46 @@ jobs:
# add --strict flag to be more strict in error catching
latexml --noparse --nocomment --strict --path=./amc2moodle/amc2moodle --dest=./out.xml ./amc2moodle/tests/payload_test_amc2moodle/QCM.tex

- name: Install amc2moodle
- name: Install amc2moodle (and hatch for coverage)
run: |
# add -e to have write access for test. TODO : change with temp file
pip install -e .
pip install hatch
pip install -e .[test]

- name: Test amc2moodle
run: |
python -m amc2moodle.tests.test_amc2moodle
pytest --pyargs amc2moodle.tests.test_amc2moodle
- name: Test moodle2amc
run: |
# add automultiplechoice.sty local copy to LaTeX PATH (for this step)
# export TEXINPUTS=.:./tests/payload_test_amc2moodle/:$TEXINPUTS (during tests, automultiplechoice.sty is copied in the temproary test folder )
python -m amc2moodle.tests.test_moodle2amc
pytest --pyargs amc2moodle.tests.test_moodle2amc
- name: Test text parser
run: |
python -m amc2moodle.tests.test_utils_text
pytest --pyargs amc2moodle.tests.test_utils_text
- name: Test calculated questions parsers
run: |
python -m amc2moodle.tests.test_utils_calculatedParser
pytest --pyargs amc2moodle.tests.test_utils_calculatedParser
- name: Generate coverage report
if: ${{ matrix.python-version == '3.13' }}
run: |
hatch test --cover
hatch run coverage xml
- name: Creating coverage folder
if: ${{ matrix.python-version == '3.13' }}
run: |
mkdir -p coverage
- name: Coverage Bagdge
if: ${{ matrix.python-version == '3.13' }}
uses: tj-actions/coverage-badge-py@v2
with:
output: coverage/coverage.svg
- name: Publish coverage report to coverage-badge branch
if: ${{ matrix.python-version == '3.13' }}
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: coverage-badge
folder: coverage

# Store output files
# amc2moodle
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/coverage.yml.bck
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Coverage

on:
push:
branches: ["*"]
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.13'
cache: 'pip'
- name: Install package with optional dependencies
run: |
pip install .[test]
- name: Test with hatch-test/pytest
run: |
hatch test
hatch run coverage xml

- name: Creating coverage folder
run: |
mkdir -p coverage
- name: Coverage Bagdge
uses: tj-actions/coverage-badge-py@v2
with:
output: coverage/coverage.svg
- name: Publish coverage report to coverage-badge branch
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: coverage-badge
folder: coverage
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# `amc2moodle`
[![pypi release](https://img.shields.io/pypi/v/amc2moodle.svg)](https://pypi.org/project/amc2moodle/) [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) ![CI-Ubuntu](https://github.com/nennigb/amc2moodle/workflows/CI-Ubuntu/badge.svg) ![CI-Mac-OS](https://github.com/nennigb/amc2moodle/workflows/CI-mac-os/badge.svg)
[![pypi release](https://img.shields.io/pypi/v/amc2moodle.svg)](https://pypi.org/project/amc2moodle/) [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) ![code coverage](https://raw.githubusercontent.com/nennigb/amc2moodle/coverage-badge/coverage.svg?raw=true) ![CI-Ubuntu](https://github.com/nennigb/amc2moodle/workflows/CI-Ubuntu/badge.svg) ![CI-Mac-OS](https://github.com/nennigb/amc2moodle/workflows/CI-mac-os/badge.svg)

`amc2moodle`, is a suite of tools to convert multiple choice questionnaires (MCQ)
- **from** [auto-multiple-choice](https://www.auto-multiple-choice.net) LaTeX quizzes **to** [moodle questions (XML format)](https://docs.moodle.org/38/en/Moodle_XML_format), see details in the [amc2moodle README file](amc2moodle/amc2moodle/README.md). Since `amc2moodle` use [LaTeXML](https://dlmf.nist.gov/LaTeXML/) to **expands LaTeX commands**, it could be _easily_ adapted to support most of LaTeX capabilities.
Expand Down
12 changes: 10 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,18 @@ default-args = ["amc2moodle/tests"]

[tool.coverage.run]
branch = true
command_line = "-m unittest discover -s amc2moodle/tests/"
command_line = "-m pytest -s amc2moodle/tests/"

[tool.coverage.html]
directory = "coverage_html_report"
show_contexts = true
directory = "reportcov"

[tool.coverage.xml]
output = "reportcov/report.xml"

[tool.coverage.report]
show_missing = true
fail_under = 80

[tool.ruff]
# Allow lines to be as long as 120.
Expand Down
Loading