Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added workflow, used flake8 and corrected test_main.py #27

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Python application

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

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
2 changes: 0 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ class Item(BaseModel):
text: str



app = FastAPI()
classifier = pipeline("sentiment-analysis")



@app.get("/")
def root():
return {"message": "Hello World"}
Expand Down
6 changes: 3 additions & 3 deletions test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
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():
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'


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'