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 testing workflow #41

Merged
merged 12 commits into from
Aug 26, 2024
50 changes: 50 additions & 0 deletions .github/workflows/standard.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: "Standard"
run-name: ${{ github.run_number }} [${{ github.actor }}] on ${{ github.ref_name }}

on:
pull_request:
branches:
- main
push:
branches:
- main
schedule:
- cron: '0 0 * * *' # Once a day at 12am UTC
workflow_dispatch:

jobs:
# ----------------------------------------------------------------------
validate:
name: Validate
runs-on: ubuntu-latest

strategy:
fail-fast: false

matrix:
python_version:
- "3.12"
- "3.11"
- "3.10"

env:
COLUMNS: "200"
SIMULATE_TERMINAL_CAPABILITIES_SUPPORTS_COLORS: "1"
PYTHONIOENCODING: "UTF-8"

permissions: {}

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Test with pytest
run: |
pip install pytest pytest-cov
pytest tests/test_generation.py --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html --subset-percentage 0.05
27 changes: 27 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import random


def pytest_addoption(parser):
parser.addoption(
"--subset-percentage",
action="store",
default=None,
help="Specify the percentage of tests to run as a subset (e.g., 0.3 for 30%)",
)


def pytest_collection_modifyitems(config, items):
subset_percentage = config.getoption("--subset-percentage")

# If the subset percentage is provided, apply it
if subset_percentage is not None:
subset_percentage = float(subset_percentage)

# Shuffle the test cases
random.shuffle(items)

# Calculate the number of tests to run based on percentage
subset_count = int(len(items) * subset_percentage)

# Select a subset of tests
items[:] = items[:subset_count]