Skip to content

Commit

Permalink
fix(api): pytest in python-script-template (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeithX authored Mar 8, 2025
2 parents bc2f60a + f687903 commit 96aa11b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/python-setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ jobs:

- name: Install Requirements
run: |
cd examples/python-starters
cd examples/python-script-template
python -m pip install --upgrade -r requirements.txt
- name: Run Python
- name: Run and Test
run: |
cd examples/python-starters
python hello.py
python -c 'import this'
cd examples/python-script-template
pytest
python -c 'import this'

9 changes: 6 additions & 3 deletions examples/python-script-template/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
import sys
from utils.helper import greet, date

def start_coding():

def long_msg():
print("You can add more Python code to this script to Extend functionality!")


def main():
os.system('cls' if os.name == 'nt' else 'clear')
name = input("Enter your name: ")
app_title = 'Python Script Example'
print(f'{"-" * 40}\n{" " * 8}{app_title}{" " * 8}\n{"-" * 40}')
name = str(input("Your name: "))
print(greet(name))
print(f"Today is {date()}.")
start_coding()
long_msg()


if __name__ == "__main__":
Expand Down
19 changes: 17 additions & 2 deletions examples/python-script-template/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
import pytest
from main import main
from datetime import datetime
from utils.helper import greet, date


@pytest.fixture
def current_datetime():
return datetime(2025, 3, 8)

def test_set_date_time(current_datetime):
assert current_datetime == datetime(
2025, 3, 8
), "Should return 2025-03-08"

def test_current_date_time():
result = datetime.strptime(date(), "%m-%d-%Y")
assert isinstance(result, datetime), "Function should return datetime object."

def test_greet():
assert main.greet("World") == "Hello, World!"
assert greet("World") == "Hello, World!"

0 comments on commit 96aa11b

Please sign in to comment.