Skip to content

Commit 545e066

Browse files
Added GitHub Actions workflow for automated testing and CI
1 parent a0f64ed commit 545e066

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed

.github/python-ci.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Name of the GitHub Actions workflow
2+
name: Python Virtual Environment Setup CI
3+
4+
# Define when this workflow should run
5+
on:
6+
push:
7+
branches: [ main ] # Trigger on pushes to main branch
8+
pull_request:
9+
branches: [ main ] # Trigger on pull requests to main branch
10+
11+
# Define the jobs to run
12+
jobs:
13+
# First job: testing across different OS and Python versions
14+
test:
15+
# Dynamic OS selection based on matrix strategy
16+
runs-on: ${{ matrix.os }}
17+
strategy:
18+
matrix:
19+
# Define test matrix: will run tests on all combinations of these
20+
os: [ubuntu-latest, windows-latest, macos-latest] # Test on all major OS
21+
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13'] # Test on multiple Python versions
22+
23+
steps:
24+
# Step 1: Check out the repository code
25+
- uses: actions/checkout@v3
26+
27+
# Step 2: Set up Python environment
28+
- name: Set up Python ${{ matrix.python-version }}
29+
uses: actions/setup-python@v4
30+
with:
31+
python-version: ${{ matrix.python-version }}
32+
33+
# Step 3: Install required Python packages
34+
- name: Install dependencies
35+
run: |
36+
python -m pip install --upgrade pip # Upgrade pip to latest version
37+
pip install pytest pytest-cov flake8 # Install testing and linting tools
38+
39+
# Step 4: Run code quality checks with flake8
40+
- name: Lint with flake8
41+
run: |
42+
# Check for specific critical errors
43+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
44+
# Check overall code quality
45+
flake8 . --count --max-complexity=10 --max-line-length=127 --statistics
46+
47+
# Step 5: Create a test virtual environment
48+
- name: Create test virtual environment
49+
run: |
50+
python -m venv test_venv
51+
52+
# Step 6: Run tests with coverage reporting
53+
- name: Test VenvCreator
54+
run: |
55+
pytest --cov=. --cov-report=xml # Run tests and generate coverage report
56+
57+
# Step 7: Upload coverage reports to Codecov
58+
- name: Upload coverage to Codecov
59+
uses: codecov/codecov-action@v3
60+
with:
61+
file: ./coverage.xml # Coverage report file
62+
flags: unittests # Tag these results as unit tests
63+
fail_ci_if_error: true # Fail if upload to Codecov fails
64+
65+
# Second job: security scanning
66+
security:
67+
runs-on: ubuntu-latest # Security checks only need to run on one OS
68+
steps:
69+
# Step 1: Check out the repository code
70+
- uses: actions/checkout@v3
71+
72+
# Step 2: Set up Python environment
73+
- name: Set up Python
74+
uses: actions/setup-python@v4
75+
with:
76+
python-version: '3.10' # Use Python 3.10 for security checks
77+
78+
# Step 3: Install security scanning tools
79+
- name: Install security scanning tools
80+
run: |
81+
pip install bandit safety # bandit for code scanning, safety for dependency checking
82+
83+
# Step 4: Run security scans
84+
- name: Run security scan
85+
run: |
86+
bandit -r . # Recursively scan all Python files for security issues
87+
safety check # Check dependencies for known security vulnerabilities

test_venv_creator.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import pytest
2+
import os
3+
from create_venv import VenvCreator
4+
5+
@pytest.fixture
6+
def venv_creator():
7+
return VenvCreator()
8+
9+
def test_init(venv_creator):
10+
assert hasattr(venv_creator, 'os_type')
11+
assert hasattr(venv_creator, 'is_windows')
12+
assert hasattr(venv_creator, 'is_linux')
13+
14+
def test_find_python_installations(venv_creator):
15+
installations = venv_creator.find_python_installations()
16+
assert isinstance(installations, list)
17+
assert len(installations) > 0
18+
19+
def test_get_python_version(venv_creator):
20+
python_path = "python" # assumes python is in PATH
21+
version = venv_creator.get_python_version(python_path)
22+
assert isinstance(version, str)
23+
assert "Python" in version
24+
25+
def test_set_dependencies_folder(venv_creator, tmp_path):
26+
# Test with valid path
27+
assert venv_creator.set_dependencies_folder(str(tmp_path)) == True
28+
29+
# Test with invalid path
30+
assert venv_creator.set_dependencies_folder("/nonexistent/path") == False

0 commit comments

Comments
 (0)