From cc8ed4520d05b056d95c4c29692b6359fcaeaa51 Mon Sep 17 00:00:00 2001 From: acse-bq23 Date: Tue, 17 Oct 2023 11:04:35 +0100 Subject: [PATCH 1/4] add trivial change --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index e715af5..bea649c 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ # CI MPM Toy repo with some simple functions for the CI lecture + +trivial change \ No newline at end of file From 72133f8bc03d76a3fb6c798b306b827cf4ee3820 Mon Sep 17 00:00:00 2001 From: acse-bq23 Date: Tue, 17 Oct 2023 11:17:00 +0100 Subject: [PATCH 2/4] Add factorial funciton. --- simple_functions/functions1.py | 7 ++++++- tests/test_simple_functions.py | 13 ++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/simple_functions/functions1.py b/simple_functions/functions1.py index 8c63a4d..a52c322 100644 --- a/simple_functions/functions1.py +++ b/simple_functions/functions1.py @@ -1,5 +1,6 @@ +from functools import cache -__all__ = ['my_sum'] +__all__ = ['my_sum', 'factorial'] def my_sum(iterable): @@ -7,3 +8,7 @@ def my_sum(iterable): for i in iterable: tot += i return tot + +@cache +def factorial(n): + return n * factorial(n-1) if n else 1 diff --git a/tests/test_simple_functions.py b/tests/test_simple_functions.py index 5a03b52..acb9fc7 100644 --- a/tests/test_simple_functions.py +++ b/tests/test_simple_functions.py @@ -1,6 +1,6 @@ import pytest -from simple_functions import my_sum +from simple_functions import my_sum,factorial class TestSimpleFunctions(object): @@ -14,3 +14,14 @@ def test_my_add(self, iterable, expected): '''Test our add function''' isum = my_sum(iterable) assert isum == expected + + + @pytest.mark.parametrize('number, expected', [ + (5, 120), + (3, 6), + (1, 1) + ]) + def test_factorial(self, number, expected): + '''Test our factorial function''' + answer = factorial(number) + assert answer == expected \ No newline at end of file From df66a5f7bf6840901dbc36a799bbe7e62dd957a1 Mon Sep 17 00:00:00 2001 From: Baisheng Qian <142481690+acse-bq23@users.noreply.github.com> Date: Tue, 17 Oct 2023 11:18:19 +0100 Subject: [PATCH 3/4] Create python-publish.yml --- .github/workflows/python-publish.yml | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/python-publish.yml diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml new file mode 100644 index 0000000..bdaab28 --- /dev/null +++ b/.github/workflows/python-publish.yml @@ -0,0 +1,39 @@ +# This workflow will upload a Python Package using Twine when a release is created +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Upload Python Package + +on: + release: + types: [published] + +permissions: + contents: read + +jobs: + deploy: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build + - name: Build package + run: python -m build + - name: Publish package + uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} From 43b9c20858d8dbaac140a152f030ae2b3309f052 Mon Sep 17 00:00:00 2001 From: acse-bq23 Date: Tue, 17 Oct 2023 11:43:10 +0100 Subject: [PATCH 4/4] add trivial change2 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bea649c..b482a34 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ # CI MPM Toy repo with some simple functions for the CI lecture -trivial change \ No newline at end of file +trivial change 2 \ No newline at end of file