Skip to content

Commit

Permalink
Merge pull request #23 from vmalloc/python312-support
Browse files Browse the repository at this point in the history
Python 3.12 support
  • Loading branch information
ayalash authored Nov 3, 2023
2 parents 1eb323f + d3765ba commit a705352
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 40 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v2
Expand All @@ -21,8 +21,10 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint pytest
pip install .[testing]
- name: Pylint
run: |
pylint --rcfile=.pylintrc dessert tests
- name: Test with pytest
run: |
pytest
11 changes: 11 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[MESSAGES CONTROL]
disable= R,attribute-defined-outside-init,bad-continuation,bad-option-value,bare-except,invalid-name,locally-disabled,missing-docstring,redefined-builtin,ungrouped-imports,wrong-import-order,wrong-import-position,unnecessary-pass,import-outside-toplevel,consider-using-f-string,redundant-u-string-prefix,unspecified-encoding,unnecessary-lambda-assignment,use-implicit-booleaness-not-comparison,raise-missing-from,superfluous-parens

[REPORTS]
reports=no
# Ignoring 'StackedObject' due to bug in astroid/pylint: https://github.com/PyCQA/pylint/issues/3116
# Activatable seems like the same bug
ignored-classes=ColorizedString,StackedObject,Activatable,AbstractContextManager

[FORMAT]
max-line-length=150
10 changes: 8 additions & 2 deletions dessert/__version__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import pkg_resources
import sys
if sys.version_info < (3, 8):
import pkg_resources
get_distribution = pkg_resources.get_distribution
else:
from importlib.metadata import distribution
get_distribution = distribution

__version__ = pkg_resources.get_distribution('dessert').version
__version__ = get_distribution('dessert').version
2 changes: 1 addition & 1 deletion dessert/rewrite.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Rewrite assertion AST to produce nice error messages"""
# pylint: disable=protected-access,unused-import,logging-not-lazy,duplicate-string-formatting-argument,logging-format-interpolation,too-many-lines
# pylint: disable=protected-access,unused-import,logging-not-lazy,duplicate-string-formatting-argument,logging-format-interpolation,too-many-lines,unused-argument,broad-exception-caught
import ast
import errno
import functools
Expand Down
8 changes: 4 additions & 4 deletions dessert/saferepr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def _format_repr_exception(exc, obj):
exc_name = type(exc).__name__
try:
exc_info = str(exc)
except Exception:
except Exception: # pylint: disable=broad-exception-caught
exc_info = "unknown"
return '<[{}("{}") raised in repr()] {} object at 0x{:x}>'.format(
exc_name, exc_info, obj.__class__.__name__, id(obj)
Expand Down Expand Up @@ -34,14 +34,14 @@ def __init__(self, maxsize):
def repr(self, x):
try:
s = super().repr(x)
except Exception as exc:
except Exception as exc: # pylint: disable=broad-exception-caught
s = _format_repr_exception(exc, x)
return _ellipsize(s, self.maxsize)

def repr_instance(self, x, level):
try:
s = repr(x)
except Exception as exc:
except Exception as exc: # pylint: disable=broad-exception-caught
s = _format_repr_exception(exc, x)
return _ellipsize(s, self.maxsize)

Expand All @@ -53,7 +53,7 @@ def safeformat(obj):
"""
try:
return pprint.pformat(obj)
except Exception as exc:
except Exception as exc: # pylint: disable=broad-exception-caught
return _format_repr_exception(exc, obj)


Expand Down
9 changes: 4 additions & 5 deletions dessert/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def format_explanation(explanation, original_msg=None):
"""
if not conf.is_message_introspection_enabled() and original_msg:
return original_msg
explanation = explanation
lines = _split_explanation(explanation)
result = _format_lines(lines)
return "\n".join(result)
Expand Down Expand Up @@ -165,7 +164,7 @@ def assertrepr_compare(config, op, left, right):
elif op == "not in":
if istext(left) and istext(right):
explanation = _notin_text(left, right, verbose)
except Exception:
except Exception: # pylint: disable=broad-exception-caught
_logger.exception("dessert: representation of details failed. "
"Probably an object has a faulty __repr__.")

Expand Down Expand Up @@ -280,7 +279,7 @@ def _compare_eq_iterable(left, right, verbose=0):
return explanation


def _compare_eq_sequence(left, right, verbose=0):
def _compare_eq_sequence(left, right, verbose=0): # pylint: disable=unused-argument
comparing_bytes = isinstance(left, bytes) and isinstance(right, bytes)
explanation = [] # type: List[str]
len_left = len(left)
Expand Down Expand Up @@ -334,7 +333,7 @@ def _compare_eq_sequence(left, right, verbose=0):
return explanation


def _compare_eq_set(left, right, verbose=0):
def _compare_eq_set(left, right, verbose=0): # pylint: disable=unused-argument
explanation = []
diff_left = left - right
diff_right = right - left
Expand Down Expand Up @@ -389,7 +388,7 @@ def _compare_eq_dict(left, right, verbose=False):


def _compare_eq_cls(left, right, verbose, type_fns):
isdatacls, isattrs = type_fns
isdatacls, isattrs = type_fns # pylint: disable=redefined-outer-name
if isdatacls(left):
all_fields = left.__dataclass_fields__
fields_to_check = [field for field, info in all_fields.items() if info.compare]
Expand Down
3 changes: 0 additions & 3 deletions dessert/warning_types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import warnings


class DessertWarning(UserWarning):
__module__ = "dessert"

Expand Down
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ build-backend = "setuptools.build_meta"
name = "dessert"
description = "Assertion introspection via AST rewriting"
readme = "README.md"
requires-python = ">=3.5"
requires-python = ">=3.7"
license = { text = "MIT" }

classifiers = [
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]

dependencies = ["munch", "py", "atomicwrites>=1.0", "attrs"]
Expand All @@ -29,7 +28,7 @@ authors = [{ name = "Rotem Yaari", email = "[email protected]" }]
"GitHub" = "https://github.com/vmalloc/dessert"

[project.optional-dependencies]
testing = ["pytest", "emport>=1.1.1"]
testing = ["pytest", "emport>=1.1.1", "pylint"]

[tool.hatch.version]
source = "vcs"
Expand Down
2 changes: 1 addition & 1 deletion tests/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import dessert

with dessert.rewrite_assertions_context():
import examples
import examples # pylint: disable=import-error

func = getattr(examples, example_name)
try:
Expand Down
32 changes: 19 additions & 13 deletions tests/test_dessert.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ def func():
with _disable_pytest_rewriting():
with pytest.warns((UserWarning)) as caught:
emport.import_file(full_path)
[warning] = caught.list
# caught.list is list of warnings.WarningMessage
# The message member is the actual warning
[warning] = [
x
for x in caught.list
if isinstance(x.message, UserWarning)
]
assert warning.filename == full_path


Expand All @@ -59,8 +65,8 @@ def mark_dessert():
assert not dessert.rewrite._MARK_ASSERTION_INTROSPECTION
dessert.rewrite._MARK_ASSERTION_INTROSPECTION = True

@pytest.fixture
def module(request, source_filename):
@pytest.fixture(name="module")
def module_fx(request, source_filename):
with dessert.rewrite_assertions_context():
with _disable_pytest_rewriting():
module = emport.import_file(source_filename)
Expand Down Expand Up @@ -91,26 +97,26 @@ def _disable_introspection():
dessert.enable_message_introspection()


@pytest.fixture(params=[
@pytest.fixture(name="assertion_line", params=[
"assert x() + y()",
"assert f(1) > g(100)",
"assert f(g(2)) == f(g(1))",
])
def assertion_line(request):
def assertion_line_fx(request):
return request.param


@pytest.fixture(params=[True, False])
def add_assert_message(request):
@pytest.fixture(name="add_assert_message", params=[True, False])
def add_assert_message_fx(request):
return request.param

@pytest.fixture
def assert_message(request):
@pytest.fixture(name="assert_message")
def assert_message_fx():
return 'msg'


@pytest.fixture
def source(assertion_line, add_assert_message, assert_message):
@pytest.fixture(name="source")
def source_fx(assertion_line, add_assert_message, assert_message):
if add_assert_message:
assertion_line += ", '{}'".format(assert_message)
returned = """def f(x):
Expand All @@ -129,8 +135,8 @@ def func():
return returned


@pytest.fixture
def source_filename(request, source):
@pytest.fixture(name="source_filename")
def source_filename_fx(request, source):
path = mkdtemp()

@request.addfinalizer
Expand Down
4 changes: 2 additions & 2 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def test_example_message_assertion(run_example):



@pytest.fixture
def run_example(tmpdir):
@pytest.fixture(name="run_example")
def run_example_fx(tmpdir):
here = os.path.dirname(__file__)
shutil.copy(os.path.join(here, 'driver.py'), str(tmpdir))
shutil.copy(os.path.join(here, 'examples.py'), str(tmpdir))
Expand Down
4 changes: 2 additions & 2 deletions tests/test_readme_doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def test_readme_doctests(tmp_filename):
result = doctest.testfile(readme_path, module_relative=False, globs={"tmp_filename": tmp_filename})
assert result.failed == 0

@pytest.fixture
def tmp_filename(request):
@pytest.fixture(name="tmp_filename")
def tmp_filename_fx(request):
tmp_dir = tempfile.mkdtemp()
@request.addfinalizer
def delete():
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py35,py36,py37,py38,py39,py310
envlist = py37,py38,py39,py310,py311,py312

[testenv]
commands = pytest
Expand Down

0 comments on commit a705352

Please sign in to comment.