Skip to content

Commit

Permalink
v 0.0.32 add shopping_list
Browse files Browse the repository at this point in the history
  • Loading branch information
Yer1k committed Aug 9, 2024
1 parent dd699cc commit d0e683f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@

This repository utilizes GitHub Actions to run a Python package workflow that **formats**, **lints**, and **tests** the python scripts in the repository, followed by **installing the required packages**. The workflow is defined in the `.github/workflows/cicd.yml` and 'Makefile' files.

- **Formatting**: The python scripts are formatted using `black`.

- **Linting**: The python scripts are linted using `pylint` and `mypy`.

- **Testing**: The python scripts are tested using `pytest`.


## Description
This repository contains python scripts that I have written to practice writing python scripts. The scripts are based on prompts from the [Wise Owl Python Exercises](https://www.wiseowl.co.uk/python/exercises/python/).

### Table of Contents
1. [User Inputs: The meaning of life python script](./src/theMeaningofLife.py)
1. [Modify List: Shipping_list](./src/shopping_list.py)


### References
Expand Down
17 changes: 17 additions & 0 deletions src/shopping_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Use a list to create a shopping list and change an item in the list."""


def change_shopping_list(index: int, item: str) -> None:
"""
Demo of how to change an item in a shopping list.
"""
shopping_list = ["Double cream", "Single cream", "Eggs", "Oreos"]
shopping_list[index] = item

summary = "\nSHOPPING LIST\n"
summary = summary + "\n" + "\n\n".join(shopping_list)
print(summary)


if __name__ == "__main__":
change_shopping_list(3, "Healthier option")
26 changes: 26 additions & 0 deletions tests/test_shopping_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Module to test the function change_shopping_list() in the file shopping_list.py."""

from unittest.mock import patch
from shopping_list import change_shopping_list # type: ignore


def test_change_shopping_list() -> None:
"""
Test that the function change_shopping_list() prints the correct summary.
"""
with patch("builtins.print") as mocked_print:
change_shopping_list(3, "Healthier option")

# Combine the print outputs into a single string
expected_output = (
"\nSHOPPING LIST\n"
"\nDouble cream\n"
"\nSingle cream\n"
"\nEggs\n"
"\nHealthier option"
)

# Flatten the actual print calls into a single string
actual_output = "".join(call[0][0] for call in mocked_print.call_args_list)

assert actual_output == expected_output

0 comments on commit d0e683f

Please sign in to comment.