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

Implemented linting and unit-test #3

Merged
merged 9 commits into from
Dec 16, 2024
Merged
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
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 100
4 changes: 2 additions & 2 deletions .github/workflows/github-actions-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Build Image
run: make ci-build
- name: Build Dev Image
run: make ci-build-dev
- name: Linting
run: make ci-lint
- name: Unit Test
Expand Down
6 changes: 6 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[MESSAGES CONTROL]
disable=
missing-docstring,
too-few-public-methods,
too-many-arguments,
too-many-public-methods
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM python:3.8-slim
ARG install_dev=n

COPY requirements.build.txt ./
RUN pip install --disable-pip-version-check \
Expand All @@ -8,7 +9,17 @@ COPY requirements.txt ./
RUN pip install --disable-pip-version-check \
-r requirements.txt

COPY requirements.dev.txt ./
RUN if [ "${install_dev}" = "y" ]; then \
pip install --disable-pip-version-check --user \
-r requirements.txt \
-r requirements.dev.txt; \
fi

COPY spacy_keyword_extraction_api ./spacy_keyword_extraction_api
COPY static ./static
COPY tests ./tests

COPY .flake8 .pylintrc ./

CMD ["python3", "-m", "uvicorn", "spacy_keyword_extraction_api.main:create_app", "--factory", "--host", "0.0.0.0", "--port", "8000"]
30 changes: 28 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,29 @@ DOCKER_COMPOSE = $(DOCKER_COMPOSE_DEV)
build:
$(DOCKER_COMPOSE) build spacy-keyword-extraction-api

build-dev:
$(DOCKER_COMPOSE) build spacy-keyword-extraction-api-dev

flake8:
$(DOCKER_COMPOSE) run --rm spacy-keyword-extraction-api-dev \
python -m flake8 spacy_keyword_extraction_api tests

pylint:
$(DOCKER_COMPOSE) run --rm spacy-keyword-extraction-api-dev \
python -m pylint spacy_keyword_extraction_api tests

mypy:
$(DOCKER_COMPOSE) run --rm spacy-keyword-extraction-api-dev \
python -m mypy spacy_keyword_extraction_api tests

lint: flake8 pylint mypy

pytest:
$(DOCKER_COMPOSE) run --rm spacy-keyword-extraction-api-dev \
python -m pytest spacy_keyword_extraction_api tests

test: lint pytest


start:
$(DOCKER_COMPOSE) up -d spacy-keyword-extraction-api
Expand All @@ -22,8 +45,11 @@ logs:
ci-build:
$(MAKE) DOCKER_COMPOSE="$(DOCKER_COMPOSE_CI)" build

ci-build-dev:
$(MAKE) DOCKER_COMPOSE="$(DOCKER_COMPOSE_CI)" build-dev

ci-lint:
echo "Dummy lint"
$(MAKE) DOCKER_COMPOSE="$(DOCKER_COMPOSE_CI)" lint

ci-unittest:
echo "Dummy unittest"
$(MAKE) DOCKER_COMPOSE="$(DOCKER_COMPOSE_CI)" pytest
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@ services:
context: .
dockerfile: Dockerfile
image: ${IMAGE_REPO}:${IMAGE_TAG}

spacy-keyword-extraction-api-dev:
build:
context: .
dockerfile: Dockerfile
args:
install_dev: y
image: ${IMAGE_REPO}-dev:${IMAGE_TAG}
command: /bin/sh -c exit 0
entrypoint: []
4 changes: 4 additions & 0 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
flake8==7.1.1
pylint==3.2.7
pytest==8.3.3
mypy==1.11.2
Empty file added tests/unit_test/__init__.py
Empty file.
9 changes: 9 additions & 0 deletions tests/unit_test/main_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from fastapi.testclient import TestClient

de-code marked this conversation as resolved.
Show resolved Hide resolved
from spacy_keyword_extraction_api.main import create_app


def test_read_main():
client = TestClient(create_app())
response = client.get("/")
assert response.status_code == 200
Loading