From 3a96bfd867d844159c5abc83e38cbdbf7b9e8017 Mon Sep 17 00:00:00 2001 From: AikaBack <42915767+AikaBack@users.noreply.github.com> Date: Wed, 29 May 2024 19:18:41 +0500 Subject: [PATCH 1/6] Update test_main.py --- test_main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test_main.py b/test_main.py index fdbdb2d..c230e78 100644 --- a/test_main.py +++ b/test_main.py @@ -12,7 +12,7 @@ def test_read_main(): def test_predict_positive(): response = client.post("/predict/", - json={"text": "I like machine learning!"}) + json={"text": "Apples are my favourite!"}) json_data = response.json() assert response.status_code == 200 assert json_data['label'] == 'POSITIVE' @@ -20,7 +20,7 @@ def test_predict_positive(): def test_predict_negative(): response = client.post("/predict/", - json={"text": "I hate machine learning!"}) + json={"text": "I'm not into hiking."}) json_data = response.json() assert response.status_code == 200 assert json_data['label'] == 'NEGATIVE' From 76dbd9ae074745e9f63668f6c9a107e240ce9be5 Mon Sep 17 00:00:00 2001 From: AikaBack <42915767+AikaBack@users.noreply.github.com> Date: Wed, 29 May 2024 19:28:49 +0500 Subject: [PATCH 2/6] Create python-app.yml --- .github/workflows/python-app.yml | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/python-app.yml diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..22eb259 --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,36 @@ +name: Python application + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # remove exit-zero to ensure build fails on lint errors + flake8 . --count --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest test_main.py From b3d51644bff6a8646d291c38cc0415a528a100c1 Mon Sep 17 00:00:00 2001 From: AikaBack <42915767+AikaBack@users.noreply.github.com> Date: Wed, 29 May 2024 19:29:25 +0500 Subject: [PATCH 3/6] Update test_main.py --- test_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_main.py b/test_main.py index c230e78..39bbf5f 100644 --- a/test_main.py +++ b/test_main.py @@ -20,7 +20,7 @@ def test_predict_positive(): def test_predict_negative(): response = client.post("/predict/", - json={"text": "I'm not into hiking."}) + json={"text": "I'm not into hiking!"}) json_data = response.json() assert response.status_code == 200 assert json_data['label'] == 'NEGATIVE' From 73d5d0c1a2ea660b9bcd7e922124263cbdceb527 Mon Sep 17 00:00:00 2001 From: AikaBack <42915767+AikaBack@users.noreply.github.com> Date: Wed, 29 May 2024 19:31:19 +0500 Subject: [PATCH 4/6] Fixed python-app.yml --- .github/workflows/python-app.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 22eb259..67d3ee0 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -2,9 +2,9 @@ name: Python application on: push: - branches: [ "main" ] + branches: [ "master" ] pull_request: - branches: [ "main" ] + branches: [ "master" ] permissions: contents: read From 3691c1bfabd6a549a6bf4d497a661ad4207a20c4 Mon Sep 17 00:00:00 2001 From: AikaBack <42915767+AikaBack@users.noreply.github.com> Date: Wed, 29 May 2024 19:53:30 +0500 Subject: [PATCH 5/6] Update flake8 main.py --- main.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/main.py b/main.py index be946ec..286338b 100644 --- a/main.py +++ b/main.py @@ -7,12 +7,10 @@ class Item(BaseModel): text: str - app = FastAPI() classifier = pipeline("sentiment-analysis") - @app.get("/") def root(): return {"message": "Hello World"} From 9daca9f7c793dd0b15fe3fe96f19d1ba0e2894fa Mon Sep 17 00:00:00 2001 From: AikaBack <42915767+AikaBack@users.noreply.github.com> Date: Wed, 29 May 2024 19:56:12 +0500 Subject: [PATCH 6/6] Correcting test_main.py --- test_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_main.py b/test_main.py index 39bbf5f..41c82c5 100644 --- a/test_main.py +++ b/test_main.py @@ -7,7 +7,7 @@ def test_read_main(): response = client.get("/") assert response.status_code == 200 - assert response.json() == {"message": "World"} + assert response.json() == {"message": "Hello World"} def test_predict_positive():