Skip to content

Commit

Permalink
Fix test_ne in test_cmp.py for Python 3.13
Browse files Browse the repository at this point in the history
Compiler in Python 3.13+ strips indents from docstrings
so they need to be compared without it for new Pythons.

Fixes: #1228
  • Loading branch information
frenzymadness committed Mar 7, 2024
1 parent b9084fa commit 69269b9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/attr/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
PY_3_9_PLUS = sys.version_info[:2] >= (3, 9)
PY310 = sys.version_info[:2] >= (3, 10)
PY_3_12_PLUS = sys.version_info[:2] >= (3, 12)
PY_3_13_PLUS = sys.version_info[:2] >= (3, 13)


if sys.version_info < (3, 8):
Expand Down
11 changes: 7 additions & 4 deletions tests/test_cmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
Tests for methods from `attrib._cmp`.
"""


import pytest

from attr._cmp import cmp_using
from attr._compat import PY_3_13_PLUS


# Test parameters.
Expand Down Expand Up @@ -54,6 +54,9 @@
cmp_data = eq_data + order_data
cmp_ids = eq_ids + order_ids

# Compiler strips indents from docstrings in Python 3.13+
indent = "" if PY_3_13_PLUS else " " * 8


class TestEqOrder:
"""
Expand Down Expand Up @@ -325,7 +328,7 @@ def test_ne(self):
method = self.cls.__ne__
assert method.__doc__.strip() == (
"Check equality and either forward a NotImplemented or\n"
" return the result negated."
f"{indent}return the result negated."
)
assert method.__name__ == "__ne__"

Expand Down Expand Up @@ -393,7 +396,7 @@ def test_ne(self):
method = self.cls.__ne__
assert method.__doc__.strip() == (
"Check equality and either forward a NotImplemented or\n"
" return the result negated."
f"{indent}return the result negated."
)
assert method.__name__ == "__ne__"

Expand Down Expand Up @@ -465,7 +468,7 @@ def test_ne(self):
method = self.cls.__ne__
assert method.__doc__.strip() == (
"Check equality and either forward a NotImplemented or\n"
" return the result negated."
f"{indent}return the result negated."
)
assert method.__name__ == "__ne__"

Expand Down

0 comments on commit 69269b9

Please sign in to comment.