Browse Source

[python] Add tox for out of box test (#8837)

* [python] Add tox for out of box test

* Add `tox` for easy and complete test
* Correct package data attribute
* Add more dirs in flake8 ignore

* Change GA from raw to tox

* Fix env setter

* Temp skip sanity

* Rm not exists job

* Add code test

* fix

* rm all need

* fix

* fix

* fix

* fix

* fix

* fix

* Migrate pip upgrede to tox setting

* Change install_commands to commands

* fix config of install command

* Add GA env to do that

* Fix env error

* Finial commit

* remove duplicate

* Change doc

* Change dependence of ci

* Change dependence of ci
3.0.0/version-upgrade
Jiajie Zhong 2 years ago committed by GitHub
parent
commit
90f9aed11d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 79
      .github/workflows/py-ci.yml
  2. 1
      .gitignore
  3. 4
      dolphinscheduler-python/pydolphinscheduler/.coveragerc
  4. 4
      dolphinscheduler-python/pydolphinscheduler/.flake8
  5. 73
      dolphinscheduler-python/pydolphinscheduler/DEVELOP.md
  6. 3
      dolphinscheduler-python/pydolphinscheduler/setup.py
  7. 48
      dolphinscheduler-python/pydolphinscheduler/tox.ini

79
.github/workflows/py-ci.yml

@ -25,22 +25,21 @@ on:
paths: paths:
- 'dolphinscheduler-python/**' - 'dolphinscheduler-python/**'
concurrency:
group: py-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
defaults: defaults:
run: run:
working-directory: dolphinscheduler-python/pydolphinscheduler working-directory: dolphinscheduler-python/pydolphinscheduler
# We have to update setuptools wheel to package with package_data, LICENSE, NOTICE
env:
DEPENDENCES: pip setuptools wheel tox
jobs: jobs:
sanity:
name: Sanity
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Sanity Check
uses: ./.github/actions/sanity-check
lint: lint:
name: Code Style name: Lint
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
@ -48,19 +47,15 @@ jobs:
uses: actions/setup-python@v2 uses: actions/setup-python@v2
with: with:
python-version: 3.7 python-version: 3.7
- name: Install Development Dependences - name: Install Dependences
run: pip install -e .[style] run: |
- name: Run Isort Checking python -m pip install --upgrade ${{ env.DEPENDENCES }}
run: isort --check . - name: Run All Lint Check
- name: Run Black Checking run: |
run: black --check . python -m tox -vv -e lint
- name: Run Flake8 Checking
run: flake8
pytest: pytest:
name: Pytest name: Pytest
needs: needs: lint
- lint
- sanity
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
fail-fast: false fail-fast: false
@ -73,16 +68,15 @@ jobs:
uses: actions/setup-python@v2 uses: actions/setup-python@v2
with: with:
python-version: ${{ matrix.python-version }} python-version: ${{ matrix.python-version }}
- name: Install dependencies & pydolphinscheduler - name: Install Dependences
run: | run: |
pip install -e .[test] python -m pip install --upgrade ${{ env.DEPENDENCES }}
- name: Run tests - name: Run All Tests
run: | run: |
pytest python -m tox -vv -e code-test
coverage: doc-build:
name: Tests coverage name: Docs Build Test
needs: needs: lint
- pytest
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
@ -90,14 +84,17 @@ jobs:
uses: actions/setup-python@v2 uses: actions/setup-python@v2
with: with:
python-version: 3.7 python-version: 3.7
- name: Install Development Dependences - name: Install Dependences
run: | run: |
pip install -e .[test] python -m pip install --upgrade ${{ env.DEPENDENCES }}
- name: Run Tests && Check coverage - name: Run Tests Build Docs
run: coverage run && coverage report run: |
doc-build: python -m tox -vv -e doc-build-test
name: Document Build Test verify-local-ci:
needs: pytest name: Local CI
needs:
- pytest
- doc-build
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
@ -105,9 +102,9 @@ jobs:
uses: actions/setup-python@v2 uses: actions/setup-python@v2
with: with:
python-version: 3.7 python-version: 3.7
- name: Install Development Dependences - name: Install Dependences
run: |
python -m pip install --upgrade ${{ env.DEPENDENCES }}
- name: Run Tests Build Docs
run: | run: |
pip install -e .[doc] python -m tox -vv -e local-ci
- name: Test Build Document
working-directory: dolphinscheduler-python/pydolphinscheduler/docs
run: make clean && make html

1
.gitignore vendored

@ -55,6 +55,7 @@ dolphinscheduler-worker/logs
# ------------------ # ------------------
# Cache # Cache
__pycache__/ __pycache__/
.tox/
# Build # Build
build/ build/

4
dolphinscheduler-python/pydolphinscheduler/.coveragerc

@ -20,8 +20,10 @@ command_line = -m pytest
omit = omit =
# Ignore all test cases in tests/ # Ignore all test cases in tests/
tests/* tests/*
# Ignore examples directory
*/pydolphinscheduler/examples/*
# TODO. Temporary ignore java_gateway file, because we could not find good way to test it. # TODO. Temporary ignore java_gateway file, because we could not find good way to test it.
src/pydolphinscheduler/java_gateway.py */pydolphinscheduler/java_gateway.py
[report] [report]
# Don’t report files that are 100% covered # Don’t report files that are 100% covered

4
dolphinscheduler-python/pydolphinscheduler/.flake8

@ -26,7 +26,9 @@ exclude =
old, old,
build, build,
dist, dist,
htmlcov htmlcov,
.tox,
dist,
ignore = ignore =
# It's clear and not need to add docstring # It's clear and not need to add docstring
D107, # D107: Don't require docstrings on __init__ D107, # D107: Don't require docstrings on __init__

73
dolphinscheduler-python/pydolphinscheduler/DEVELOP.md

@ -60,7 +60,53 @@ pydolphinscheduler tasks object, we use tasks to define exact job we want Dolphi
we only support `shell` task to execute shell task. [This link][all-task] list all tasks support in DolphinScheduler we only support `shell` task to execute shell task. [This link][all-task] list all tasks support in DolphinScheduler
and would be implemented in the further. and would be implemented in the further.
## Code Style ## Test Your Code
Linting and tests is very important for open source project, so we pay more attention to it. We have continuous
integration service run by GitHub Action to test whether the patch is good or not, which you could jump to
section [With GitHub Action](#with-github-action) see more detail.
And to make more convenience to local tests, we also have the way to run your [test automated with tox](#automated-testing-with-tox)
locally. It is helpful when your try to find out the detail when continuous integration in GitHub Action failed,
or you have a great patch and want to test local first.
Besides [automated testing with tox](#automated-testing-with-tox) locally, we also have a [manual way](#manually)
run tests. And it is scattered commands to reproduce each step of the integration test we told about.
* Remote
* [With GitHub Action](#with-github-action)
* Local
* [Automated Testing With tox](#automated-testing-with-tox)
* [Manually](#manually)
### With GitHub Action
GitHub Action test in various environment for pydolphinscheduler, including different python version in
`3.6|3.7|3.8|3.9` and operating system `linux|macOS|windows`. It will trigger and run automatically when you
submit pull requests to `apache/dolphinscheduler`.
### Automated Testing With tox
[tox](https://tox.wiki) is a package aims to automate and standardize testing in Python, both our continuous
integration and local test use it to run actual task. To use it, you should install it first
```shell
python -m pip install --upgrade tox
```
After installation, you could run a single command to run all the tests, it is almost like test in GitHub Action
but not so much different environment.
```shell
tox -e local-ci
```
It will take a while when you run it the first time, because it has to install dependencies and make some prepare,
and the next time you run it will be faster.
### Manually
#### Code Style
We use [isort][isort] to automatically keep Python imports alphabetically, and use [Black][black] for code We use [isort][isort] to automatically keep Python imports alphabetically, and use [Black][black] for code
formatter and [Flake8][flake8] for pep8 checker. If you use [pycharm][pycharm]or [IntelliJ IDEA][idea], formatter and [Flake8][flake8] for pep8 checker. If you use [pycharm][pycharm]or [IntelliJ IDEA][idea],
@ -74,33 +120,30 @@ GitHub, you could also run static check locally.
# but Flake8 just hint when code style not match pep8 # but Flake8 just hint when code style not match pep8
# Run Isort # Run Isort
isort . python -m isort .
# Run Black # Run Black
black . python -m black .
# Run Flake8 # Run Flake8
flake8 python -m flake8
``` ```
## Testing #### Testing
pydolphinscheduler using [pytest][pytest] to test our codebase. GitHub Action will run our test when you create pydolphinscheduler using [pytest][pytest] to run all tests in directory `tests`. You could run tests by the commands
pull request or commit to dev branch, with python version `3.6|3.7|3.8|3.9` and operating system `linux|macOS|windows`.
To test locally, you could directly run pytest after set `PYTHONPATH`
```shell ```shell
PYTHONPATH=src/ pytest python -m pytest --cov=pydolphinscheduler --cov-config=.coveragerc tests/
``` ```
We try to keep pydolphinscheduler usable through unit test coverage. 90% test coverage is our target, but for Besides run tests, it will also check the unit test [coverage][coverage] threshold, for now when test cover less than 90%
now, we require test coverage up to 85%, and each pull request leas than 85% would fail our CI step will fail the coverage, as well as our GitHub Action.
`Tests coverage`. We use [coverage][coverage] to check our test coverage, and you could check it locally by
run command. The command above will check test coverage automatically, and you could also test the coverage by command.
```shell ```shell
coverage run && coverage report python -m coverage run && python -m coverage report
``` ```
It would not only run unit test but also show each file coverage which cover rate less than 100%, and `TOTAL` It would not only run unit test but also show each file coverage which cover rate less than 100%, and `TOTAL`

3
dolphinscheduler-python/pydolphinscheduler/setup.py

@ -57,6 +57,7 @@ test = [
"pytest>=6.2", "pytest>=6.2",
"freezegun>=1.1", "freezegun>=1.1",
"coverage>=6.1", "coverage>=6.1",
"pytest-cov>=3.0",
] ]
style = [ style = [
@ -144,7 +145,7 @@ setup(
package_dir={"": "src"}, package_dir={"": "src"},
include_package_data=True, include_package_data=True,
package_data={ package_data={
"examples": ["examples.tutorial.py"], "pydolphinscheduler": ["core/default_config.yaml"],
}, },
platforms=["any"], platforms=["any"],
classifiers=[ classifiers=[

48
dolphinscheduler-python/pydolphinscheduler/tox.ini

@ -0,0 +1,48 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
[tox]
envlist = local-ci, lint, doc-build-test, code-test, py{36,37,38,39}
[testenv]
whitelist_externals = make
[testenv:lint]
extras = style
commands =
python -m isort --check .
python -m black --check .
python -m flake8
[testenv:code-test]
extras = test
# Run both tests and coverage
commands =
python -m pytest --cov=pydolphinscheduler --cov-config={toxinidir}/.coveragerc tests/
[testenv:doc-build-test]
extras = doc
commands =
make -C {toxinidir}/docs clean
make -C {toxinidir}/docs html
[testenv:local-ci]
extras = dev
commands =
{[testenv:lint]commands}
{[testenv:code-test]commands}
{[testenv:doc-build-test]commands}
Loading…
Cancel
Save