AI Hints
Home›CI/CD with GitHub Actions Tutorial›Pipelines and Our Project
CI/CD with GitHub Actions · Lesson 5 of 138

Our Project

A tiny shop library.

⏱ 2 min read▶ Video at 4:40🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

To learn CI/CD, we need a project to automate. Ours is tiny on purpose. A small Python library for a shop, with a function that adds tax, a function that applies discounts, and a few tests. Small enough to understand at a glance, but real.

Our Project
From the video: Our Project
  • A project to automate
  • A tiny shop library
  • Small, but real

Looking around

Here's the shop folder. LS shows the files. App dot py holds the code, test app dot py holds the tests, and requirements dot txt lists the tools we need. Cat shows the code. Total adds twenty percent tax, and discount takes a percentage off, but refuses a percentage over one hundred.

Terminal
ls
README.md  app.py  requirements.txt  test_app.py
cat app.py
def total(prices, tax=0.2):
    return round(sum(prices) * (1 + tax), 2)

def discount(price, percent):
    if not 0 <= percent <= 100:
        raise ValueError("percent must be 0-100")
    return round(price * (1 - percent / 100), 2)

The tests

And here are the tests. Each test function calls our code, and uses assert to check the answer. The last one checks that a bad percentage raises a value error. Requirements dot txt lists pytest, which runs the tests, and flake8, which checks the style.

Terminal
cat test_app.py
import pytest
from app import total, discount

def test_total_adds_tax():
    assert total([10, 20]) == 36.0

def test_discount():
    assert discount(50, 10) == 45.0

def test_discount_rejects_bad_percent():
    with pytest.raises(ValueError):
        discount(50, 120)
cat requirements.txt
pytest
flake8

Summary

Our project is a tiny shop library, with code, tests, and a list of requirements. Next, running the tests by hand, before we automate them.

Key takeaways
  • app.py
  • test_app.py
  • requirements.txt
Next up: Running Tests by Hand — what CI will do for us