From 05a312dde091e1b2e5b3aa81e6342797a2758917 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Fri, 12 Jul 2024 15:54:26 +0200 Subject: [PATCH] Use ruff linter --- .github/workflows/tests.yml | 2 ++ docs/conf.py | 3 ++- pyproject.toml | 6 +++++- tests/test_webencodings.py | 21 ++++++++++++++++----- webencodings/__init__.py | 1 - webencodings/x_user_defined.py | 1 - 6 files changed, 25 insertions(+), 9 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 19d9983..615ff3e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -23,3 +23,5 @@ jobs: run: python -m pip install .[test] - name: Launch tests run: python -m pytest + - name: Check coding style + run: python -m ruff check diff --git a/docs/conf.py b/docs/conf.py index a80c9e9..1321d88 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,7 +12,8 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys, os, re +import os +import re # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the diff --git a/pyproject.toml b/pyproject.toml index 329d164..6fbfe52 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,7 +39,11 @@ Changelog = 'https://github.com/gsnedders/python-webencodings/releases' [project.optional-dependencies] doc = ['sphinx'] -test = ['pytest'] +test = ['pytest', 'ruff'] [tool.flit.sdist] exclude = ['.*'] + +[tool.ruff.lint] +select = ['E', 'W', 'F', 'I', 'N', 'RUF'] +ignore = ['RUF001', 'RUF002', 'RUF003'] diff --git a/tests/test_webencodings.py b/tests/test_webencodings.py index 369c22c..3a8b027 100644 --- a/tests/test_webencodings.py +++ b/tests/test_webencodings.py @@ -11,8 +11,16 @@ """ from webencodings import ( - lookup, LABELS, decode, encode, iter_decode, iter_encode, IncrementalDecoder, - IncrementalEncoder, UTF8) + LABELS, + UTF8, + IncrementalDecoder, + IncrementalEncoder, + decode, + encode, + iter_decode, + iter_encode, + lookup, +) def assert_raises(exception, function, *args, **kwargs): @@ -77,10 +85,13 @@ def test_decode(): assert decode(b'\xc3\xa9', 'utf8') == ('é', lookup('utf8')) assert decode(b'\xc3\xa9', UTF8) == ('é', lookup('utf8')) assert decode(b'\xc3\xa9', 'ascii') == ('é', lookup('ascii')) - assert decode(b'\xEF\xBB\xBF\xc3\xa9', 'ascii') == ('é', lookup('utf8')) # UTF-8 with BOM + # UTF-8 with BOM + assert decode(b'\xEF\xBB\xBF\xc3\xa9', 'ascii') == ('é', lookup('utf8')) - assert decode(b'\xFE\xFF\x00\xe9', 'ascii') == ('é', lookup('utf-16be')) # UTF-16-BE with BOM - assert decode(b'\xFF\xFE\xe9\x00', 'ascii') == ('é', lookup('utf-16le')) # UTF-16-LE with BOM + # UTF-16-BE with BOM + assert decode(b'\xFE\xFF\x00\xe9', 'ascii') == ('é', lookup('utf-16be')) + # UTF-16-LE with BOM + assert decode(b'\xFF\xFE\xe9\x00', 'ascii') == ('é', lookup('utf-16le')) assert decode(b'\xFE\xFF\xe9\x00', 'ascii') == ('\ue900', lookup('utf-16be')) assert decode(b'\xFF\xFE\x00\xe9', 'ascii') == ('\ue900', lookup('utf-16le')) diff --git a/webencodings/__init__.py b/webencodings/__init__.py index 5064ce7..2027133 100644 --- a/webencodings/__init__.py +++ b/webencodings/__init__.py @@ -15,7 +15,6 @@ from .labels import LABELS - VERSION = __version__ = '0.6-dev' diff --git a/webencodings/x_user_defined.py b/webencodings/x_user_defined.py index 52efe3d..7052041 100644 --- a/webencodings/x_user_defined.py +++ b/webencodings/x_user_defined.py @@ -12,7 +12,6 @@ import codecs - ### Codec APIs class Codec(codecs.Codec):