From 18a3b742279f5f85b942e3ef41eda783b8483f9a Mon Sep 17 00:00:00 2001 From: Azulinho Date: Wed, 19 Apr 2023 16:58:20 +0100 Subject: [PATCH] use docker for lint tests --- .dockerignore | 1 - .github/workflows/pr_docker_tests.yaml | 5 ++ .github/workflows/pr_lint.yaml | 82 -------------------------- Dockerfile.tests | 38 ++++++++++++ run | 14 +---- tests/test_bot.py | 3 + 6 files changed, 49 insertions(+), 94 deletions(-) delete mode 100644 .github/workflows/pr_lint.yaml create mode 100644 Dockerfile.tests diff --git a/.dockerignore b/.dockerignore index 484270c..7bb5fdd 100644 --- a/.dockerignore +++ b/.dockerignore @@ -11,7 +11,6 @@ secrets/* state/* .tags tags -tests/* .venv .venv/* .git diff --git a/.github/workflows/pr_docker_tests.yaml b/.github/workflows/pr_docker_tests.yaml index f2ad462..c57cc51 100644 --- a/.github/workflows/pr_docker_tests.yaml +++ b/.github/workflows/pr_docker_tests.yaml @@ -23,3 +23,8 @@ jobs: run: | set -ex ./run github_actions_ci_pr_docker_tests TAG=pr + + - name: ./run tests + run: | + set -ex + ./run tests diff --git a/.github/workflows/pr_lint.yaml b/.github/workflows/pr_lint.yaml deleted file mode 100644 index 95a0db1..0000000 --- a/.github/workflows/pr_lint.yaml +++ /dev/null @@ -1,82 +0,0 @@ -name: Run lint and syntax tests on a Pull Request -on: pull_request - -jobs: - pr_tests: - name: Run PR tests - runs-on: ubuntu-latest - env: - ACTIONS_ALLOW_UNSECURE_COMMANDS: true - steps: - - name: Check out the repo - uses: actions/checkout@v2 - - - name: retrieve cached ta-lib - id: cache-ta-lib - uses: actions/cache@v3 - with: - path: /tmp/ta-lib - key: ta-lib - - - name: retrieve cached pip packages - id: cache-pip - uses: actions/cache@v3 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements-dev.txt') }}-${{ hashFiles('**/requirements.txt') }}-${{ hashFiles('.python-version') }} - - - name: install apt-packages - run: | - sudo apt-get update - sudo DEBIAN_FRONTEND=noninteractive apt-get install -yq eatmydata - sudo DEBIAN_FRONTEND=noninteractive eatmydata apt-get install -yq \ - make \ - build-essential \ - libssl-dev \ - zlib1g-dev \ - libbz2-dev \ - libisal-dev \ - libisal2 \ - libreadline-dev \ - libsqlite3-dev \ - wget \ - curl \ - llvm \ - libncursesw5-dev \ - xz-utils \ - tk-dev \ - libxml2-dev \ - libxmlsec1-dev \ - libffi-dev \ - liblzma-dev \ - git \ - ca-certificates \ - cargo \ - gzip \ - pigz \ - bzip2 \ - pbzip2 \ - autoconf \ - automake \ - shtool \ - coreutils \ - autogen \ - libtool \ - shtool \ - nasm - - - name: install ta-lib - run: | - cd /tmp \ - && eatmydata wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz \ - && eatmydata tar xf ta-lib-0.4.0-src.tar.gz \ - && cd ta-lib \ - && eatmydata ./configure --prefix=/usr \ - && eatmydata make \ - && sudo eatmydata make install - - - name: run setup - run: eatmydata ./run setup - - - name: run cryptobot tests - run: eatmydata ./run tests diff --git a/Dockerfile.tests b/Dockerfile.tests new file mode 100644 index 0000000..bd1caef --- /dev/null +++ b/Dockerfile.tests @@ -0,0 +1,38 @@ +FROM local:tests +RuN mkdir log cache tmp +ADD requirements-dev.txt /cryptobot/requirements-dev.txt +RUN /cryptobot/.venv/bin/pip install -r requirements-dev.txt +ADD .mypy.ini /cryptobot/ +ADD pyproject.toml /cryptobot/ +ADD tests/ /cryptobot/tests/ +ADD strategies/Buy* /cryptobot/strategies/ + +RUN /cryptobot/.venv/bin/black --check \ + app.py \ + klines_caching_service.py \ + price_log_service.py \ + strategies/ \ + lib/ \ + tests/ \ + utils/ + +RUN ls strategies/*.py \ + |grep -v Local \ +| xargs /cryptobot/.venv/bin/pylint \ + app.py \ + klines_caching_service.py \ + price_log_service.py \ + lib/*.py \ + utils/*.py + +RUN ls strategies/*.py \ + |grep -v Local \ + | xargs /cryptobot/.venv/bin/mypy \ + app.py \ + klines_caching_service.py \ + price_log_service.py \ + lib/*.py \ + utils/*.py + +RUN /cryptobot/.venv/bin/pytest \ + --quiet -W ignore --disable-pytest-warnings tests/ diff --git a/run b/run index 86914d6..bf4264f 100755 --- a/run +++ b/run @@ -277,17 +277,9 @@ function setup() { # local setup for development function tests() { # CI and pre-commit tests set -e set -o pipefail - export PATH=~/.pyenv/bin:$PATH - source .venv/bin/activate - echo "running black..." - black --check app.py klines_caching_service.py price_log_service.py strategies/ lib/ tests/ utils/ - echo "running pylint..." - ls strategies/*.py |grep -v Local | xargs pylint app.py klines_caching_service.py price_log_service.py lib/*.py utils/*.py - echo "running mypy..." - ls strategies/*.py |grep -v Local | xargs mypy app.py klines_caching_service.py price_log_service.py lib/*.py utils/*.py - echo "running pytest..." - pytest --quiet -W ignore --disable-pytest-warnings tests/ - deactivate + + IMAGE=local TAG=tests build + docker build -f Dockerfile.tests . } function github_actions_ci_pr_docker_tests() { diff --git a/tests/test_bot.py b/tests/test_bot.py index 929551b..78caacb 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -505,6 +505,9 @@ def test_extract_order_data(self, bot, coin): "selfTradePreventionMode": "NONE", } + bot.calculate_volume_size = mock.MagicMock() + bot.calculate_volume_size.return_value = (True, 0.5) + ok, data = bot.extract_order_data(order_details, coin) assert ok is True assert data["avgPrice"] == 332.53376623376624