From 8815d161eba3e0a29cba857e8a753741902b4b01 Mon Sep 17 00:00:00 2001 From: Colm O'Connor Date: Fri, 22 Oct 2021 11:20:35 +0100 Subject: [PATCH] Basic test and docker compose runner. --- docker-compose.yaml | 56 ++++++++++++++++++++++++++++++++++++++++ docker/run_tests.sh | 53 +++++++++++++++++++++++++++++++++++++ tests/unit/test_basic.py | 4 +-- 3 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 docker-compose.yaml create mode 100755 docker/run_tests.sh diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..129f2c2 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,56 @@ +version: '3.4' + +# Defaults + +x-build-args-36: &build_args_36 + IMAGE_TAG: "3.6-buster" + +x-build-args-37: &build_args_37 + IMAGE_TAG: "3.7-buster" + +x-build-args-38: &build_args_38 + IMAGE_TAG: "3.8-buster" + +services: + + # Devbox + + dev: &dev + build: &dev_build + dockerfile: ./docker/Dockerfile + context: . + image: avro-to-markdown-dev + command: /bin/bash + volumes: + - ./:/app + + # Test & Lint suite + + test-36: + <<: *dev + build: + <<: *dev_build + args: + IMAGE: python:3.6-buster + image: avro-to-markdown-test-36 + command: docker/run_tests.sh + + test-37: + <<: *dev + build: + <<: *dev_build + args: + IMAGE: python:3.7-buster + image: avro-to-markdown-test-37 + command: docker/run_tests.sh + + # NOTE: test-38 command includes `--format-code` option that will + # apply changes when the lint suite is run + test-38: + <<: *dev + build: + <<: *dev_build + args: + IMAGE: python:3.8-buster + image: avro-to-markdown-test-38 + command: docker/run_tests.sh --format-code diff --git a/docker/run_tests.sh b/docker/run_tests.sh new file mode 100755 index 0000000..397f989 --- /dev/null +++ b/docker/run_tests.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +set -eo pipefail + +BLACK_ACTION="--check" +ISORT_ACTION="--check-only" + +function usage +{ + echo "usage: run_tests.sh [--format-code]" + echo "" + echo " --format-code : Format the code instead of checking formatting." + exit 1 +} + +while [[ $# -gt 0 ]]; do + arg="$1" + case $arg in + --format-code) + BLACK_ACTION="--quiet" + ISORT_ACTION="" + ;; + -h|--help) + usage + ;; + "") + # ignore + ;; + *) + echo "Unexpected argument: ${arg}" + usage + ;; + esac + shift +done + +# only generate html locally +pytest tests/unit --cov-report html + +echo "Running MyPy..." +mypy avro_to_markdown tests + +echo "Running black..." +black ${BLACK_ACTION} avro_to_markdown tests + +echo "Running iSort..." +isort ${ISORT_ACTION} avro_to_markdown tests + +echo "Running flake8..." +flake8 avro_to_markdown tests + +echo "Running bandit..." +bandit --ini .bandit --quiet -r avro_to_markdown diff --git a/tests/unit/test_basic.py b/tests/unit/test_basic.py index a661040..90a05c7 100644 --- a/tests/unit/test_basic.py +++ b/tests/unit/test_basic.py @@ -1,5 +1,5 @@ import avro_to_markdown -def test_avro_to_markdown(): - pass +def test_avro_to_markdown_version(): + assert avro_to_markdown.__version__ == "0.1.0"