diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f2b42a1..d140e42 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,16 +16,16 @@ jobs: strategy: matrix: include: - - dependencies: black python3-isort + - dependencies: ruff task: make -f Makefile fmt-travis - dependencies: yamllint task: make -f Makefile yamllint - dependencies: > - pylint python3-hypothesis python3-justbases python3-setuptools - task: PYTHONPATH=./src make -f Makefile lint + ruff + task: make -f Makefile lint - dependencies: > python3-hypothesis python3-justbases diff --git a/.isort.cfg b/.isort.cfg deleted file mode 100644 index 905be4a..0000000 --- a/.isort.cfg +++ /dev/null @@ -1,17 +0,0 @@ -[settings] -profile = black - -sections = FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCAL,LOCALFOLDER -default_section=THIRDPARTY - -import_heading_future=isort: FUTURE -import_heading_stdlib=isort: STDLIB -import_heading_thirdparty=isort: THIRDPARTY -import_heading_firstparty=isort: FIRSTPARTY -import_heading_local=isort: LOCAL - -# All items above should be the same for every -# Stratis project. The items below vary with -# each project. -known_local=justbytes -known_first_party=justbases diff --git a/Makefile b/Makefile index 15404e2..80db7ec 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,6 @@ .PHONY: lint lint: - pylint setup.py - pylint src/justbytes - pylint tests --disable=unnecessary-dunder-call + ruff check .PHONY: test test: @@ -16,13 +14,13 @@ coverage: .PHONY: fmt fmt: - isort setup.py src tests --skip src/justbytes/__init__.py - black . + ruff check --fix --select I + ruff format .PHONY: fmt-travis fmt-travis: - isort --diff --check-only setup.py src tests --skip src/justbytes/__init__.py - black . --check + ruff check --select I + ruff format --check PYREVERSE_OPTS = --output=pdf .PHONY: view diff --git a/doc/conf.py b/doc/conf.py index a49eba3..bad5698 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -11,7 +11,8 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys, os +import os +import sys import justbytes @@ -188,7 +189,7 @@ # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ - ("index", "justbytes.tex", "justbytes Documentation", "mulhern", "manual"), + ("index", "justbytes.tex", "justbytes Documentation", "mulhern", "manual") ] # The name of an image file (relative to this directory) to place at the top of @@ -236,7 +237,7 @@ "justbytes", "One line description of project.", "Miscellaneous", - ), + ) ] # Documents to append as an appendix to all manuals. diff --git a/pyproject.toml b/pyproject.toml index fed528d..10bbc1d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,17 @@ [build-system] requires = ["setuptools"] build-backend = "setuptools.build_meta" + +[tool.ruff] +target-version = "py312" +line-length = 88 + +[tool.ruff.lint] +select = ["PL"] + +[tool.ruff.lint.isort] +known-first-party = ["justbases"] +split-on-trailing-comma = false + +[tool.ruff.format] +skip-magic-trailing-comma = true diff --git a/setup.py b/setup.py index 4562db3..82aed6a 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,6 @@ Python packaging file for setup tools. """ -# isort: THIRDPARTY import setuptools setuptools.setup() diff --git a/src/justbytes/_config.py b/src/justbytes/_config.py index 9a01860..225987a 100644 --- a/src/justbytes/_config.py +++ b/src/justbytes/_config.py @@ -19,7 +19,6 @@ # pylint: disable=invalid-name -# isort: FIRSTPARTY import justbases from ._constants import PRECISE_NUMERIC_TYPES, UNITS, RoundingMethods @@ -33,8 +32,6 @@ class BaseConfig(justbases.BaseConfig): Override defaults of justbases.BaseConfig. """ - # pylint: disable=too-few-public-methods - def __init__(self, use_prefix=False, use_subscript=False): """ Initializer. @@ -55,8 +52,6 @@ class DisplayConfig(justbases.DisplayConfig): DisplayConfig overrides justbases.DisplayConfig's defaults. """ - # pylint: disable=too-few-public-methods - def __init__( self, show_approx_str=True, @@ -97,8 +92,6 @@ class ValueConfig: but 0.05 GiB is still displayed as 51.2 MiB. """ - # pylint: disable=too-few-public-methods - _FMT_STR = ", ".join( [ "base=%(base)s", @@ -111,7 +104,7 @@ class ValueConfig: ] ) - def __init__( # pylint: disable=too-many-positional-arguments + def __init__( # noqa: PLR0913 self, max_places=2, min_value=1, @@ -134,7 +127,7 @@ def __init__( # pylint: disable=too-many-positional-arguments :param base: numeric base :param rounding_method: one of RoundingMethods.METHODS() """ - # pylint: disable=too-many-arguments + if max_places is not None and max_places < 0: raise RangeValueError(max_places, "max_places", "must be an int at least 0") @@ -148,7 +141,7 @@ def __init__( # pylint: disable=too-many-positional-arguments unit, "unit", f"must be one of {', '.join(str(x) for x in UNITS())}" ) - if base < 2: + if base < 2: # noqa: PLR2004 raise RangeValueError(base, "base", "must be at least 2") self.max_places = max_places @@ -177,8 +170,6 @@ def __str__(self): class StringConfig: """Configuration for :class:`Range` class.""" - # pylint: disable=too-few-public-methods - def __init__(self, value_config, display_config, display_impl): """ Initializer. diff --git a/src/justbytes/_constants.py b/src/justbytes/_constants.py index a8dec8a..8d96b36 100644 --- a/src/justbytes/_constants.py +++ b/src/justbytes/_constants.py @@ -22,11 +22,9 @@ * Size units, e.g., Ki, Mi """ -# isort: STDLIB import abc from numbers import Rational -# isort: FIRSTPARTY import justbases from ._errors import RangeValueError @@ -37,8 +35,6 @@ class Unit: """Class to encapsulate unit information.""" - # pylint: disable=too-few-public-methods - def __init__(self, factor, prefix, abbr): self._factor = factor self._prefix = prefix @@ -49,7 +45,6 @@ def __str__(self): __repr__ = __str__ - # pylint: disable=protected-access factor = property(lambda s: s._factor, doc="numeric multiple of bytes") abbr = property(lambda s: s._abbr, doc="abbreviation for unit, precedes 'B'") prefix = property(lambda s: s._prefix, doc="prefix for 'bytes'") @@ -67,8 +62,6 @@ class Units(metaclass=abc.ABCMeta): Generic class for units. """ - # pylint: disable=too-few-public-methods - FACTOR = abc.abstractproperty(doc="factor for each unit") _UNITS = abc.abstractproperty(doc="ordered list of units") @@ -76,14 +69,14 @@ class Units(metaclass=abc.ABCMeta): _MAX_EXPONENT = None @classmethod - def UNITS(cls): # pylint: disable=invalid-name + def UNITS(cls): """ Units of this class. """ return cls._UNITS[:] @classmethod - def unit_for_exp(cls, exponent): # pylint: disable=invalid-name + def unit_for_exp(cls, exponent): """ Get the unit for the given exponent. @@ -112,9 +105,6 @@ def max_exponent(cls): class DecimalUnits(Units): """Class to store decimal unit constants.""" - # pylint: disable=invalid-name - # pylint: disable=too-few-public-methods - FACTOR = 10**3 KB = Unit(FACTOR**1, "kilo", "k") @@ -132,8 +122,6 @@ class DecimalUnits(Units): class BinaryUnits(Units): """Class to store binary unit constants.""" - # pylint: disable=too-few-public-methods - FACTOR = 2**10 KiB = Unit(FACTOR**1, "kibi", "Ki") @@ -148,7 +136,7 @@ class BinaryUnits(Units): _UNITS = [KiB, MiB, GiB, TiB, PiB, EiB, ZiB, YiB] -def UNITS(): # pylint: disable=invalid-name +def UNITS(): """All unit constants.""" return [B] + BinaryUnits.UNITS() + DecimalUnits.UNITS() diff --git a/src/justbytes/_errors.py b/src/justbytes/_errors.py index 76005b1..ad55173 100644 --- a/src/justbytes/_errors.py +++ b/src/justbytes/_errors.py @@ -17,7 +17,6 @@ """Exception types used by the justbytes class.""" -# isort: STDLIB import abc @@ -42,7 +41,7 @@ def __init__(self, value, param, msg=None): :param str param: the parameter :param str msg: an explanatory message """ - # pylint: disable=super-init-not-called + self.value = value self.param = param self.msg = msg @@ -74,7 +73,7 @@ def __init__(self, operator, other): :param str operator: the operator :param object other: the other argument """ - # pylint: disable=super-init-not-called + self._operator = operator self._other = other @@ -94,7 +93,7 @@ def __init__(self, operator, other): :param str operator: the operator :param object other: the other argument """ - # pylint: disable=super-init-not-called + self._operator = operator self._other = other diff --git a/src/justbytes/_generators.py b/src/justbytes/_generators.py index 5c4147a..29090c5 100644 --- a/src/justbytes/_generators.py +++ b/src/justbytes/_generators.py @@ -46,6 +46,6 @@ def next_or_last(pred, seq, default=None): if pred(elem): return elem try: - return elem # pylint: disable=undefined-loop-variable + return elem except NameError: return default diff --git a/src/justbytes/_size.py b/src/justbytes/_size.py index 2cb0a65..bcd76c5 100644 --- a/src/justbytes/_size.py +++ b/src/justbytes/_size.py @@ -24,10 +24,8 @@ expressions will cause an exception to be raised. """ -# isort: STDLIB from fractions import Fraction -# isort: FIRSTPARTY import justbases from ._config import Config @@ -107,7 +105,7 @@ def __init__(self, value=0, units=None): raise RangeValueError( units, "units", "meaningless when Range value is passed" ) - magnitude = value.magnitude # pylint: disable=no-member + magnitude = value.magnitude else: raise RangeValueError(value, "value") @@ -123,7 +121,7 @@ def magnitude(self): """ return self._magnitude - def getStringInfo(self, config): # pylint: disable=invalid-name + def getStringInfo(self, config): """ Return a representation of the size. @@ -135,7 +133,7 @@ def getStringInfo(self, config): # pylint: disable=invalid-name (result, relation) = self._as_single_number(magnitude, config) return (result, relation, units) - def getString(self, config): # pylint: disable=invalid-name + def getString(self, config): """ Return a string representation of the size. @@ -155,10 +153,10 @@ def __repr__(self): """ Use actual Fraction magnitude in result. """ - return f"Range({self._magnitude !r})" + return f"Range({self._magnitude!r})" def __deepcopy__(self, memo): - # pylint: disable=unused-argument + return Range(self._magnitude) def __nonzero__(self): @@ -275,7 +273,6 @@ def __lt__(self, other): raise RangeNonsensicalBinOpError("<", other) return self._magnitude < other.magnitude - # pylint: disable=raising-format-tuple def __mod__(self, other): # other * div + mod = self # Therefore, T(mod) = Range @@ -368,7 +365,7 @@ def __rtruediv__(self, other): __rdiv__ = __rtruediv__ - def convertTo(self, spec=None): # pylint: disable=invalid-name + def convertTo(self, spec=None): """ Return the size in the units indicated by the specifier. @@ -390,7 +387,7 @@ def convertTo(self, spec=None): # pylint: disable=invalid-name return self._magnitude / factor - def componentsList(self, binary_units=True): # pylint: disable=invalid-name + def componentsList(self, binary_units=True): """ Yield a representation of this size for every unit, decomposed into a Fraction value and a unit specifier @@ -437,10 +434,7 @@ def components(self, config=Config.STRING_CONFIG.VALUE_CONFIG): ) return candidates[-1] - def roundTo( - self, unit, rounding, bounds=(None, None) - ): # pylint: disable=invalid-name - # pylint: disable=line-too-long + def roundTo(self, unit, rounding, bounds=(None, None)): """ Rounds to unit specified as a named constant or a Range. diff --git a/src/justbytes/_sizes.py b/src/justbytes/_sizes.py index bf8e9a6..9bc7852 100644 --- a/src/justbytes/_sizes.py +++ b/src/justbytes/_sizes.py @@ -16,6 +16,7 @@ # Red Hat Author(s): Anne Mulhern """Class for methods that do not properly belong in the Range class.""" + from ._size import Range AI = Range(0) # pragma: no cover diff --git a/tests/test_deterministic/test_config.py b/tests/test_deterministic/test_config.py index 332d385..6ad7825 100644 --- a/tests/test_deterministic/test_config.py +++ b/tests/test_deterministic/test_config.py @@ -16,10 +16,9 @@ # Red Hat Author(s): Anne Mulhern """Test for configuration classes.""" -# isort: STDLIB + import unittest -# isort: LOCAL from justbytes._config import Config, ValueConfig from justbytes._errors import RangeValueError @@ -27,8 +26,6 @@ class ConfigTestCase(unittest.TestCase): """Exercise methods of output configuration classes.""" - # pylint: disable=too-few-public-methods - def test_value_config_object(self): """Miscellaneous tests for string configuration.""" self.assertIsInstance(str(Config.STRING_CONFIG.VALUE_CONFIG), str) diff --git a/tests/test_deterministic/test_constants.py b/tests/test_deterministic/test_constants.py index 85563f2..e9a703c 100644 --- a/tests/test_deterministic/test_constants.py +++ b/tests/test_deterministic/test_constants.py @@ -16,10 +16,9 @@ # Red Hat Author(s): Anne Mulhern """Test for constants classes.""" -# isort: STDLIB + import unittest -# isort: LOCAL from justbytes._constants import UNITS, B, BinaryUnits, DecimalUnits, RoundingMethods from justbytes._errors import RangeValueError diff --git a/tests/test_deterministic/test_errors.py b/tests/test_deterministic/test_errors.py index 9ef0873..505b721 100644 --- a/tests/test_deterministic/test_errors.py +++ b/tests/test_deterministic/test_errors.py @@ -16,10 +16,9 @@ # Red Hat Author(s): Anne Mulhern """Test for error classes.""" -# isort: STDLIB + import unittest -# isort: LOCAL from justbytes._errors import ( RangeFractionalResultError, RangeNonsensicalBinOpError, diff --git a/tests/test_deterministic/test_size/test_conversions.py b/tests/test_deterministic/test_size/test_conversions.py index e10992e..2bf167b 100644 --- a/tests/test_deterministic/test_size/test_conversions.py +++ b/tests/test_deterministic/test_size/test_conversions.py @@ -17,11 +17,9 @@ """Tests for operations on Range objects.""" -# isort: STDLIB import copy import unittest -# isort: LOCAL from justbytes import Range diff --git a/tests/test_deterministic/test_size/test_initializer.py b/tests/test_deterministic/test_size/test_initializer.py index daa2ca4..565ceec 100644 --- a/tests/test_deterministic/test_size/test_initializer.py +++ b/tests/test_deterministic/test_size/test_initializer.py @@ -17,11 +17,9 @@ """Tests for Range initialization.""" -# isort: STDLIB import unittest from decimal import Decimal -# isort: LOCAL from justbytes import B, Range from justbytes._errors import RangeValueError diff --git a/tests/test_deterministic/test_size/test_named.py b/tests/test_deterministic/test_size/test_named.py index b7d2ba7..33a64c2 100644 --- a/tests/test_deterministic/test_size/test_named.py +++ b/tests/test_deterministic/test_size/test_named.py @@ -17,10 +17,8 @@ """Tests for named methods of Range objects.""" -# isort: STDLIB import unittest -# isort: LOCAL from justbytes import ROUND_HALF_UP, B, Config, Range, StringConfig, ValueConfig from justbytes._errors import RangeValueError diff --git a/tests/test_deterministic/test_size/test_operations.py b/tests/test_deterministic/test_size/test_operations.py index 8cecfbb..4a64872 100644 --- a/tests/test_deterministic/test_size/test_operations.py +++ b/tests/test_deterministic/test_size/test_operations.py @@ -17,11 +17,9 @@ """Tests for operations on Range objects.""" -# isort: STDLIB import unittest from decimal import Decimal -# isort: LOCAL from justbytes import B, GiB, MiB, Range, TiB from justbytes._errors import ( RangeNonsensicalBinOpError, @@ -39,12 +37,10 @@ def test_binary_operators_range(self): # ** with self.assertRaises(RangeNonsensicalBinOpError): - # pylint: disable=expression-not-assigned, pointless-statement size ** Range(2) with self.assertRaises(RangePowerResultError): - size**2 # pylint: disable=pointless-statement + size**2 with self.assertRaises(RangeNonsensicalBinOpError): - # pylint: disable=expression-not-assigned, pointless-statement 2 ** Range(0) def test_binary_operators_boolean(self): @@ -53,30 +49,30 @@ def test_binary_operators_boolean(self): # < self.assertTrue(Range(0, MiB) < Range(32)) with self.assertRaises(RangeNonsensicalBinOpError): - Range(0) < 1 # pylint: disable=expression-not-assigned + Range(0) < 1 with self.assertRaises(RangeNonsensicalBinOpError): - 1 < Range(32, TiB) # pylint: disable=expression-not-assigned + 1 < Range(32, TiB) # <= self.assertTrue(Range(0, MiB) <= Range(32)) with self.assertRaises(RangeNonsensicalBinOpError): - Range(0) <= 1 # pylint: disable=expression-not-assigned + Range(0) <= 1 with self.assertRaises(RangeNonsensicalBinOpError): - 1 <= Range(32, TiB) # pylint: disable=expression-not-assigned + 1 <= Range(32, TiB) # > self.assertTrue(Range(32, MiB) > Range(32)) with self.assertRaises(RangeNonsensicalBinOpError): - Range(32) > 1 # pylint: disable=expression-not-assigned + Range(32) > 1 with self.assertRaises(RangeNonsensicalBinOpError): - 1 > Range(0, TiB) # pylint: disable=expression-not-assigned + 1 > Range(0, TiB) # >= self.assertTrue(Range(32, MiB) >= Range(32)) with self.assertRaises(RangeNonsensicalBinOpError): - Range(32) >= 1 # pylint: disable=expression-not-assigned + Range(32) >= 1 with self.assertRaises(RangeNonsensicalBinOpError): - 1 >= Range(0, TiB) # pylint: disable=expression-not-assigned + 1 >= Range(0, TiB) # != self.assertTrue(Range(32, MiB) != Range(32, GiB)) @@ -106,7 +102,7 @@ class AdditionTestCase(unittest.TestCase): def test_exceptions(self): """Any non-size other raises an exception.""" - # pylint: disable=expression-not-assigned + with self.assertRaises(RangeNonsensicalBinOpError): 2 + Range(0) with self.assertRaises(RangeNonsensicalBinOpError): @@ -118,7 +114,7 @@ class DivmodTestCase(unittest.TestCase): def test_exceptions(self): """Test that exceptions are thrown.""" - # pylint: disable=expression-not-assigned + with self.assertRaises(RangeNonsensicalBinOpError): divmod(2048, Range(12, B)) with self.assertRaises(RangeNonsensicalBinOpError): @@ -136,7 +132,7 @@ class FloordivTestCase(unittest.TestCase): def test_exceptions(self): """Test that exceptions are thrown.""" - # pylint: disable=expression-not-assigned + with self.assertRaises(RangeNonsensicalBinOpError): 2048 // Range(12, B) with self.assertRaises(RangeNonsensicalBinOpError): @@ -154,11 +150,11 @@ class ModTestCase(unittest.TestCase): def test_exceptions(self): """Test that exceptions are thrown.""" - # pylint: disable=expression-not-assigned + with self.assertRaises(RangeNonsensicalBinOpError): 2048 % Range(12, B) with self.assertRaises(RangeNonsensicalBinOpError): - Range(12) % "str" # pylint: disable=consider-using-f-string + Range(12) % "str" with self.assertRaises(RangeNonsensicalBinOpValueError): Range(12) % Range(0) with self.assertRaises(RangeNonsensicalBinOpValueError): @@ -172,7 +168,7 @@ class MultiplicationTestCase(unittest.TestCase): def test_exceptions(self): """Range others are unrepresentable.""" - # pylint: disable=expression-not-assigned + with self.assertRaises(RangePowerResultError): Range(0) * Range(0) with self.assertRaises(RangeNonsensicalBinOpError): @@ -186,7 +182,7 @@ class RdivmodTestCase(unittest.TestCase): def test_exceptions(self): """Test that exceptions are thrown.""" - # pylint: disable=expression-not-assigned + with self.assertRaises(RangeNonsensicalBinOpError): Range(12).__rdivmod__(str) with self.assertRaises(RangeNonsensicalBinOpValueError): @@ -200,7 +196,7 @@ class RfloordivTestCase(unittest.TestCase): def test_exceptions(self): """Test that exceptions are thrown.""" - # pylint: disable=expression-not-assigned + with self.assertRaises(RangeNonsensicalBinOpError): Range(12, B).__rfloordiv__(1024) with self.assertRaises(RangeNonsensicalBinOpValueError): @@ -214,7 +210,7 @@ class RmodTestCase(unittest.TestCase): def test_exceptions(self): """Test that exceptions are thrown.""" - # pylint: disable=expression-not-assigned + with self.assertRaises(RangeNonsensicalBinOpError): Range(12, B).__rmod__(1024) with self.assertRaises(RangeNonsensicalBinOpError): @@ -230,7 +226,7 @@ class RsubTestCase(unittest.TestCase): def test_exceptions(self): """Any non-size other raises an exception.""" - # pylint: disable=expression-not-assigned + with self.assertRaises(RangeNonsensicalBinOpError): Range(0).__rsub__(2) @@ -240,7 +236,7 @@ class RtruedivTestCase(unittest.TestCase): def test_exceptions(self): """Test that exceptions are thrown.""" - # pylint: disable=expression-not-assigned + with self.assertRaises(RangeNonsensicalBinOpError): Range(12, B).__rtruediv__(1024) with self.assertRaises(RangeNonsensicalBinOpError): @@ -256,7 +252,7 @@ class SubtractionTestCase(unittest.TestCase): def test_exceptions(self): """Any non-size other raises an exception.""" - # pylint: disable=expression-not-assigned + with self.assertRaises(RangeNonsensicalBinOpError): 2 - Range(0) with self.assertRaises(RangeNonsensicalBinOpError): @@ -268,7 +264,7 @@ class TruedivTestCase(unittest.TestCase): def test_exceptions(self): """Test that exceptions are thrown.""" - # pylint: disable=expression-not-assigned + with self.assertRaises(RangeNonsensicalBinOpError): 2048 / Range(12, B) with self.assertRaises(RangeNonsensicalBinOpError): diff --git a/tests/test_deterministic/test_size/test_size.py b/tests/test_deterministic/test_size/test_size.py index db88a32..227ec2f 100644 --- a/tests/test_deterministic/test_size/test_size.py +++ b/tests/test_deterministic/test_size/test_size.py @@ -17,11 +17,9 @@ """Tests for behavior of Range objects.""" -# isort: STDLIB import unittest from fractions import Fraction -# isort: LOCAL from justbytes import ( KB, B, diff --git a/tests/test_deterministic/test_version.py b/tests/test_deterministic/test_version.py index e243343..c1d42d7 100644 --- a/tests/test_deterministic/test_version.py +++ b/tests/test_deterministic/test_version.py @@ -16,10 +16,9 @@ # Red Hat Author(s): Anne Mulhern """Test for version information.""" -# isort: STDLIB + import unittest -# isort: LOCAL import justbytes diff --git a/tests/test_hypothesis/test_config.py b/tests/test_hypothesis/test_config.py index 1c846e9..45a842b 100644 --- a/tests/test_hypothesis/test_config.py +++ b/tests/test_hypothesis/test_config.py @@ -16,13 +16,11 @@ # Red Hat Author(s): Anne Mulhern """Test for configuration classes.""" -# isort: STDLIB + import unittest -# isort: THIRDPARTY from hypothesis import given, settings, strategies -# isort: LOCAL from justbytes._config import Config, DisplayConfig, ValueConfig from justbytes._constants import UNITS @@ -30,8 +28,6 @@ class RangeTestCase(unittest.TestCase): """Test Range configuration.""" - # pylint: disable=too-few-public-methods - def setUp(self): self.display_config = Config.STRING_CONFIG.DISPLAY_CONFIG self.str_config = Config.STRING_CONFIG.VALUE_CONFIG diff --git a/tests/test_hypothesis/test_constants.py b/tests/test_hypothesis/test_constants.py index 10fc171..6c9d413 100644 --- a/tests/test_hypothesis/test_constants.py +++ b/tests/test_hypothesis/test_constants.py @@ -16,13 +16,11 @@ # Red Hat Author(s): Anne Mulhern """Test for constants classes.""" -# isort: STDLIB + import unittest -# isort: THIRDPARTY from hypothesis import given, strategies -# isort: LOCAL from justbytes._constants import BinaryUnits, DecimalUnits diff --git a/tests/test_hypothesis/test_size/test_conversions.py b/tests/test_hypothesis/test_size/test_conversions.py index af00f54..eb4688e 100644 --- a/tests/test_hypothesis/test_size/test_conversions.py +++ b/tests/test_hypothesis/test_size/test_conversions.py @@ -17,13 +17,10 @@ """Tests for operations on Range objects.""" -# isort: STDLIB import unittest -# isort: THIRDPARTY from hypothesis import given, settings, strategies -# isort: LOCAL from justbytes import UNITS, Range @@ -44,4 +41,4 @@ def test_int(self, size, unit): @settings(max_examples=50) def test_repr(self, value): """Test that repr looks right.""" - self.assertEqual(f"{value !r}", f"Range({value.magnitude !r})") + self.assertEqual(f"{value!r}", f"Range({value.magnitude!r})") diff --git a/tests/test_hypothesis/test_size/test_initializer.py b/tests/test_hypothesis/test_size/test_initializer.py index c74c424..3aec647 100644 --- a/tests/test_hypothesis/test_size/test_initializer.py +++ b/tests/test_hypothesis/test_size/test_initializer.py @@ -17,14 +17,11 @@ """Tests for Range initialization.""" -# isort: STDLIB import unittest from fractions import Fraction -# isort: THIRDPARTY from hypothesis import given, settings, strategies -# isort: LOCAL from justbytes import UNITS, Range diff --git a/tests/test_hypothesis/test_size/test_named.py b/tests/test_hypothesis/test_size/test_named.py index 3b1f228..c98f89c 100644 --- a/tests/test_hypothesis/test_size/test_named.py +++ b/tests/test_hypothesis/test_size/test_named.py @@ -17,15 +17,12 @@ """Tests for named methods of Range objects.""" -# isort: STDLIB import string import unittest from fractions import Fraction -# isort: THIRDPARTY from hypothesis import assume, example, given, settings, strategies -# isort: LOCAL from justbytes import ( ROUND_DOWN, ROUND_HALF_DOWN, @@ -44,8 +41,7 @@ ValueConfig, ) from justbytes._constants import UNITS, BinaryUnits, DecimalUnits - -from tests.test_hypothesis.test_size.utils import SIZE_STRATEGY # isort:skip +from tests.test_hypothesis.test_size.utils import SIZE_STRATEGY class ConversionTestCase(unittest.TestCase): @@ -124,7 +120,7 @@ def test_config(self, a_size, config, base): ) ) - if config.base_config.use_prefix and base == 16: + if config.base_config.use_prefix and base == 16: # noqa: PLR2004 self.assertNotEqual(result.find("0x"), -1) @@ -185,7 +181,7 @@ def test_bounds(self, size, unit, rounding, bounds): """ (lower, upper) = bounds assume(lower is None or upper is None or lower <= upper) - rounded = size.roundTo(unit, rounding, bounds) # pylint: disable=unreachable + rounded = size.roundTo(unit, rounding, bounds) self.assertTrue(lower is None or lower <= rounded) self.assertTrue(upper is None or upper >= rounded) @@ -198,9 +194,9 @@ def test_bounds(self, size, unit, rounding, bounds): strategies.sampled_from(ROUNDING_METHODS()), ) @example(Range(32), Range(0), ROUND_DOWN) - def test_results(self, size, unit, rounding): + def test_results(self, size, unit, rounding): # noqa: PLR0912 """Test roundTo results.""" - # pylint: disable=too-many-branches + rounded = size.roundTo(unit, rounding) if (isinstance(unit, Range) and unit.magnitude == 0) or ( @@ -239,13 +235,11 @@ def test_results(self, size, unit, rounding): self.assertEqual(rounded, ceiling) elif remainder < half: self.assertEqual(rounded, floor) + elif rounding is ROUND_HALF_UP: + self.assertEqual(rounded, ceiling) + elif rounding is ROUND_HALF_DOWN: + self.assertEqual(rounded, floor) + elif size > Range(0): + self.assertEqual(rounded, floor) else: - if rounding is ROUND_HALF_UP: - self.assertEqual(rounded, ceiling) - elif rounding is ROUND_HALF_DOWN: - self.assertEqual(rounded, floor) - else: - if size > Range(0): - self.assertEqual(rounded, floor) - else: - self.assertEqual(rounded, ceiling) + self.assertEqual(rounded, ceiling) diff --git a/tests/test_hypothesis/test_size/test_operations.py b/tests/test_hypothesis/test_size/test_operations.py index 1bd5070..8d0ac8d 100644 --- a/tests/test_hypothesis/test_size/test_operations.py +++ b/tests/test_hypothesis/test_size/test_operations.py @@ -17,20 +17,15 @@ """Tests for operations on Range objects.""" -# isort: STDLIB import copy import unittest from decimal import Decimal from fractions import Fraction -# isort: THIRDPARTY from hypothesis import given, settings -# isort: LOCAL from justbytes import Range - -from tests.test_hypothesis.test_size.utils import NUMBERS_STRATEGY # isort:skip -from tests.test_hypothesis.test_size.utils import SIZE_STRATEGY # isort:skip +from tests.test_hypothesis.test_size.utils import NUMBERS_STRATEGY, SIZE_STRATEGY class AdditionTestCase(unittest.TestCase): @@ -228,7 +223,6 @@ class ArithmeticPropertiesTestCase(unittest.TestCase): NUMBERS_STRATEGY.filter(lambda n: not isinstance(n, Decimal)), ) @settings(max_examples=10) - # pylint: disable=invalid-name def test_distributivity1(self, s, n, m): """ Assert distributivity across numbers. @@ -237,7 +231,6 @@ def test_distributivity1(self, s, n, m): @given(SIZE_STRATEGY, SIZE_STRATEGY, NUMBERS_STRATEGY) @settings(max_examples=10) - # pylint: disable=invalid-name def test_distributivity2(self, p, q, n): """ Assert distributivity across sizes. @@ -246,7 +239,6 @@ def test_distributivity2(self, p, q, n): @given(SIZE_STRATEGY, SIZE_STRATEGY, SIZE_STRATEGY) @settings(max_examples=10) - # pylint: disable=invalid-name def test_associativity(self, p, q, r): """ Assert associativity across sizes. diff --git a/tests/test_hypothesis/test_size/utils.py b/tests/test_hypothesis/test_size/utils.py index 82a412a..0547a93 100644 --- a/tests/test_hypothesis/test_size/utils.py +++ b/tests/test_hypothesis/test_size/utils.py @@ -16,10 +16,9 @@ # Red Hat Author(s): Anne Mulhern """Utilities for testing.""" -# isort: THIRDPARTY + from hypothesis import strategies -# isort: LOCAL from justbytes import UNITS, Range NUMBERS_STRATEGY = strategies.one_of( diff --git a/tests/test_hypothesis/test_util.py b/tests/test_hypothesis/test_util.py index 7669e8a..4d8d81c 100644 --- a/tests/test_hypothesis/test_util.py +++ b/tests/test_hypothesis/test_util.py @@ -17,13 +17,10 @@ """Test for utility functions.""" -# isort: STDLIB import unittest -# isort: THIRDPARTY from hypothesis import given, settings, strategies -# isort: LOCAL from justbytes._generators import next_or_last, takeuntil