Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Tests

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

permissions:
contents: read

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v5

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}

- name: Install system dependencies (Ubuntu)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y python3-tk xvfb

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest pytest-cov
shell: bash

- name: Install requirements if present
run: |
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
shell: bash
if: runner.os != 'Windows'

- name: Install requirements if present (Windows)
run: |
if (Test-Path requirements.txt) { pip install -r requirements.txt }
shell: pwsh
if: runner.os == 'Windows'

- name: Run tests (Linux)
if: runner.os == 'Linux'
run: |
xvfb-run -a python -m pytest tests/ -v --cov=. --cov-report=xml --cov-report=term

- name: Run tests (Windows/macOS)
if: runner.os != 'Linux'
run: |
python -m pytest tests/ -v --cov=. --cov-report=xml --cov-report=term

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12'
with:
file: ./coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<img alt="PyPI Build State" src="https://github.com/Dog-Face-Development/ProgramVer/actions/workflows/push-to-pypi.yml/badge.svg">
<!-- Stability -->
<img alt="Pylint State" src="https://github.com/Dog-Face-Development/ProgramVer/actions/workflows/pylint.yml/badge.svg">
<!-- Tests -->
<img alt="Tests State" src="https://github.com/Dog-Face-Development/ProgramVer/actions/workflows/tests.yml/badge.svg">
<!-- CodeQL -->
<img alt="CodeQL State" src="https://github.com/Dog-Face-Development/ProgramVer/actions/workflows/codeql-analysis.yml/badge.svg">
<!-- Version -->
Expand Down Expand Up @@ -106,6 +108,36 @@ However, you may want to add the version window to your program. To do so, follo

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)**.

## Testing

ProgramVer includes a comprehensive test suite to ensure code quality and reliability. The test suite achieves 100% code coverage for the main module.

### Running Tests

To run the test suite locally:

```bash
# Install test dependencies
pip install -r requirements.txt

# Run tests (Linux)
xvfb-run -a python -m pytest tests/ -v

# Run tests (Windows/macOS)
python -m pytest tests/ -v

# Run tests with coverage
python -m pytest tests/ --cov=main --cov-report=term-missing
```

For more information about testing, see the [tests README](tests/README.md).

### Continuous Integration

Tests are automatically run on GitHub Actions for every push and pull request across:
- Operating Systems: Ubuntu, Windows, and macOS
- Python Versions: 3.9, 3.10, 3.11, and 3.12

## Contributing

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).
Expand Down
25 changes: 18 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,32 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
#pylint: disable=import-error, invalid-name

# pylint: disable=import-error, invalid-name

import os
from tkinter import Tk, Text, INSERT, PhotoImage, Label, Button, TOP, BOTTOM

# Import Statements

# Helper Functions


def get_resource_path(filename):
"""Get the absolute path to a resource file."""
base_dir = os.path.dirname(os.path.abspath(__file__))
return os.path.join(base_dir, filename)


# Document Functions


def openLicense():
"""Opens the license file in a new window."""
windowl = Tk()
with open("LICENSE.txt", "r", encoding="UTF-8") as licensefile:
license_path = get_resource_path("LICENSE.txt")
with open(license_path, "r", encoding="UTF-8") as licensefile:
licensecontents = licensefile.read()
licensefile.close()
windowl.title("License")
licensetext = Text(windowl)
licensetext.insert(INSERT, licensecontents)
Expand All @@ -38,9 +49,9 @@ def openLicense():
def openEULA():
"""Opens the EULA file in a new window."""
windowl = Tk()
with open("EULA.txt", "r", encoding="UTF-8") as eulafile:
eula_path = get_resource_path("EULA.txt")
with open(eula_path, "r", encoding="UTF-8") as eulafile:
eulacontents = eulafile.read()
eulafile.close()
windowl.title("EULA")
eulatext = Text(windowl)
eulatext.insert(INSERT, eulacontents)
Expand All @@ -56,8 +67,8 @@ def ProgramVer():
"Copyright & Version Info for ProgramVer"
) # change name based on program name
# UI Elements
dfdimage = PhotoImage(file="imgs/dfdlogo.gif")
pythonimage = PhotoImage(file="imgs/pythonpoweredlengthgif.gif")
dfdimage = PhotoImage(file=get_resource_path("imgs/dfdlogo.gif"))
pythonimage = PhotoImage(file=get_resource_path("imgs/pythonpoweredlengthgif.gif"))
dfdlogo = Label(window, image=dfdimage)
pythonpowered = Label(window, image=pythonimage)
info = Label(
Expand Down
10 changes: 10 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[tool:pytest]
testpaths = tests
python_files = test_*.py
python_classes = Test*
python_functions = test_*
addopts =
-v
--tb=short
--strict-markers
--disable-warnings
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Project Requirements
pytest>=7.4.0
pytest-cov>=4.1.0
100 changes: 100 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# ProgramVer Test Suite

This directory contains the comprehensive test suite for ProgramVer.

## Running Tests

### Prerequisites

Install the required testing dependencies:

```bash
pip install -r requirements.txt
```

On Linux systems, you'll also need to install tkinter and xvfb for headless GUI testing:

```bash
sudo apt-get install python3-tk xvfb
```

### Running All Tests

To run all tests:

```bash
# On Linux (headless environment)
xvfb-run -a python -m pytest tests/ -v

# On Windows/macOS (with display)
python -m pytest tests/ -v
```

### Running Tests with Coverage

To run tests with coverage report:

```bash
# On Linux
xvfb-run -a python -m pytest tests/ --cov=. --cov-report=term-missing --cov-report=html

# On Windows/macOS
python -m pytest tests/ --cov=. --cov-report=term-missing --cov-report=html
```

The HTML coverage report will be generated in the `htmlcov` directory.

### Running Specific Tests

To run a specific test file:

```bash
xvfb-run -a python -m pytest tests/test_main.py -v
```

To run a specific test class:

```bash
xvfb-run -a python -m pytest tests/test_main.py::TestOpenLicense -v
```

To run a specific test method:

```bash
xvfb-run -a python -m pytest tests/test_main.py::TestOpenLicense::test_openLicense_creates_window -v
```

## Test Structure

The test suite is organized as follows:

- `test_main.py` - Tests for the main ProgramVer module
- `TestOpenLicense` - Tests for the openLicense function
- `TestOpenEULA` - Tests for the openEULA function
- `TestProgramVer` - Tests for the ProgramVer main function
- `TestModuleIntegration` - Integration tests for the module

## GitHub Actions Integration

The test suite is automatically run on GitHub Actions for every push and pull request. The workflow:

- Runs on Ubuntu, Windows, and macOS
- Tests against Python 3.9, 3.10, 3.11, and 3.12
- Generates coverage reports
- Uploads coverage to Codecov (for master branch)

See `.github/workflows/tests.yml` for the complete configuration.

## Writing New Tests

When adding new features to ProgramVer, please add corresponding tests following these guidelines:

1. Create test classes that inherit from `unittest.TestCase`
2. Use descriptive test method names that start with `test_`
3. Use mocking for GUI components to avoid requiring a display
4. Add docstrings to explain what each test verifies
5. Ensure tests are independent and can run in any order

## Coverage Goals

We aim to maintain at least 90% code coverage for the main module. Currently, we have 100% coverage for `main.py`.
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Test package for ProgramVer."""
Loading