Skip to content

Commit 87425be

Browse files
committed
Initial commit: Add helloworld.py with tests and GitHub Actions workflow
- Added helloworld.py with hello_world() and greet() functions - Added tests directory with test_helloworld.py containing pytest tests - Added .github/workflows/python-ci.yml for GitHub Actions CI workflow - Updated README.md with project documentation
1 parent 3f28fd9 commit 87425be

4 files changed

Lines changed: 92 additions & 0 deletions

File tree

.github/workflows/python-ci.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Python CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v4
18+
with:
19+
python-version: '3.9'
20+
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install pytest
25+
26+
- name: Run tests
27+
run: |
28+
python -m pytest tests/ -v

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,36 @@
11
# test-action
2+
23
Test Github Actions
4+
5+
## Project Structure
6+
7+
This is a simple Python project with a Hello World function and associated tests to demonstrate GitHub Actions CI/CD workflow.
8+
9+
## Files
10+
11+
- `helloworld.py`: Contains simple greeting functions
12+
- `tests/test_helloworld.py`: Pytest tests for the greeting functions
13+
- `.github/workflows/python-ci.yml`: GitHub Actions workflow for running tests
14+
15+
## Functions
16+
17+
- `hello_world()`: Returns "Hello, World!"
18+
- `greet(name)`: Returns a personalized greeting "Hello, {name}!"
19+
20+
## Running Tests Locally
21+
22+
To run the tests locally:
23+
24+
1. Install pytest:
25+
```
26+
pip install pytest
27+
```
28+
29+
2. Run the tests:
30+
```
31+
python -m pytest tests/ -v
32+
```
33+
34+
## GitHub Actions
35+
36+
This repository uses GitHub Actions to automatically run tests on every push and pull request to the main branch.

helloworld.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def hello_world():
2+
"""Return the classic 'Hello, World!' string."""
3+
return "Hello, World!"
4+
5+
6+
def greet(name):
7+
"""Return a personalized greeting."""
8+
return f"Hello, {name}!"
9+
10+
11+
if __name__ == "__main__":
12+
print(hello_world())

tests/test_helloworld.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import pytest
2+
from helloworld import hello_world, greet
3+
4+
5+
def test_hello_world():
6+
"""Test the hello_world function returns the correct string."""
7+
assert hello_world() == "Hello, World!"
8+
9+
10+
def test_greet():
11+
"""Test the greet function returns a personalized greeting."""
12+
assert greet("Alice") == "Hello, Alice!"
13+
assert greet("Bob") == "Hello, Bob!"
14+
15+
16+
def test_greet_empty_string():
17+
"""Test the greet function with an empty string."""
18+
assert greet("") == "Hello, !"

0 commit comments

Comments
 (0)