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

[Mula] Feature/mula test coverage #180

Merged
merged 9 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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
94 changes: 46 additions & 48 deletions mula/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,60 @@ export file
export DOCKER_BUILDKIT=1
export COMPOSE_DOCKER_CLI_BUILD=1

ci-docker-compose := docker-compose -f base.yml -f .ci/docker-compose.yml

##
##+------------------------------------------------------------------------+
##| Help |
##+------------------------------------------------------------------------+
help: ## Show this help.
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/ ##/ /' | sed -e 's/##//'

##
##+------------------------------------------------------------------------+
##| Development |
##+------------------------------------------------------------------------+

check: ## Check the code style using black, mypy and pylint.
make black
make mypy
make pylint

mypy: ## Check code style using mypy.
docker-compose -f base.yml -f .ci/docker-compose.yml \
run --rm mula \
$(ci-docker-compose) run --rm mula \
python -m mypy --cache-dir /home/scheduler/.mypy_cache /app/scheduler/scheduler

black: ## Check code style with black.
docker-compose -f base.yml -f .ci/docker-compose.yml \
run --rm mula \
$(ci-docker-compose) run --rm mula \
black --check --diff .

pylint: ## Rate the code with pylint.
docker-compose -f base.yml -f .ci/docker-compose.yml \
run --rm mula \
$(ci-docker-compose) run --rm mula \
pylint --rcfile pyproject.toml scheduler

fmt: ## Format the code using black.
docker-compose -f base.yml -f .ci/docker-compose.yml \
run --rm mula \
$(ci-docker-compose) run --rm mula \
black .

done: ## Prepare for a commit.
make lint
make check
make test

cov: ## Generate a test coverage report
$(ci-docker-compose) run --rm mula \
python -m pytest \
--cov-report term-missing:skip-covered \
--cov=scheduler tests/

##
##+------------------------------------------------------------------------+
##| Migrations |
##+------------------------------------------------------------------------+

sql: ## Generate raw sql for the migrations.
docker-compose exec scheduler \
alembic \
--config /app/scheduler/alembic.ini \
alembic --config /app/scheduler/alembic.ini \
upgrade $(rev1):$(rev2) --sql

migrations: ## Create migration.
Expand All @@ -68,70 +85,51 @@ ifeq ($(m),)
else ifeq ($(revid),)
$(HIDE) (echo "ERROR: Specify a message with m={message} and a rev-id with revid={revid} (e.g. 0001 etc.)"; exit 1)
else
docker-compose \
run scheduler \
docker-compose run scheduler \
alembic --config /app/scheduler/scheduler/alembic.ini \
revision --autogenerate \
-m "$(m)" --rev-id "$(revid)"
endif

migrate: ## Run migrations using alembic.
docker-compose \
run scheduler \
docker-compose run scheduler \
alembic --config /app/scheduler/scheduler/alembic.ini \
upgrade head


##
##|------------------------------------------------------------------------|
## Tests
##|------------------------------------------------------------------------|
##+------------------------------------------------------------------------+
##| Testing |
##+------------------------------------------------------------------------+

utest: ## Run the unit tests.
ifneq ($(build),)
docker-compose -f base.yml -f .ci/docker-compose.yml build mula
endif

ifneq ($(file),)
docker-compose -f base.yml -f .ci/docker-compose.yml \
run --rm mula python -m unittest tests/unit/${file} ${function}; \
docker-compose -f base.yml -f .ci/docker-compose.yml down
$(ci-docker-compose) run --rm mula python -m pytest tests/unit/${file} ${function}
else
docker-compose -f base.yml -f .ci/docker-compose.yml \
run --rm mula python -m unittest discover tests/unit; \
docker-compose -f base.yml -f .ci/docker-compose.yml down
$(ci-docker-compose) run --rm mula python -m pytest tests/unit
endif
$(ci-docker-compose) down --remove-orphans

itest: ## Run the integration tests.
ifneq ($(build),)
docker-compose -f base.yml -f .ci/docker-compose.yml build mula_integration
endif

ifneq ($(file),)
docker-compose -f base.yml -f .ci/docker-compose.yml \
run --rm mula_integration python -m unittest -v tests/integration/${file} ${function}; \
docker-compose -f base.yml -f .ci/docker-compose.yml down
$(ci-docker-compose) run --rm mula python -m pytest tests/integration/${file} ${function}
else
docker-compose -f base.yml -f .ci/docker-compose.yml \
run --rm mula_integration python -m unittest discover -v tests/integration; \
docker-compose -f base.yml -f .ci/docker-compose.yml down
$(ci-docker-compose) run --rm mula python -m pytest tests/integration
endif
$(ci-docker-compose) down --remove-orphans

stest: ## Run the simulation tests.
docker-compose -f base.yml -f .ci/docker-compose.yml \
run --rm mula python -m unittest discover -v tests/simulation; \
docker-compose -f base.yml -f .ci/docker-compose.yml down
$(ci-docker-compose) run --rm mula python -m pytest tests/simulation
$(ci-docker-compose) down --remove-orphans

test: ## Run all tests.
make utest
make itest


##
##|------------------------------------------------------------------------|
## Building
##|------------------------------------------------------------------------|
debian:
##+------------------------------------------------------------------------+
##| Building |
##+------------------------------------------------------------------------+
debian: ## debian
mkdir -p build
docker run --rm \
--env PKG_NAME=kat-mula \
Expand All @@ -144,7 +142,7 @@ debian:
kat-debian-build-image \
packaging/scripts/build-debian-package.sh

ubuntu:
ubuntu: ## ubuntu
mkdir -p build
docker run --rm \
--env PKG_NAME=kat-mula \
Expand All @@ -157,7 +155,7 @@ ubuntu:
kat-ubuntu-build-image \
packaging/scripts/build-debian-package.sh

clean:
clean: ## clean
rm -rf build
rm -rf debian/kat-*/ debian/.debhelper debian/files *.egg-info/ dist/
rm -f debian/debhelper-build-stamp
Expand Down
5 changes: 5 additions & 0 deletions mula/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ exclude = ["tests"]
[build-system]
requires = ["setuptools>=59", "wheel"]
build-backend = "setuptools.build_meta:__legacy__"

[tool.coverage.run]
omit = [
"scheduler/alembic/*"
]
2 changes: 2 additions & 0 deletions mula/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ black==22.10.0
pylint==2.15.6
click==8.0.4
psutil==5.9.4
pytest==7.2.1
pytest-cov==4.0.0
4 changes: 2 additions & 2 deletions mula/tests/integration/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from tests.utils.functions import create_p_item


class TestPriorityQueue(queues.PriorityQueue):
class MockPriorityQueue(queues.PriorityQueue):
def create_hash(self, item: functions.TestModel):
return hash(item.id)

Expand All @@ -37,7 +37,7 @@ def setUp(self):
# Scheduler
self.organisation = OrganisationFactory()

queue = TestPriorityQueue(
queue = MockPriorityQueue(
pq_id=self.organisation.id,
maxsize=10,
item_type=functions.TestModel,
Expand Down
4 changes: 2 additions & 2 deletions mula/tests/unit/test_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from tests.utils import functions


class TestPriorityQueue(queues.PriorityQueue):
class MockPriorityQueue(queues.PriorityQueue):
def create_hash(self, item: functions.TestModel):
return hash(item.id)

Expand All @@ -22,7 +22,7 @@ def setUp(self) -> None:

self.pq_store = sqlalchemy.PriorityQueueStore(datastore=self.datastore)

self.pq = TestPriorityQueue(
self.pq = MockPriorityQueue(
pq_id="test",
maxsize=10,
item_type=functions.TestModel,
Expand Down