diff --git a/.codecov.yml b/.codecov.yml new file mode 100644 index 0000000..c3da9d8 --- /dev/null +++ b/.codecov.yml @@ -0,0 +1,13 @@ +codecov: + require_ci_to_pass: yes + +coverage: + precision: 1 + round: down + target: "20...100" + +ignore: + - '**/test/**' + - 'env/**' + - 'reports/**' + - '.pytest_cache/**' diff --git a/.github/workflows/continous_integration.yml b/.github/workflows/continous_integration.yml index 33caf8c..ba6f1d4 100644 --- a/.github/workflows/continous_integration.yml +++ b/.github/workflows/continous_integration.yml @@ -1,14 +1,30 @@ name: Python application -on: [push] +on: [push,pull_request] jobs: build: + env: + PYTHON_FILES: . + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: get changed files for push + if: ${{ github.event_name == 'push' }} + run: | + echo ::set-env name=PYTHON_FILES::$(find . -type f -name "*.py" | xargs git diff --name-only --diff-filter=ACMRT ${{ github.sha }}~ ${{ github.sha }} | awk '{print $1}' | paste -d' ' -s) + - name: get changed files for pull request + if: ${{ github.event_name == 'pull_request' }} + run: | + echo ::set-env name=PYTHON_FILES::$(find . -type f -name "*.py" | xargs git diff --name-only --diff-filter=ACMRT origin/${{ github.base_ref }} origin/${{ github.head_ref }} | awk '{print $1}' | paste -d' ' -s) + - name: print PYTHON_FILES + run: | + echo ${{ env.PYTHON_FILES }} - name: Set up Python 3.8 uses: actions/setup-python@v1 with: @@ -17,21 +33,18 @@ jobs: run: | python -m pip install --upgrade pip pip install -r requirements.txt - - name: get changed files - id: getfile - run: | - echo "::set-output name=files::$(git diff-tree --no-commit-id --name-only -r ${{ github.sha }} | xargs)" - - name: echo output + - name: Formatting check + if: ${{ env.PYTHON_FILES }} run: | - echo ${{ steps.getfile.outputs.files }} -# - name: Lint with flake8 -# run: | -# pip install -q wemake-python-styleguide -# wget "https://raw.githubusercontent.com/ebot7/eb7-styleguide/master/settings/setup_ml_githooks.cfg" -# flake8 pgb/ --config=setup_ml_githooks.cfg -# rm setup_ml_githooks.cfg -# with: -# - fail_ci_if_error: true + pip install -qU autoflake==1.4 black==20.8b1 docformatter==1.3.1 isort==5.5.3 + echo "Checking with autoflake" + autoflake --check --expand-star-imports --remove-all-unused-imports --ignore-init-module-imports --remove-duplicate-keys --remove-unused-variables ${{ env.PYTHON_FILES }} + echo "Checking with docformatter" + docformatter --check --make-summary-multi-line --pre-summary-newline ${{ env.PYTHON_FILES }} + echo "Checking with isort" + isort --check-only --quiet ${{ env.PYTHON_FILES }} + echo "Checking with black" + black --check ${{ env.PYTHON_FILES }} -l 79 - name: Test with pytest run: | pip install pytest==5.3.5 coverage==4.5.4 diff --git a/pgb/add.py b/pgb/add.py index 74b7093..c98172c 100644 --- a/pgb/add.py +++ b/pgb/add.py @@ -1,6 +1,6 @@ def add(a: int, b: int) -> int: """ - Adds two number + Adds two number. Args: a (int): First argument diff --git a/pgb/mul.py b/pgb/mul.py index 8b4d21b..bb11a46 100644 --- a/pgb/mul.py +++ b/pgb/mul.py @@ -1,6 +1,6 @@ def mul(a: int, b: int) -> int: """ - Multiplies two number + Multiplies two number. Args: a (int): First argument diff --git a/pgb/pow.py b/pgb/pow.py new file mode 100644 index 0000000..595f3ac --- /dev/null +++ b/pgb/pow.py @@ -0,0 +1,12 @@ +def pow(a: int, b: int) -> int: + """ + Power of two number. + + Args: + a (int): First argument + b (int): Second argument + + Returns: + Power of second arguments on the base of first argument + """ + return a ** b diff --git a/pgb/sub.py b/pgb/sub.py index 2ad8680..9a467f0 100644 --- a/pgb/sub.py +++ b/pgb/sub.py @@ -1,6 +1,6 @@ def sub(a: int, b: int) -> int: """ - Subtracts two number + Subtracts two number. Args: a (int): First argument diff --git a/tests/test_calculator.py b/tests/test_calculator.py index 39d0781..2c3f613 100644 --- a/tests/test_calculator.py +++ b/tests/test_calculator.py @@ -1,5 +1,6 @@ import unittest -from pgb import add, mul + +from pgb import add, mul, pow, sub class TestCalculator(unittest.TestCase): @@ -13,6 +14,16 @@ def test_mul(self): b = 10 self.assertEqual(mul.mul(a, b), 50) + def test_sub(self): + a = 5 + b = 10 + self.assertEqual(sub.sub(a, b), -5) + + def test_pow(self): + a = 2 + b = 10 + self.assertEqual(pow.pow(a, b), 1024) + -if __name__ == '__main__': +if __name__ == "__main__": unittest.main()