Skip to content

Commit 873319c

Browse files
committed
Added comprehensive unit tests
1 parent a943927 commit 873319c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+4798
-255
lines changed

.bandit

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[bandit]
2+
# Bandit configuration file
3+
exclude_dirs = ['tests', 'build', 'dist', '.git', '.tox', '.venv', '__pycache__']
4+
5+
# Skip certain tests that may be too strict for this project
6+
skips = ['B101', 'B601']
7+
8+
# B101: Test for use of assert
9+
# B601: Test for shell injection within Paramiko
10+
11+
[bandit.assert_used]
12+
# Allow assert statements in test files
13+
skips = ['*test*.py', '*tests*.py']

.bumpversion.cfg

Lines changed: 0 additions & 15 deletions
This file was deleted.

.flake8

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[flake8]
2+
max-line-length = 120
3+
extend-ignore = E203, W503
4+
exclude =
5+
.git,
6+
__pycache__,
7+
build,
8+
dist,
9+
.eggs,
10+
*.egg-info,
11+
.venv,
12+
.tox,
13+
himl/_version.py
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: '[BUG] '
5+
labels: bug
6+
assignees: ''
7+
---
8+
9+
## Bug Description
10+
11+
A clear and concise description of what the bug is.
12+
13+
## To Reproduce
14+
15+
Steps to reproduce the behavior:
16+
1. Go to '...'
17+
2. Click on '....'
18+
3. Scroll down to '....'
19+
4. See error
20+
21+
## Expected Behavior
22+
23+
A clear and concise description of what you expected to happen.
24+
25+
## Actual Behavior
26+
27+
A clear and concise description of what actually happened.
28+
29+
## Environment
30+
31+
- OS: [e.g. Ubuntu 20.04, macOS 12.0, Windows 10]
32+
- Python version: [e.g. 3.9.7]
33+
- himl version: [e.g. 0.17.0]
34+
- Installation method: [e.g. pip, conda, from source]
35+
36+
## Configuration Files
37+
38+
If applicable, add sample configuration files that reproduce the issue.
39+
40+
```yaml
41+
# Example config that causes the issue
42+
```
43+
44+
## Error Messages
45+
46+
If applicable, add the full error message and stack trace.
47+
48+
```
49+
Paste error message here
50+
```
51+
52+
## Additional Context
53+
54+
Add any other context about the problem here.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: '[FEATURE] '
5+
labels: enhancement
6+
assignees: ''
7+
---
8+
9+
## Feature Description
10+
11+
A clear and concise description of what you want to happen.
12+
13+
## Problem Statement
14+
15+
Is your feature request related to a problem? Please describe.
16+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
17+
18+
## Proposed Solution
19+
20+
Describe the solution you'd like.
21+
A clear and concise description of what you want to happen.
22+
23+
## Alternatives Considered
24+
25+
Describe alternatives you've considered.
26+
A clear and concise description of any alternative solutions or features you've considered.
27+
28+
## Use Case
29+
30+
Describe your use case and how this feature would help.
31+
32+
## Implementation Ideas
33+
34+
If you have ideas about how this could be implemented, please share them here.
35+
36+
## Additional Context
37+
38+
Add any other context or screenshots about the feature request here.

.github/pull_request_template.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## Description
2+
3+
Brief description of the changes in this PR.
4+
5+
## Type of Change
6+
7+
- [ ] Bug fix (non-breaking change which fixes an issue)
8+
- [ ] New feature (non-breaking change which adds functionality)
9+
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
10+
- [ ] Documentation update
11+
- [ ] Code refactoring
12+
- [ ] Performance improvement
13+
- [ ] Test improvement
14+
15+
## Testing
16+
17+
- [ ] Tests pass locally with my changes
18+
- [ ] I have added tests that prove my fix is effective or that my feature works
19+
- [ ] New and existing unit tests pass locally with my changes
20+
- [ ] I have tested the changes manually
21+
22+
## Checklist
23+
24+
- [ ] My code follows the style guidelines of this project
25+
- [ ] I have performed a self-review of my own code
26+
- [ ] I have commented my code, particularly in hard-to-understand areas
27+
- [ ] I have made corresponding changes to the documentation
28+
- [ ] My changes generate no new warnings
29+
- [ ] Any dependent changes have been merged and published in downstream modules
30+
31+
## Additional Notes
32+
33+
Add any additional notes, concerns, or context about the changes here.

.github/workflows/ci.yaml

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
workflow_dispatch:
9+
10+
env:
11+
FORCE_COLOR: 1
12+
13+
jobs:
14+
test:
15+
name: Test Python ${{ matrix.python-version }} on ${{ matrix.os }}
16+
runs-on: ${{ matrix.os }}
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
os: [ubuntu-latest, macos-latest]
21+
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14']
22+
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v4
26+
27+
- name: Set up Python ${{ matrix.python-version }}
28+
uses: actions/setup-python@v5
29+
with:
30+
python-version: ${{ matrix.python-version }}
31+
32+
- name: Get pip cache dir
33+
id: pip-cache
34+
run: |
35+
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
36+
37+
- name: Cache pip dependencies
38+
uses: actions/cache@v4
39+
with:
40+
path: ${{ steps.pip-cache.outputs.dir }}
41+
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml', '**/tests/requirements.txt') }}
42+
restore-keys: |
43+
${{ runner.os }}-pip-${{ matrix.python-version }}-
44+
${{ runner.os }}-pip-
45+
46+
- name: Install dependencies
47+
run: |
48+
python -m pip install --upgrade pip setuptools wheel
49+
pip install -e .[dev]
50+
51+
- name: Lint with flake8
52+
run: |
53+
# Stop the build if there are Python syntax errors or undefined names
54+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
55+
# Exit-zero treats all errors as warnings
56+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=120 --statistics
57+
58+
- name: Type check with mypy
59+
run: |
60+
mypy himl/ --ignore-missing-imports
61+
62+
- name: Run tests with pytest
63+
run: |
64+
python -m pytest tests/ -v --tb=short --cov=himl --cov-report=xml --cov-report=term-missing --cov-fail-under=80
65+
66+
- name: Upload coverage to Codecov
67+
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.14'
68+
uses: codecov/codecov-action@v4
69+
with:
70+
file: ./coverage.xml
71+
flags: unittests
72+
name: codecov-umbrella
73+
fail_ci_if_error: false
74+
75+
security:
76+
name: Security checks
77+
runs-on: ubuntu-latest
78+
# Note: Using Python 3.13 for security checks until bandit supports Python 3.14
79+
# See: https://github.com/PyCQA/bandit/issues with ast.Num deprecation
80+
steps:
81+
- name: Checkout code
82+
uses: actions/checkout@v4
83+
84+
- name: Set up Python
85+
uses: actions/setup-python@v5
86+
with:
87+
python-version: '3.13' # Use 3.13 until bandit supports 3.14
88+
89+
- name: Install security tools
90+
run: |
91+
python -m pip install --upgrade pip
92+
pip install bandit[toml] safety
93+
94+
- name: Run security checks with bandit
95+
run: |
96+
# Generate JSON report (allow failures for reporting)
97+
bandit -r himl/ -f json -o bandit-report.json || echo "Bandit JSON report generation completed with issues"
98+
# Run bandit with medium severity (fail on medium+ issues)
99+
bandit -r himl/ --severity-level medium
100+
101+
102+
- name: Upload security reports
103+
if: always()
104+
uses: actions/upload-artifact@v4
105+
with:
106+
name: security-reports
107+
path: |
108+
bandit-report.json
109+
110+
build:
111+
name: Build package
112+
runs-on: ubuntu-latest
113+
steps:
114+
- name: Checkout code
115+
uses: actions/checkout@v4
116+
with:
117+
fetch-depth: 0 # Needed for setuptools_scm
118+
119+
- name: Set up Python
120+
uses: actions/setup-python@v5
121+
with:
122+
python-version: '3.14'
123+
124+
- name: Install build dependencies
125+
run: |
126+
python -m pip install --upgrade pip
127+
pip install build twine
128+
129+
- name: Build package
130+
run: |
131+
python -m build
132+
133+
- name: Check package
134+
run: |
135+
twine check dist/*
136+
137+
- name: Test package installation
138+
run: |
139+
pip install dist/*.whl
140+
himl --help
141+
himl-config-merger --help
142+
143+
- name: Upload build artifacts
144+
uses: actions/upload-artifact@v4
145+
with:
146+
name: dist-${{ github.sha }}
147+
path: dist/
148+
retention-days: 30
149+
150+
integration:
151+
name: Integration tests
152+
runs-on: ubuntu-latest
153+
needs: [test, build]
154+
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main'
155+
steps:
156+
- name: Checkout code
157+
uses: actions/checkout@v4
158+
159+
- name: Set up Python
160+
uses: actions/setup-python@v5
161+
with:
162+
python-version: '3.14'
163+
164+
- name: Download build artifacts
165+
uses: actions/download-artifact@v4
166+
with:
167+
name: dist-${{ github.sha }}
168+
path: dist/
169+
170+
- name: Install package from wheel
171+
run: |
172+
python -m pip install --upgrade pip
173+
pip install dist/*.whl
174+
175+
- name: Run integration tests
176+
run: |
177+
# Test CLI tools work
178+
himl --help
179+
himl-config-merger --help
180+
181+
# Test basic functionality with examples
182+
if [ -d "examples" ]; then
183+
cd examples
184+
if [ -d "simple" ]; then
185+
himl simple/production --format yaml
186+
fi
187+
fi
188+
189+
docker:
190+
name: Docker build test
191+
runs-on: ubuntu-latest
192+
needs: [test, build]
193+
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main'
194+
steps:
195+
- name: Checkout code
196+
uses: actions/checkout@v4
197+
with:
198+
fetch-depth: 0 # Needed for setuptools_scm
199+
200+
- name: Set up Docker Buildx
201+
uses: docker/setup-buildx-action@v3
202+
203+
- name: Build Docker image
204+
uses: docker/build-push-action@v6
205+
with:
206+
context: .
207+
push: false
208+
tags: himl:test
209+
cache-from: type=gha
210+
cache-to: type=gha,mode=max
211+
212+
- name: Test Docker image
213+
run: |
214+
# Test that both CLI commands work
215+
docker run --rm himl:test himl --help
216+
docker run --rm himl:test himl-config-merger --help
217+
218+
# Test basic functionality
219+
docker run --rm himl:test python -c "import himl; print('himl import successful')"

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,6 @@ venv.bak/
104104

105105
# mypy
106106
.mypy_cache/
107+
108+
# setuptools_scm generated version file
109+
himl/_version.py

0 commit comments

Comments
 (0)