diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..67d3ee0 --- /dev/null +++ b/.github/workflows/python-app.yml @@ -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 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"} diff --git a/test_main.py b/test_main.py index fdbdb2d..41c82c5 100644 --- a/test_main.py +++ b/test_main.py @@ -7,12 +7,12 @@ 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' @@ -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'