Skip to content

Commit da818e1

Browse files
Merge pull request #100 from Dog-Face-Development/copilot/create-test-suite-actions-integration
2 parents 7a9c7f0 + d6a4320 commit da818e1

File tree

8 files changed

+503
-7
lines changed

8 files changed

+503
-7
lines changed

.github/workflows/tests.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
test:
14+
runs-on: ${{ matrix.os }}
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
os: [ubuntu-latest, windows-latest, macos-latest]
19+
python-version: ["3.9", "3.10", "3.11", "3.12"]
20+
21+
steps:
22+
- uses: actions/checkout@v5
23+
24+
- name: Set up Python ${{ matrix.python-version }}
25+
uses: actions/setup-python@v6
26+
with:
27+
python-version: ${{ matrix.python-version }}
28+
29+
- name: Install system dependencies (Ubuntu)
30+
if: runner.os == 'Linux'
31+
run: |
32+
sudo apt-get update
33+
sudo apt-get install -y python3-tk xvfb
34+
35+
- name: Install dependencies
36+
run: |
37+
python -m pip install --upgrade pip
38+
pip install pytest pytest-cov
39+
shell: bash
40+
41+
- name: Install requirements if present
42+
run: |
43+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
44+
shell: bash
45+
if: runner.os != 'Windows'
46+
47+
- name: Install requirements if present (Windows)
48+
run: |
49+
if (Test-Path requirements.txt) { pip install -r requirements.txt }
50+
shell: pwsh
51+
if: runner.os == 'Windows'
52+
53+
- name: Run tests (Linux)
54+
if: runner.os == 'Linux'
55+
run: |
56+
xvfb-run -a python -m pytest tests/ -v --cov=. --cov-report=xml --cov-report=term
57+
58+
- name: Run tests (Windows/macOS)
59+
if: runner.os != 'Linux'
60+
run: |
61+
python -m pytest tests/ -v --cov=. --cov-report=xml --cov-report=term
62+
63+
- name: Upload coverage to Codecov
64+
uses: codecov/codecov-action@v5
65+
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12'
66+
with:
67+
file: ./coverage.xml
68+
flags: unittests
69+
name: codecov-umbrella
70+
fail_ci_if_error: false

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
<img alt="PyPI Build State" src="https://github.com/Dog-Face-Development/ProgramVer/actions/workflows/push-to-pypi.yml/badge.svg">
1616
<!-- Stability -->
1717
<img alt="Pylint State" src="https://github.com/Dog-Face-Development/ProgramVer/actions/workflows/pylint.yml/badge.svg">
18+
<!-- Tests -->
19+
<img alt="Tests State" src="https://github.com/Dog-Face-Development/ProgramVer/actions/workflows/tests.yml/badge.svg">
1820
<!-- CodeQL -->
1921
<img alt="CodeQL State" src="https://github.com/Dog-Face-Development/ProgramVer/actions/workflows/codeql-analysis.yml/badge.svg">
2022
<!-- Version -->
@@ -106,6 +108,36 @@ However, you may want to add the version window to your program. To do so, follo
106108

107109
Customization for ProgramVer can be found in the [`CUSTOMIZATION`](https://github.com/Dog-Face-Development/ProgramVer/blob/master/docs/CUSTOMIZATION.md) doc. More documentation is available in the **[Documentation](https://github.com/Dog-Face-Development/ProgramVer/tree/master/docs)** and on the **[Wiki](https://github.com/Dog-Face-Development/ProgramVer/wiki)**. If more support is required, please open a **[GitHub Discussion](https://github.com/Dog-Face-Development/ProgramVer/discussions)** or join our **[Discord](https://discord.gg/x3G8adwVUe)**.
108110

111+
## Testing
112+
113+
ProgramVer includes a comprehensive test suite to ensure code quality and reliability. The test suite achieves 100% code coverage for the main module.
114+
115+
### Running Tests
116+
117+
To run the test suite locally:
118+
119+
```bash
120+
# Install test dependencies
121+
pip install -r requirements.txt
122+
123+
# Run tests (Linux)
124+
xvfb-run -a python -m pytest tests/ -v
125+
126+
# Run tests (Windows/macOS)
127+
python -m pytest tests/ -v
128+
129+
# Run tests with coverage
130+
python -m pytest tests/ --cov=main --cov-report=term-missing
131+
```
132+
133+
For more information about testing, see the [tests README](tests/README.md).
134+
135+
### Continuous Integration
136+
137+
Tests are automatically run on GitHub Actions for every push and pull request across:
138+
- Operating Systems: Ubuntu, Windows, and macOS
139+
- Python Versions: 3.9, 3.10, 3.11, and 3.12
140+
109141
## Contributing
110142

111143
Please contribute using [GitHub Flow](https://guides.github.com/introduction/flow). Create a branch, add commits, and [open a pull request](https://github.com/Dog-Face-Development/ProgramVer/compare).

main.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,32 @@
1414
You should have received a copy of the GNU General Public License
1515
along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
"""
17-
#pylint: disable=import-error, invalid-name
1817

18+
# pylint: disable=import-error, invalid-name
19+
20+
import os
1921
from tkinter import Tk, Text, INSERT, PhotoImage, Label, Button, TOP, BOTTOM
2022

2123
# Import Statements
2224

25+
# Helper Functions
26+
27+
28+
def get_resource_path(filename):
29+
"""Get the absolute path to a resource file."""
30+
base_dir = os.path.dirname(os.path.abspath(__file__))
31+
return os.path.join(base_dir, filename)
32+
33+
2334
# Document Functions
2435

2536

2637
def openLicense():
2738
"""Opens the license file in a new window."""
2839
windowl = Tk()
29-
with open("LICENSE.txt", "r", encoding="UTF-8") as licensefile:
40+
license_path = get_resource_path("LICENSE.txt")
41+
with open(license_path, "r", encoding="UTF-8") as licensefile:
3042
licensecontents = licensefile.read()
31-
licensefile.close()
3243
windowl.title("License")
3344
licensetext = Text(windowl)
3445
licensetext.insert(INSERT, licensecontents)
@@ -38,9 +49,9 @@ def openLicense():
3849
def openEULA():
3950
"""Opens the EULA file in a new window."""
4051
windowl = Tk()
41-
with open("EULA.txt", "r", encoding="UTF-8") as eulafile:
52+
eula_path = get_resource_path("EULA.txt")
53+
with open(eula_path, "r", encoding="UTF-8") as eulafile:
4254
eulacontents = eulafile.read()
43-
eulafile.close()
4455
windowl.title("EULA")
4556
eulatext = Text(windowl)
4657
eulatext.insert(INSERT, eulacontents)
@@ -56,8 +67,8 @@ def ProgramVer():
5667
"Copyright & Version Info for ProgramVer"
5768
) # change name based on program name
5869
# UI Elements
59-
dfdimage = PhotoImage(file="imgs/dfdlogo.gif")
60-
pythonimage = PhotoImage(file="imgs/pythonpoweredlengthgif.gif")
70+
dfdimage = PhotoImage(file=get_resource_path("imgs/dfdlogo.gif"))
71+
pythonimage = PhotoImage(file=get_resource_path("imgs/pythonpoweredlengthgif.gif"))
6172
dfdlogo = Label(window, image=dfdimage)
6273
pythonpowered = Label(window, image=pythonimage)
6374
info = Label(

pytest.ini

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[tool:pytest]
2+
testpaths = tests
3+
python_files = test_*.py
4+
python_classes = Test*
5+
python_functions = test_*
6+
addopts =
7+
-v
8+
--tb=short
9+
--strict-markers
10+
--disable-warnings

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
# Project Requirements
2+
pytest>=7.4.0
3+
pytest-cov>=4.1.0

tests/README.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# ProgramVer Test Suite
2+
3+
This directory contains the comprehensive test suite for ProgramVer.
4+
5+
## Running Tests
6+
7+
### Prerequisites
8+
9+
Install the required testing dependencies:
10+
11+
```bash
12+
pip install -r requirements.txt
13+
```
14+
15+
On Linux systems, you'll also need to install tkinter and xvfb for headless GUI testing:
16+
17+
```bash
18+
sudo apt-get install python3-tk xvfb
19+
```
20+
21+
### Running All Tests
22+
23+
To run all tests:
24+
25+
```bash
26+
# On Linux (headless environment)
27+
xvfb-run -a python -m pytest tests/ -v
28+
29+
# On Windows/macOS (with display)
30+
python -m pytest tests/ -v
31+
```
32+
33+
### Running Tests with Coverage
34+
35+
To run tests with coverage report:
36+
37+
```bash
38+
# On Linux
39+
xvfb-run -a python -m pytest tests/ --cov=. --cov-report=term-missing --cov-report=html
40+
41+
# On Windows/macOS
42+
python -m pytest tests/ --cov=. --cov-report=term-missing --cov-report=html
43+
```
44+
45+
The HTML coverage report will be generated in the `htmlcov` directory.
46+
47+
### Running Specific Tests
48+
49+
To run a specific test file:
50+
51+
```bash
52+
xvfb-run -a python -m pytest tests/test_main.py -v
53+
```
54+
55+
To run a specific test class:
56+
57+
```bash
58+
xvfb-run -a python -m pytest tests/test_main.py::TestOpenLicense -v
59+
```
60+
61+
To run a specific test method:
62+
63+
```bash
64+
xvfb-run -a python -m pytest tests/test_main.py::TestOpenLicense::test_openLicense_creates_window -v
65+
```
66+
67+
## Test Structure
68+
69+
The test suite is organized as follows:
70+
71+
- `test_main.py` - Tests for the main ProgramVer module
72+
- `TestOpenLicense` - Tests for the openLicense function
73+
- `TestOpenEULA` - Tests for the openEULA function
74+
- `TestProgramVer` - Tests for the ProgramVer main function
75+
- `TestModuleIntegration` - Integration tests for the module
76+
77+
## GitHub Actions Integration
78+
79+
The test suite is automatically run on GitHub Actions for every push and pull request. The workflow:
80+
81+
- Runs on Ubuntu, Windows, and macOS
82+
- Tests against Python 3.9, 3.10, 3.11, and 3.12
83+
- Generates coverage reports
84+
- Uploads coverage to Codecov (for master branch)
85+
86+
See `.github/workflows/tests.yml` for the complete configuration.
87+
88+
## Writing New Tests
89+
90+
When adding new features to ProgramVer, please add corresponding tests following these guidelines:
91+
92+
1. Create test classes that inherit from `unittest.TestCase`
93+
2. Use descriptive test method names that start with `test_`
94+
3. Use mocking for GUI components to avoid requiring a display
95+
4. Add docstrings to explain what each test verifies
96+
5. Ensure tests are independent and can run in any order
97+
98+
## Coverage Goals
99+
100+
We aim to maintain at least 90% code coverage for the main module. Currently, we have 100% coverage for `main.py`.

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Test package for ProgramVer."""

0 commit comments

Comments
 (0)