From 4459d34f54cc5af4aebf36d50d6f95ea11474564 Mon Sep 17 00:00:00 2001 From: teds-lin Date: Mon, 3 Jul 2023 21:18:34 +0800 Subject: [PATCH 1/6] [CI] fix #3 --- .../{python-package-conda.yml => build_test.yml} | 9 +-------- requirements.txt | 4 ++++ 2 files changed, 5 insertions(+), 8 deletions(-) rename .github/workflows/{python-package-conda.yml => build_test.yml} (72%) diff --git a/.github/workflows/python-package-conda.yml b/.github/workflows/build_test.yml similarity index 72% rename from .github/workflows/python-package-conda.yml rename to .github/workflows/build_test.yml index 0b00100..d308ce8 100644 --- a/.github/workflows/python-package-conda.yml +++ b/.github/workflows/build_test.yml @@ -1,4 +1,4 @@ -name: Python Package using Conda +name: Python Package build test on: push: @@ -18,22 +18,15 @@ jobs: uses: actions/setup-python@v3 with: python-version: '3.10.11' - - name: Add conda to system path - run: | - # $CONDA is an environment variable pointing to the root of the miniconda directory - echo $CONDA/bin >> $GITHUB_PATH - name: Install dependencies run: | - # conda env update --file .yml --name base pip install -r requirements.txt - name: Lint with flake8 run: | - conda install flake8 # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest run: | - conda install pytest pytest \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 7710096..35ad970 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,6 @@ +#app flask == 2.3.2 + +#test +flake8 == 6.0.0 pytest == 7.3.1 \ No newline at end of file From f772608417a199c1229e053e9acd81e17829e1b9 Mon Sep 17 00:00:00 2001 From: teds-lin Date: Mon, 3 Jul 2023 21:22:39 +0800 Subject: [PATCH 2/6] [CI] test #3 --- .github/workflows/build_test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index d308ce8..1cae0a3 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -2,9 +2,9 @@ name: Python Package build test on: push: - branches: ["backend"] + branches: ["backend*"] pull_request: - branches: ["backend"] + branches: ["backend*"] jobs: build-linux: From d450fa4f8a9b2be537540e9487da95be6c1776d9 Mon Sep 17 00:00:00 2001 From: teds-lin Date: Fri, 7 Jul 2023 23:54:52 +0800 Subject: [PATCH 3/6] [e2e]resolve #5 --- .github/workflows/build_test.yml | 1 + {src => backend/magician/app}/__init__.py | 0 backend/magician/app/flask_app.py | 10 ++++++++++ {src => backend/magician}/service/__init__.py | 0 backend/magician/service/print_hello.py | 2 ++ backend/setup.py | 7 +++++++ requirements.txt | 3 ++- src/service/print_hello.py | 2 -- test/__init__.py | 0 test/test_hello.py | 17 ----------------- tests/conftest.py | 12 ++++++++++++ tests/e2e/test_api.py | 8 ++++++++ tests/unit/test_hello.py | 6 ++++++ 13 files changed, 48 insertions(+), 20 deletions(-) rename {src => backend/magician/app}/__init__.py (100%) create mode 100644 backend/magician/app/flask_app.py rename {src => backend/magician}/service/__init__.py (100%) create mode 100644 backend/magician/service/print_hello.py create mode 100644 backend/setup.py delete mode 100644 src/service/print_hello.py delete mode 100644 test/__init__.py delete mode 100644 test/test_hello.py create mode 100644 tests/conftest.py create mode 100644 tests/e2e/test_api.py create mode 100644 tests/unit/test_hello.py diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index 1cae0a3..071ed23 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -21,6 +21,7 @@ jobs: - name: Install dependencies run: | pip install -r requirements.txt + pip install -e backend - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names diff --git a/src/__init__.py b/backend/magician/app/__init__.py similarity index 100% rename from src/__init__.py rename to backend/magician/app/__init__.py diff --git a/backend/magician/app/flask_app.py b/backend/magician/app/flask_app.py new file mode 100644 index 0000000..cdb6a45 --- /dev/null +++ b/backend/magician/app/flask_app.py @@ -0,0 +1,10 @@ +from flask import Flask + +from magician.service.print_hello import print_hello + +app = Flask(__name__) + + +@app.route('/hello', methods=['GET']) +def api_hello(): + return {"msg": print_hello()}, 200 diff --git a/src/service/__init__.py b/backend/magician/service/__init__.py similarity index 100% rename from src/service/__init__.py rename to backend/magician/service/__init__.py diff --git a/backend/magician/service/print_hello.py b/backend/magician/service/print_hello.py new file mode 100644 index 0000000..162207b --- /dev/null +++ b/backend/magician/service/print_hello.py @@ -0,0 +1,2 @@ +def print_hello(): + return 'hello world' diff --git a/backend/setup.py b/backend/setup.py new file mode 100644 index 0000000..e46a5fd --- /dev/null +++ b/backend/setup.py @@ -0,0 +1,7 @@ +from setuptools import setup, find_packages + +setup( + name="magician", + version="0.1", + packages=find_packages(), +) diff --git a/requirements.txt b/requirements.txt index 35ad970..98886fd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,5 @@ flask == 2.3.2 #test flake8 == 6.0.0 -pytest == 7.3.1 \ No newline at end of file +pytest == 7.3.1 +requests == 2.31.0 \ No newline at end of file diff --git a/src/service/print_hello.py b/src/service/print_hello.py deleted file mode 100644 index b303cf6..0000000 --- a/src/service/print_hello.py +++ /dev/null @@ -1,2 +0,0 @@ -def print_hello(): - return 'hello world' \ No newline at end of file diff --git a/test/__init__.py b/test/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/test/test_hello.py b/test/test_hello.py deleted file mode 100644 index 7f94f65..0000000 --- a/test/test_hello.py +++ /dev/null @@ -1,17 +0,0 @@ -import pytest -from src.service.print_hello import print_hello - - - -def test_mytest(): - assert 'hello world' == print_hello() - # assert 1==2123 - - -# def f(): -# raise SystemExit(1) - - -# def test_mytest(): -# with pytest.raises(SystemExit): -# f() \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..3197026 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,12 @@ +import pytest +from magician.app.flask_app import app as flask_app + + +@pytest.fixture +def app(): + return flask_app + + +@pytest.fixture +def client(app): + return app.test_client() diff --git a/tests/e2e/test_api.py b/tests/e2e/test_api.py new file mode 100644 index 0000000..eb09782 --- /dev/null +++ b/tests/e2e/test_api.py @@ -0,0 +1,8 @@ +import json + + +def test_hello(app, client): + res = client.get('/hello') + assert res.status_code == 200 + expected = {'msg': 'hello world'} + assert expected == json.loads(res.get_data(as_text=True)) diff --git a/tests/unit/test_hello.py b/tests/unit/test_hello.py new file mode 100644 index 0000000..f9b87cb --- /dev/null +++ b/tests/unit/test_hello.py @@ -0,0 +1,6 @@ +from magician.service.print_hello import print_hello + + +def test_mytest(): + assert 'hello world' == print_hello() + # assert 1==2123 From 7c0a4f02a010db0bff8f6d3f1d62ee2d3f489f7a Mon Sep 17 00:00:00 2001 From: teds-lin Date: Sat, 8 Jul 2023 00:10:09 +0800 Subject: [PATCH 4/6] [e2e]CI debug #5 --- .github/workflows/build_test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index 071ed23..2ea43a6 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -22,6 +22,9 @@ jobs: run: | pip install -r requirements.txt pip install -e backend + - name: CI debug + run: | + pip list - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names From 542a2bd4b80e205a00e78adbf966c83083d97c72 Mon Sep 17 00:00:00 2001 From: teds-lin Date: Sat, 8 Jul 2023 00:20:37 +0800 Subject: [PATCH 5/6] Revert "[e2e]CI debug #5" This reverts commit 7c0a4f02a010db0bff8f6d3f1d62ee2d3f489f7a. --- .github/workflows/build_test.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index 2ea43a6..071ed23 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -22,9 +22,6 @@ jobs: run: | pip install -r requirements.txt pip install -e backend - - name: CI debug - run: | - pip list - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names From 6b62e9cb5b24edde300cf8479b785f5ebbabf874 Mon Sep 17 00:00:00 2001 From: teds-lin Date: Sat, 8 Jul 2023 09:46:36 +0800 Subject: [PATCH 6/6] [e2e]fix setup.py #5 --- backend/setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/setup.py b/backend/setup.py index e46a5fd..3688f34 100644 --- a/backend/setup.py +++ b/backend/setup.py @@ -1,7 +1,7 @@ -from setuptools import setup, find_packages +from setuptools import setup setup( name="magician", version="0.1", - packages=find_packages(), + packages=["magician"], )