-
-
Notifications
You must be signed in to change notification settings - Fork 1
146 lines (122 loc) · 4.46 KB
/
tests.yml
File metadata and controls
146 lines (122 loc) · 4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
name: Tests
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.8', '3.9', '3.10', '3.11']
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Cache pip dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r examples/requirements.txt
pip install -r examples/requirements-dev.txt
- name: Lint with pylint
run: |
pylint examples/ --fail-under=7.0 --disable=C0114,C0115,C0116
- name: Format check with black
run: |
black --check examples/
- name: Type check with mypy
run: |
mypy examples/ --ignore-missing-imports --disable-error-code=import
- name: Test example imports
run: |
python -c "import sys; sys.path.append('examples'); import utils.visualization"
- name: Test CLI interfaces
run: |
python examples/module1_fundamentals/01_classical_vs_quantum_bits.py --help
python examples/module4_algorithms/01_deutsch_jozsa_algorithm.py --help
python examples/module6_machine_learning/01_quantum_feature_maps.py --help
- name: Run smoke tests (basic functionality)
env:
MPLBACKEND: Agg # Use non-interactive matplotlib backend
run: |
# Test a few examples with minimal parameters to ensure they run
timeout 60s python examples/module1_fundamentals/01_classical_vs_quantum_bits.py --shots 10 || echo "Module 1 test completed"
timeout 60s python examples/module2_mathematics/01_complex_numbers_amplitudes.py || echo "Module 2 test completed"
timeout 60s python examples/module4_algorithms/01_deutsch_jozsa_algorithm.py --qubits 2 --function-type constant_0 || echo "Module 4 test completed"
documentation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r examples/requirements-dev.txt
- name: Check README files exist
run: |
test -f README.md
test -f examples/README.md
test -f docs/CONTRIBUTING.md
test -f docs/CODE_OF_CONDUCT.md
test -f docs/SECURITY.md
for module in examples/module*/; do
test -f "$module/README.md"
done
- name: Validate example structure
run: |
# Check that each module has exactly 5 examples
for module in examples/module*/; do
count=$(find "$module" -maxdepth 1 -name "*.py" | wc -l)
if [ "$count" -ne 5 ]; then
echo "Error: $module should have exactly 5 Python examples, found $count"
exit 1
fi
done
- name: Check for placeholder content
run: |
# Ensure no TODO or placeholder content in main files
if grep -r "TODO\|FIXME\|XXX" examples/module*/*.py; then
echo "Found placeholder content in examples"
exit 1
fi
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install security tools
run: |
python -m pip install --upgrade pip
pip install safety bandit
- name: Check for known security vulnerabilities
run: |
pip install -r examples/requirements.txt
safety check
- name: Run security linter
run: |
bandit -r examples/ -f json -o bandit-report.json || true
# Convert to readable format and check for high-severity issues
bandit -r examples/ -ll || echo "Security scan completed with warnings"
- name: Upload security report
uses: actions/upload-artifact@v3
if: always()
with:
name: security-report
path: bandit-report.json