Skip to content

Commit

Permalink
Run tests on 3.12 (#2889)
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Mar 25, 2024
1 parent 43a966f commit d4f70c6
Show file tree
Hide file tree
Showing 27 changed files with 232 additions and 328 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.9', '3.10', '3.11']
python-version: ['3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v4
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ Semantic versioning in our case means:
You can use `ruff` to change all `object`-based types to the new style:
`ruff check --select=UP004 --fix .`
https://docs.astral.sh/ruff/rules/useless-object-inheritance/
- **Breaking**: allow positional-only parameters,
since it is required by `mypy` when using `Concatenate`
- Due to how `f`-string are parsed in `python3.12` several token-based
violations are not reported anymore for them:
`WrongMultilineStringViolation`, `ImplicitRawStringViolation`,
`WrongUnicodeEscapeViolation`, `RawStringNotNeededViolation`
- `wemake` output formatter now respects `NO_COLOR=1` option
to disable text highlighting. See https://no-color.org
- Add `ImportObjectCollisionViolation` to detect
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ to make all people write **exactly** the same `Python` code.

We have several primary objectives:

0. Enforce `python3.7+` usage
1. Significantly reduce the complexity of your code and make it more maintainable
2. Enforce "There should be one -- and preferably only one -- obvious way to do it" rule to coding and naming styles
3. Protect developers from possible errors and enforce best practices
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/usage/integrations/ci.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Setting up ``GitlabCI`` is also easy:

.. code:: yaml
image: python3.7
image: python3.12
test:
before_script: pip install wemake-python-styleguide
script: flake8 .
Expand Down
6 changes: 3 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ plugins =
[coverage:coverage_conditional_plugin]
# Here we specify our pragma rules for conditional coverage:
rules =
# 3.9
"sys_version_info < (3, 9)": py-lt-39
"sys_version_info >= (3, 9)": py-gte-39
# 3.10
"sys_version_info < (3, 10)": py-lt-310
"sys_version_info >= (3, 10)": py-gte-310
# 3.12
"sys_version_info < (3, 12)": py-lt-312
"sys_version_info >= (3, 12)": py-gte-312


[mypy]
Expand Down
55 changes: 55 additions & 0 deletions tests/fixtures/noqa/noqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,3 +827,58 @@ def method(self, number):
class Antediluvian(Baseline):
def method(self):
return list((super().method(some_item) for some_item in items)) # noqa: WPS616


# porting noqa38.py
class WithStatic:
@staticmethod
def some_static(arg1): # noqa: WPS602
my_print('WTF?')

@staticmethod
async def some_async_static(arg1): # noqa: WPS602
my_print('WTF?')


@first
@second
@third(param='a')
@fourth
@fifth()
@error
def decorated(): # noqa: WPS216
my_print('WTF?')


def wrong_comprehension1():
return [ # noqa: WPS307
node
for node in 'ab'
if node != 'a'
if node != 'b'
]


def wrong_comprehension2():
return [ # noqa: WPS224
target
for assignment in range(hex_number)
for target in range(assignment)
for _ in range(10)
if isinstance(target, int)
]


for unique_element in range(10):
if (other := unique_element) > 5: # noqa: WPS332
my_print(1)

try: # noqa: WPS452
my_print(1)
except AnyError:
my_print('nope')
finally:
# See:
# https://github.com/wemake-services/wemake-python-styleguide/issues/1082
continue
my_print(4)
67 changes: 0 additions & 67 deletions tests/fixtures/noqa/noqa38.py

This file was deleted.

41 changes: 9 additions & 32 deletions tests/test_checker/test_noqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import pytest

# Versions for different version-specific fixtures.
_PY38 = (3, 8) <= sys.version_info < (3, 9)
_PY39 = (3, 9) <= sys.version_info < (3, 10)
_PY310 = (3, 10) <= sys.version_info < (3, 11)

Expand All @@ -42,22 +41,6 @@

#: Number and count of violations that would be raised.
VERSION_SPECIFIC = types.MappingProxyType({
'noqa_pre38': {
'WPS216': 1,
'WPS224': 1,
'WPS307': 1,
'WPS416': 1,
'WPS602': 2,
},
'noqa38': {
'WPS216': 1,
'WPS224': 1,
'WPS307': 1,
'WPS332': 1,
'WPS451': 1,
'WPS452': 1,
'WPS602': 2,
},
'noqa39': {
'WPS466': 1,
},
Expand Down Expand Up @@ -104,15 +87,15 @@
'WPS213': 1,
'WPS214': 1,
'WPS215': 1,
'WPS216': 0, # defined in version specific table.
'WPS216': 1,
'WPS217': 1,
'WPS218': 1,
'WPS219': 1,
'WPS220': 1,
'WPS221': 2,
'WPS222': 1,
'WPS223': 1,
'WPS224': 0, # defined in version specific table.
'WPS224': 1,
'WPS225': 1,
'WPS226': 0, # defined in ignored violations.
'WPS227': 2,
Expand All @@ -135,7 +118,7 @@
'WPS304': 1,
'WPS305': 2,
'WPS306': 2,
'WPS307': 0, # defined in version specific table.
'WPS307': 1,
'WPS308': 1,
'WPS309': 1,
'WPS310': 4,
Expand All @@ -160,7 +143,7 @@
'WPS329': 1,
'WPS330': 1,
'WPS331': 1,
'WPS332': 0, # defined in version specific table.
'WPS332': 1,
'WPS333': 1,
'WPS334': 1,
'WPS335': 1,
Expand Down Expand Up @@ -208,7 +191,7 @@
'WPS413': 1,
'WPS414': 1,
'WPS415': 1,
'WPS416': 0, # defined in version specific table.
'WPS416': 0, # deprecated
'WPS417': 1,
'WPS418': 1,
'WPS419': 1,
Expand Down Expand Up @@ -243,8 +226,8 @@
'WPS448': 1,
'WPS449': 1,
'WPS450': 1,
'WPS451': 0, # defined in version specific table.
'WPS452': 1, # also defined in version specific table.
'WPS451': 0, # deprecated
'WPS452': 2,
'WPS453': 0,
'WPS454': 1,
'WPS455': 1,
Expand Down Expand Up @@ -304,7 +287,7 @@

'WPS600': 1,
'WPS601': 1,
'WPS602': 0, # defined in version specific table.
'WPS602': 2,
'WPS603': 1,
'WPS604': 2,
'WPS605': 1,
Expand Down Expand Up @@ -352,7 +335,7 @@ def _assert_errors_count_in_output(

assert set(
filter(lambda key: errors[key] != 0, errors),
) - found_errors.keys() == set()
) == set(found_errors.keys())


def test_codes(all_violations):
Expand All @@ -362,12 +345,6 @@ def test_codes(all_violations):

@pytest.mark.parametrize(('filename', 'violations', 'total'), [
('noqa.py', SHOULD_BE_RAISED, True),
pytest.param(
'noqa38.py',
VERSION_SPECIFIC['noqa38'],
0,
marks=pytest.mark.skipif(not _PY38, reason='ast changes on 3.8'),
),
pytest.param(
'noqa39.py',
VERSION_SPECIFIC['noqa39'],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import pytest

from wemake_python_styleguide.compat.constants import PY39
from wemake_python_styleguide.violations.best_practices import (
NewStyledDecoratorViolation,
)
from wemake_python_styleguide.visitors.ast.decorators import (
WrongDecoratorVisitor,
)

_reason = 'new-styled decorators appeared in 3.9'
_mark = pytest.mark.skipif(not PY39, reason=_reason)

function_def = """
@{0}
def some(): ...
Expand All @@ -24,14 +20,8 @@ def some(self): ...


@pytest.mark.parametrize('code', [
pytest.param(
function_def,
marks=_mark,
),
pytest.param(
method_def,
marks=_mark,
),
function_def,
method_def,
])
@pytest.mark.parametrize('decorator', [
'some[1]',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from wemake_python_styleguide.violations.best_practices import (
ComplexDefaultValueViolation,
PositionalOnlyArgumentsViolation,
)
from wemake_python_styleguide.visitors.ast.functions import (
FunctionSignatureVisitor,
Expand Down Expand Up @@ -100,7 +99,6 @@ def test_wrong_function_defaults(
assert_errors(
visitor,
[ComplexDefaultValueViolation],
ignored_types=PositionalOnlyArgumentsViolation,
)


Expand Down Expand Up @@ -135,4 +133,4 @@ def test_correct_function_defaults(
visitor = FunctionSignatureVisitor(default_options, tree=tree)
visitor.run()

assert_errors(visitor, [], ignored_types=PositionalOnlyArgumentsViolation)
assert_errors(visitor, [])

0 comments on commit d4f70c6

Please sign in to comment.