Skip to content

Commit

Permalink
GitHub matrix job to test against old dependencies
Browse files Browse the repository at this point in the history
The job pins Python dependencies to oldest supported versions.
  • Loading branch information
akaihola committed Feb 6, 2022
1 parent 86db58e commit 10def1d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
constraints: ['']
include:
- os: ubuntu-latest
python-version: '3.6'
constraints: '--constraint constraints-oldest.txt'

steps:
- uses: actions/checkout@v2
Expand All @@ -30,7 +35,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade 'pip>=20.3' # strict dependency resolution added in pip 20.3
pip install -e '.[isort,test]'
pip install -e '.[isort,test]' ${{ matrix.constraints }}
- name: Test with pytest
run: |
pytest
13 changes: 13 additions & 0 deletions constraints-oldest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Constraints for pip to pin dependencies to oldest supported versions.
# This is used in a GitHub Workflow matrix job which ensures everything
# still works against oldest supported versions of both the Python
# interpreter and Python ependencies. Keep this up-to-date with minimum
# versions in `setup.cfg`.
black==21.8b0
mypy==0.910
pytest==6.1.0
pytest-flake8==1.0.6
pytest-isort==1.1.0
pytest-kwparametrize==0.0.3
regex==2021.4.4
types-toml==0.1.3
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ package_dir =
=src
packages = find:
install_requires =
# NOTE: remember to keep `constraints-oldest.txt` in sync with these
black>=21.5b1
toml
typing-extensions ; python_version < "3.8"
dataclasses ; python_version < "3.7"
# NOTE: remember to keep `.github/workflows/python-package.yml` in sync
# with the minimum required Python version
python_requires = >=3.6

[options.packages.find]
Expand All @@ -46,6 +49,7 @@ pygments.lexers =
isort =
isort>=5.0.1
test =
# NOTE: remember to keep `constraints-oldest.txt` in sync with these
black>=21.7b1 # to prevent Mypy error about `gen_python_files`, see issue #189
flake8<4
mypy>=0.910
Expand Down
25 changes: 22 additions & 3 deletions src/darker/tests/test_black_diff.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Unit tests for `darker.black_diff`"""

import re
from dataclasses import dataclass, field
from pathlib import Path
from unittest.mock import ANY, patch

Expand All @@ -17,6 +18,20 @@
from darker.utils import TextDocument


@dataclass
class RegexEquality:
"""Compare equality to either `re.Pattern` or `regex.Pattern`"""

pattern: str
flags: int = field(default=re.UNICODE)

def __eq__(self, other):
return (
other.pattern == self.pattern
and other.flags & 0x1FF == re.compile(self.pattern).flags | self.flags
)


@pytest.mark.kwparametrize(
dict(
config_path=None, config_lines=["line-length = 79"], expect={"line_length": 79}
Expand Down Expand Up @@ -46,15 +61,19 @@
dict(config_lines=[r"include = '\.pyi$'"], expect={}),
dict(
config_lines=[r"exclude = '\.pyx$'"],
expect={"exclude": re.compile("\\.pyx$")},
expect={"exclude": RegexEquality("\\.pyx$")},
),
dict(
config_lines=["extend-exclude = '''", r"^/setup\.py", r"|^/dummy\.py", "'''"],
expect={"extend_exclude": re.compile("(?x)^/setup\\.py\n|^/dummy\\.py\n")},
expect={
"extend_exclude": RegexEquality(
"(?x)^/setup\\.py\n|^/dummy\\.py\n", re.VERBOSE
)
},
),
dict(
config_lines=["force-exclude = '''", r"^/setup\.py", r"|\.pyc$", "'''"],
expect={"force_exclude": re.compile("(?x)^/setup\\.py\n|\\.pyc$\n")},
expect={"force_exclude": RegexEquality("(?x)^/setup\\.py\n|\\.pyc$\n")},
),
config_path=None,
)
Expand Down

0 comments on commit 10def1d

Please sign in to comment.