Skip to content

Commit

Permalink
refactor!: require mock name, remove deprecated methods, drop Python …
Browse files Browse the repository at this point in the history
…3.6 (#151)

BREAKING CHANGE: if you do not specify a `cls` or `func` argument to `decoy.mock()`,
you must specify a `name` parameter.

You can use the following find-and-replace patterns
to fix most tests that start failing due to this change:

```
# find
([a-z_]+?)(: .+?)? = decoy.mock\(\)
# replace
$1$2 = decoy.mock(name="$1")
```

```
# find
([a-z_]+?)(: .+?)? = decoy.mock\(is_async=(.+?)\)
# replace
$1$2 = decoy.mock(name="$1", is_async=$3)
```
  • Loading branch information
mcous authored Feb 20, 2023
1 parent e9fe3f7 commit 1f4e9b3
Show file tree
Hide file tree
Showing 30 changed files with 1,205 additions and 1,187 deletions.
22 changes: 0 additions & 22 deletions .flake8

This file was deleted.

57 changes: 57 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: "Set up repository for CI"
description: "Install development dependencies"

inputs:
python-version:
description: "Python version to install"
default: "3.11"
poetry-version:
description: "Poetry version to install"
default: "1.3.2"
cache:
description: "Cache directory"
default: "${{ runner.temp }}/cache"

runs:
using: "composite"
steps:
- name: "Set up Python"
id: setup-python
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }}

- name: "Set up dependency cache"
uses: actions/cache@v3
with:
key: ${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ inputs.poetry-version }}-${{ hashFiles('poetry.lock') }}
path: ${{ inputs.cache }}

- name: "Set up PATH on POSIX"
if: ${{ runner.os != 'windows'}}
shell: bash
run: echo "${{ inputs.cache }}/tools/bin" >> $GITHUB_PATH

- name: "Set up PATH on Windows"
if: ${{ runner.os == 'windows'}}
shell: bash
run: echo "${{ inputs.cache }}/tools/Scripts" >> $GITHUB_PATH

- name: "Check poetry installation"
id: check-poetry
shell: bash
continue-on-error: true
run: poetry --version

- name: "Install poetry"
shell: bash
if: ${{ steps.check-poetry.outcome == 'failure'}}
run: |
"${{ steps.setup-python.outputs.python-path }}" -m venv "${{ inputs.cache }}/tools"
pip install poetry==${{ inputs.poetry-version }}
- name: "Install development dependencies"
shell: bash
run: |
poetry config cache-dir "${{ inputs.cache }}/poetry"
poetry install --sync
107 changes: 21 additions & 86 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,123 +1,58 @@
name: 'Continuous integration'
name: "Continuous integration"

on: [push, pull_request]

env:
PIP_CACHE_DIR: ${{ github.workspace }}/.cache/pip
POETRY_CACHE_DIR: ${{ github.workspace }}/.cache/pypoetry
DEFAULT_PYTHON: '3.8'

jobs:
test:
name: 'Test Python ${{ matrix.python-version }} on ${{ matrix.os }}'
name: "Test Python ${{ matrix.python-version }} on ${{ matrix.os }}"
runs-on: ${{ matrix.os }}-latest
strategy:
matrix:
os: [Ubuntu, Windows, macOS]
python-version: ['3.7', '3.8', '3.9', '3.10']
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
steps:
- name: 'Check out repository'
- name: "Check out repository"
uses: actions/checkout@v3

- name: 'Set up Python'
uses: actions/setup-python@v4
- name: "Set up Python and development dependencies"
uses: ./.github/actions/setup
with:
python-version: ${{ matrix.python-version }}

- name: 'Set up dependency cache'
uses: actions/cache@v3
# poetry venv restore is buggy on windows
# https://github.com/python-poetry/poetry/issues/2629
if: ${{ matrix.os != 'Windows' }}
with:
key: deps-${{ secrets.GH_CACHE }}-${{ runner.os }}-python${{ matrix.python-version }}-${{ hashFiles('**/*.lock') }}
path: |
${{ env.PIP_CACHE_DIR }}
${{ env.POETRY_CACHE_DIR }}
- name: 'Install poetry'
run: pip install "poetry==1.1.11"

- name: 'Install dependencies'
run: poetry install

- name: 'Run tests'
run: poetry run coverage run --branch --source=decoy -m pytest --mypy-same-process
- name: "Run tests"
run: poetry run poe test-ci

- name: 'Generate coverage report'
run: poetry run coverage xml

- name: 'Upload coverage report'
- name: "Upload coverage report"
uses: codecov/codecov-action@v3

check:
name: 'Lint and type checks'
name: "Lint and type checks"
runs-on: ubuntu-latest
steps:
- name: 'Check out repository'
- name: "Check out repository"
uses: actions/checkout@v3

- name: 'Set up Python'
uses: actions/setup-python@v4
with:
python-version: ${{ env.DEFAULT_PYTHON }}

- name: 'Set up dependency cache'
uses: actions/cache@v3
with:
key: deps-${{ secrets.GH_CACHE }}-${{ runner.os }}-python${{ env.DEFAULT_PYTHON }}-${{ hashFiles('**/*.lock') }}
path: |
${{ env.PIP_CACHE_DIR }}
${{ env.POETRY_CACHE_DIR }}
- name: 'Install poetry'
run: pip install "poetry==1.1.11"
- name: "Set up Python and development dependencies"
uses: ./.github/actions/setup

- name: 'Install dependencies'
run: poetry install

- name: 'Check formatting'
run: poetry run black --check .

- name: 'Check linter'
run: poetry run flake8

- name: 'Checks types'
run: poetry run mypy
- name: "Check types, lints, and formatting"
run: poetry run poe check-ci

build:
name: Build assets and deploy on tags
runs-on: ubuntu-latest
needs: [test, check]
steps:
- name: 'Check out repository'
- name: "Check out repository"
uses: actions/checkout@v3

- name: 'Set up Python'
uses: actions/setup-python@v4
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: "Set up Python and development dependencies"
uses: ./.github/actions/setup

- name: 'Set up dependency cache'
uses: actions/cache@v3
with:
key: deps-${{ secrets.GH_CACHE }}-${{ runner.os }}-python${{ env.DEFAULT_PYTHON }}-${{ hashFiles('**/*.lock') }}
path: |
${{ env.PIP_CACHE_DIR }}
${{ env.POETRY_CACHE_DIR }}
- name: 'Install poetry'
run: pip install "poetry==1.1.11"

- name: 'Install dependencies'
run: poetry install

- name: 'Build artifacts'
run: |
poetry build
poetry run mkdocs build
- name: "Build artifacts"
run: poetry run poe build-ci

- name: 'Deploy to PyPI and GitHub Pages'
- name: "Deploy to PyPI and GitHub Pages"
if: startsWith(github.ref, 'refs/tags/v')
env:
USER_NAME: ${{ github.actor }}
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ site
*.egg-info
.python-version
__pycache__
.cache
.coverage
coverage.xml
htmlcov
.ruff_cache
31 changes: 20 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ All contributions are greatly appreciated! Before contributing, please read the

This project uses [Poetry][] to manage dependencies and builds, and you will need to install it before working on Decoy.

Once Poetry is installed, you should be good to set up a virtual environment and install development dependencies. Python >= 3.8 is required for development.
Once Poetry is installed, you should be good to set up a virtual environment and install development dependencies. Python 3.11 is recommended for development.

```bash
git clone https://github.com/mcous/decoy.git
Expand All @@ -16,18 +16,27 @@ poetry install

## Development Tasks

Decoy uses [poethepoet][] to manage development tasks. If you want to quickly check everything, run the following:

```shell
poetry run poe all
```

[poethepoet]: https://github.com/nat-n/poethepoet

### Tests

Decoy's tests are run using [pytest][].
Decoy's tests are run using [pytest][]. To run tests in watch mode:

```bash
poetry run pytest
poetry run poe test
```

You can also run tests in watch mode using [pytest-xdist][].
To run tests once and report coverage

```bash
poetry run pytest --looponfail
poetry run poe test-once
poetry run poe coverage
```

In an exciting twist, since version 1.6.0, Decoy's tests rely on Decoy itself to test (and more importantly, design) the relationships between Decoy's internal APIs. This means:
Expand All @@ -39,27 +48,27 @@ If you find yourself in a situation where Decoy's test suite has blown up, **con

### Checks

Decoy's source code is typechecked with [mypy][] and linted with [flake8][].
Decoy's source code is typechecked with [mypy][] and linted with [ruff][].

```bash
poetry run mypy
poetry run flake8
poetry run poe check
poetry run poe lint
```

### Formatting

Decoy's source code is formatted using [black][].

```bash
poetry run black .
poetry run poe format
```

### Documentation

Decoy's documentation is built with [mkdocs][], which you can use to preview the documentation site locally.

```bash
poetry run mkdocs serve
poetry run docs
```

## Deploying
Expand Down Expand Up @@ -92,7 +101,7 @@ git push --follow-tags
[pytest]: https://docs.pytest.org/
[pytest-xdist]: https://github.com/pytest-dev/pytest-xdist
[mypy]: https://mypy.readthedocs.io
[flake8]: https://flake8.pycqa.org
[ruff]: https://github.com/charliermarsh/ruff
[black]: https://black.readthedocs.io
[mkdocs]: https://www.mkdocs.org/
[semantic versioning]: https://semver.org/
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020-2021, Mike Cousins
Copyright (c) 2020-2023, Mike Cousins

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Loading

0 comments on commit 1f4e9b3

Please sign in to comment.