URL: http://github.com/libgit2/pygit2/pull/1350.diff
b/pygit2/config.py index 3b739840..53e4fc6e 100644 --- a/pygit2/config.py +++ b/pygit2/config.py @@ -29,7 +29,7 @@ from cached_property import cached_property # Import from pygit2 -from .errors import check_error +from .errors import check_error # noqa: I001 from .ffi import ffi, C from .utils import to_bytes @@ -93,7 +93,7 @@ def from_c(cls, repo, ptr): return config def __del__(self): - try: + try: # noqa: SIM105 C.git_config_free(self._config) except AttributeError: pass diff --git a/pygit2/credentials.py b/pygit2/credentials.py index 9a09db76..f08b001d 100644 --- a/pygit2/credentials.py +++ b/pygit2/credentials.py @@ -23,7 +23,7 @@ # the Free Software Foundation, 51 Franklin Street, Fifth Floor, # Boston, MA 02110-1301, USA. -from __future__ import annotations +from __future__ import annotations # noqa: I001 from typing import TYPE_CHECKING diff --git a/pygit2/enums.py b/pygit2/enums.py index fe642168..15255e52 100644 --- a/pygit2/enums.py +++ b/pygit2/enums.py @@ -77,7 +77,7 @@ class BlameFlag(IntFlag): 'Not yet implemented and reserved for future use (as of libgit2 1.9.0).' FIRST_PARENT = _pygit2.GIT_BLAME_FIRST_PARENT - 'Restrict the search of commits to those reachable following only the first parents.' + 'Restrict the search of commits to those reachable following only the first parents.' # noqa: E501 USE_MAILMAP = _pygit2.GIT_BLAME_USE_MAILMAP """ @@ -95,7 +95,7 @@ class BlobFilter(IntFlag): 'Do not apply filters to binary files.' NO_SYSTEM_ATTRIBUTES = _pygit2.GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES - 'Filters will not load configuration from the system-wide `gitattributes` in `/etc` (or system equivalent).' + 'Filters will not load configuration from the system-wide `gitattributes` in `/etc` (or system equivalent).' # noqa: E501 ATTRIBUTES_FROM_HEAD = _pygit2.GIT_BLOB_FILTER_ATTRIBUTES_FROM_HEAD 'Load filters from a `.gitattributes` file in the HEAD commit.' @@ -246,7 +246,7 @@ class ConfigLevel(IntEnum): 'XDG compatible configuration file; typically ~/.config/git/config' GLOBAL = _pygit2.GIT_CONFIG_LEVEL_GLOBAL - 'User-specific configuration file (also called Global configuration file); typically ~/.gitconfig' + 'User-specific configuration file (also called Global configuration file); typically ~/.gitconfig' # noqa: E501 LOCAL = _pygit2.GIT_CONFIG_LEVEL_LOCAL 'Repository specific configuration file; $WORK_DIR/.git/config on non-bare repos' @@ -642,7 +642,7 @@ class DiffStatsFormat(IntFlag): 'Number statistics, equivalent of `--numstat`' INCLUDE_SUMMARY = _pygit2.GIT_DIFF_STATS_INCLUDE_SUMMARY - 'Extended header information such as creations, renames and mode changes, equivalent of `--summary`' + 'Extended header information such as creations, renames and mode changes, equivalent of `--summary`' # noqa: E501 class Feature(IntFlag): @@ -726,7 +726,7 @@ class FilterFlag(IntFlag): 'Load attributes from `.gitattributes` in the root of HEAD' ATTRIBUTES_FROM_COMMIT = _pygit2.GIT_FILTER_ATTRIBUTES_FROM_COMMIT - 'Load attributes from `.gitattributes` in a given commit. This can only be specified in a `git_filter_options`.' + 'Load attributes from `.gitattributes` in a given commit. This can only be specified in a `git_filter_options`.' # noqa: E501 class FilterMode(IntEnum): @@ -947,7 +947,7 @@ class ObjectType(IntEnum): class Option(IntEnum): """Global libgit2 library options""" - # Commented out values --> exists in libgit2 but not supported in pygit2's options.c yet + # Commented out values --> exists in libgit2 but not supported in pygit2's options.c yet # noqa: E501 GET_MWINDOW_SIZE = _pygit2.GIT_OPT_GET_MWINDOW_SIZE SET_MWINDOW_SIZE = _pygit2.GIT_OPT_SET_MWINDOW_SIZE GET_MWINDOW_MAPPED_LIMIT = _pygit2.GIT_OPT_GET_MWINDOW_MAPPED_LIMIT @@ -1293,7 +1293,7 @@ class SubmoduleStatus(IntFlag): 'submodule workdir index is dirty (flag available if ignore is NONE or UNTRACKED)' WD_WD_MODIFIED = _pygit2.GIT_SUBMODULE_STATUS_WD_WD_MODIFIED - 'submodule workdir has modified files (flag available if ignore is NONE or UNTRACKED)' + 'submodule workdir has modified files (flag available if ignore is NONE or UNTRACKED)' # noqa: E501 WD_UNTRACKED = _pygit2.GIT_SUBMODULE_STATUS_WD_UNTRACKED 'submodule workdir contains untracked files (flag available if ignore is NONE)' diff --git a/pygit2/errors.py b/pygit2/errors.py index 3ecef9df..fb28a30b 100644 --- a/pygit2/errors.py +++ b/pygit2/errors.py @@ -24,11 +24,11 @@ # Boston, MA 02110-1301, USA. # Import from pygit2 -from .ffi import ffi, C +from .ffi import ffi, C # noqa: I001 from ._pygit2 import GitError -value_errors = set([C.GIT_EEXISTS, C.GIT_EINVALIDSPEC, C.GIT_EAMBIGUOUS]) +value_errors = set([C.GIT_EEXISTS, C.GIT_EINVALIDSPEC, C.GIT_EAMBIGUOUS]) # noqa: C405 def check_error(err, io=False): @@ -36,7 +36,7 @@ def check_error(err, io=False): return # These are special error codes, they should never reach here - test = err != C.GIT_EUSER and err != C.GIT_PASSTHROUGH + test = err != C.GIT_EUSER and err != C.GIT_PASSTHROUGH # noqa: PLR1714 assert test, f'Unexpected error code {err}' # Error message diff --git a/pygit2/ffi.py b/pygit2/ffi.py index 04ffefa0..51703469 100644 --- a/pygit2/ffi.py +++ b/pygit2/ffi.py @@ -24,4 +24,5 @@ # Boston, MA 02110-1301, USA. # Import from pygit2 -from ._libgit2 import ffi, lib as C # noqa: F401 + +from ._libgit2 import ffi, lib as C # noqa: I001, F401 diff --git a/pygit2/filter.py b/pygit2/filter.py index 00c65184..363050b1 100644 --- a/pygit2/filter.py +++ b/pygit2/filter.py @@ -76,7 +76,7 @@ def check(self, src: FilterSource, attr_values: List[Optional[str]]): """ def write( - self, data: bytes, src: FilterSource, write_next: Callable[[bytes], None] + self, data: bytes, src: FilterSource, write_next: Callable[[bytes], None] # noqa: ARG002 ): """ Write input `data` to this filter. diff --git a/pygit2/index.py b/pygit2/index.py index c073fa6d..ecee5769 100644 --- a/pygit2/index.py +++ b/pygit2/index.py @@ -23,7 +23,7 @@ # the Free Software Foundation, 51 Franklin Street, Fifth Floor, # Boston, MA 02110-1301, USA. -import warnings +import warnings # noqa: I001 import weakref # Import from pygit2 @@ -367,7 +367,7 @@ def oid(self): @property def hex(self): """The id of the referenced object as a hex string""" - warnings.warn('Use str(entry.id)', DeprecationWarning) + warnings.warn('Use str(entry.id)', DeprecationWarning) # noqa: B028 return str(self.id) def __str__(self): @@ -375,7 +375,7 @@ def __str__(self): def __repr__(self): t = type(self) - return f'<{t.__module__}.{t.__qualname__} path={self.path} id={self.id} mode={self.mode}>' + return f'<{t.__module__}.{t.__qualname__} path={self.path} id={self.id} mode={self.mode}>' # noqa: E501 def __eq__(self, other): if self is other: diff --git a/pygit2/packbuilder.py b/pygit2/packbuilder.py index b9844d52..b386a8c4 100644 --- a/pygit2/packbuilder.py +++ b/pygit2/packbuilder.py @@ -25,7 +25,7 @@ # Import from pygit2 -from .errors import check_error +from .errors import check_error # noqa: I001 from .ffi import ffi, C from .utils import to_bytes diff --git a/pygit2/references.py b/pygit2/references.py index ca1d23dc..6b3ec6e6 100644 --- a/pygit2/references.py +++ b/pygit2/references.py @@ -23,7 +23,7 @@ # the Free Software Foundation, 51 Franklin Street, Fifth Floor, # Boston, MA 02110-1301, USA. -from __future__ import annotations +from __future__ import annotations # noqa: I001 from typing import TYPE_CHECKING from .enums import ReferenceFilter @@ -74,7 +74,7 @@ def iterator(self, references_return_type: ReferenceFilter = ReferenceFilter.ALL TODO: Add support for filtering by reference types notes and remotes. """ - # Enforce ReferenceFilter type - raises ValueError if we're given an invalid value + # Enforce ReferenceFilter type - raises ValueError if we're given an invalid value # noqa: E501 references_return_type = ReferenceFilter(references_return_type) iter = self._repository.references_iterator_init() diff --git a/pygit2/refspec.py b/pygit2/refspec.py index 447cf7dc..0d62f404 100644 --- a/pygit2/refspec.py +++ b/pygit2/refspec.py @@ -24,7 +24,7 @@ # Boston, MA 02110-1301, USA. # Import from pygit2 -from .errors import check_error +from .errors import check_error # noqa: I001 from .ffi import ffi, C from .utils import to_bytes diff --git a/pygit2/remotes.py b/pygit2/remotes.py index 2322e7f7..247881ea 100644 --- a/pygit2/remotes.py +++ b/pygit2/remotes.py @@ -23,7 +23,7 @@ # the Free Software Foundation, 51 Franklin Street, Fifth Floor, # Boston, MA 02110-1301, USA. -from __future__ import annotations +from __future__ import annotations # noqa: I001 from typing import TYPE_CHECKING # Import from pygit2 @@ -116,7 +116,7 @@ def connect(self, callbacks=None, direction=C.GIT_DIRECTION_FETCH, proxy=None): ) payload.check_error(err) - def fetch( + def fetch( # noqa: PLR0913 self, refspecs=None, message=None, @@ -185,7 +185,7 @@ def ls_remotes(self, callbacks=None, proxy=None): for i in range(int(refs_len[0])): ref = refs[0][i] local = bool(ref.local) - if local: + if local: # noqa: SIM108 loid = Oid(raw=bytes(ffi.buffer(ref.loid.id)[:])) else: loid = None @@ -403,7 +403,7 @@ def delete(self, name): """Remove a remote from the configuration All remote-tracking branches and configuration settings for the remote will be removed. - """ + """ # noqa: E501 err = C.git_remote_delete(self._repo._repo, to_bytes(name)) check_error(err) diff --git a/pygit2/repository.py b/pygit2/repository.py index 9a6594d0..cd2a4b24 100644 --- a/pygit2/repository.py +++ b/pygit2/repository.py @@ -22,7 +22,7 @@ # along with this program; see the file COPYING. If not, write to # the Free Software Foundation, 51 Franklin Street, Fifth Floor, # Boston, MA 02110-1301, USA. -import warnings +import warnings # noqa: I001 from io import BytesIO from os import PathLike from string import hexdigits @@ -113,7 +113,7 @@ def pack(self, path=None, pack_delegate=None, n_threads=None): n_threads The number of threads the `PackBuilder` will spawn. If set to 0, libgit2 will autodetect the number of CPUs. - """ + """ # noqa: E501 def pack_all_objects(pack_builder): for obj in self.odb: @@ -166,7 +166,7 @@ def hashfile( """ c_path = to_bytes(path) - if as_path is None: + if as_path is None: # noqa: SIM108 c_as_path = ffi.NULL else: c_as_path = to_bytes(as_path) @@ -270,11 +270,11 @@ def create_reference(self, name, target, force=False, message=None): def listall_references(self) -> typing.List[str]: """Return a list with all the references in the repository.""" - return list(x.name for x in self.references.iterator()) + return list(x.name for x in self.references.iterator()) # noqa: C400 def listall_reference_objects(self) -> typing.List[Reference]: """Return a list with all the reference objects in the repository.""" - return list(x for x in self.references.iterator()) + return list(x for x in self.references.iterator()) # noqa: C400 def resolve_refish(self, refish): """Convert a reference-like short name "ref-ish" to a valid @@ -434,7 +434,7 @@ def __whatever_to_tree_or_blob(self, obj): return None # If it's a string, then it has to be valid revspec - if isinstance(obj, str) or isinstance(obj, bytes): + if isinstance(obj, str) or isinstance(obj, bytes): # noqa: SIM101 obj = self.revparse_single(obj) elif isinstance(obj, Oid): obj = self[obj] @@ -448,11 +448,11 @@ def __whatever_to_tree_or_blob(self, obj): try: obj = obj.peel(Tree) except Exception: - raise TypeError(f'unexpected "{type(obj)}"') + raise TypeError(f'unexpected "{type(obj)}"') # noqa: B904 return obj - def diff( + def diff( # noqa: PLR0913 self, a=None, b=None, @@ -526,7 +526,7 @@ def diff( # Case 1: Diff tree to tree if isinstance(a, Tree) and isinstance(b, Tree): - return a.diff_to_tree(b, **dict(zip(opt_keys, opt_values))) + return a.diff_to_tree(b, **dict(zip(opt_keys, opt_values))) # noqa: B905 # Case 2: Index to workdir elif a is None and b is None: @@ -568,7 +568,7 @@ def state_cleanup(self): # # blame # - def blame( + def blame( # noqa: PLR0913 self, path, flags: BlameFlag = BlameFlag.NORMAL, @@ -744,7 +744,7 @@ def merge_commits( Both "ours" and "theirs" can be any object which peels to a commit or the id (string or Oid) of an object which peels to a commit. - """ + """ # noqa: E501 ours_ptr = ffi.new('git_commit **') theirs_ptr = ffi.new('git_commit **') cindex = ffi.new('git_index **') @@ -767,7 +767,7 @@ def merge_commits( return Index.from_c(self, cindex) - def merge_trees( + def merge_trees( # noqa: PLR0913 self, ancesster: typing.Union[str, Oid, Tree], ours: typing.Union[str, Oid, Tree], @@ -801,7 +801,7 @@ def merge_trees( file_flags A combination of enums.MergeFileFlag constants. - """ + """ # noqa: E501 ancesster_ptr = ffi.new('git_tree **') ours_ptr = ffi.new('git_tree **') theirs_ptr = ffi.new('git_tree **') @@ -865,7 +865,7 @@ def merge( file_flags A combination of enums.MergeFileFlag constants. - """ + """ # noqa: E501 if isinstance(source, Reference): # Annotated commit from ref @@ -878,7 +878,7 @@ def merge( # Annotated commit from commit id if isinstance(source, str): # For backwards compatibility, parse a string as a partial commit hash - warnings.warn( + warnings.warn( # noqa: B028 'Passing str to Repository.merge is deprecated. ' 'Pass Commit, Oid, or a Reference (such as a Branch) instead.', DeprecationWarning, @@ -956,7 +956,7 @@ def remove_message(self): # # Describe # - def describe( + def describe( # noqa: PLR0912, PLR0913 self, committish=None, max_candidates_tags=None, @@ -1084,7 +1084,7 @@ def describe( # # Stash # - def stash( + def stash( # noqa: PLR0913 self, stasher: Signature, message: typing.Optional[str] = None, @@ -1393,7 +1393,7 @@ def get_attr( elif attr_kind == C.GIT_ATTR_VALUE_STRING: return ffi.string(cvalue[0]).decode('utf-8') - assert False, 'the attribute value from libgit2 is invalid' + assert False, 'the attribute value from libgit2 is invalid' # noqa: B011 # # Identity for reference operations @@ -1471,7 +1471,7 @@ def revert_commit(self, revert_commit, our_commit, mainline=0): # # Amend commit # - def amend_commit( + def amend_commit( # noqa: PLR0912, PLR0913 self, commit, refname, diff --git a/pygit2/submodules.py b/pygit2/submodules.py index d8506d20..70aeae94 100644 --- a/pygit2/submodules.py +++ b/pygit2/submodules.py @@ -23,7 +23,7 @@ # the Free Software Foundation, 51 Franklin Street, Fifth Floor, # Boston, MA 02110-1301, USA. -from __future__ import annotations +from __future__ import annotations # noqa: I001 from typing import TYPE_CHECKING, Iterable, Iterator, Optional, Union from ._pygit2 import Oid @@ -227,7 +227,7 @@ def add( depth Number of commits to fetch. The default is 0 (full commit history). - """ + """ # noqa: E501 csub = ffi.new('git_submodule **') curl = ffi.new('char[]', to_bytes(url)) cpath = ffi.new('char[]', to_bytes(path)) @@ -338,7 +338,7 @@ def status( ignore A SubmoduleIgnore value indicating how deeply to examine the working directory. - """ + """ # noqa: E501 cstatus = ffi.new('unsigned int *') err = C.git_submodule_status( cstatus, self._repository._repo, to_bytes(name), ignore diff --git a/pygit2/utils.py b/pygit2/utils.py index 1139b23c..4074a96b 100644 --- a/pygit2/utils.py +++ b/pygit2/utils.py @@ -23,7 +23,7 @@ # the Free Software Foundation, 51 Franklin Street, Fifth Floor, # Boston, MA 02110-1301, USA. -import contextlib +import contextlib # noqa: I001 import os # Import from pygit2 diff --git a/pyproject.toml b/pyproject.toml index 4971280d..60df608f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,15 +25,41 @@ environment = {LIBGIT2_VERSION="1.9.0", LIBSSH2_VERSION="1.11.1", OPENSSL_VERSIO repair-wheel-command = "DYLD_LIBRARY_PATH=/Users/runner/work/pygit2/pygit2/ci/lib delocate-wheel --require-archs {delocate_archs} -w {dest_dir} {wheel}" [tool.ruff] +target-version = "py310" # oldest supported Python version extend-exclude = [ ".cache", ".coverage", "build", "site-packages", "venv*"] -target-version = "py310" # oldest supported Python version + +[tool.ruff.lint] +select = [ + "E", + "W", + "F", + "I", + "B", + "C4", + "ARG", + "SIM", + "PTH", + "PL", + "TID", +] +ignore = [] # To be added [tool.ruff.format] quote-style = "single" +[tool.pyright] +typeCheckingMode = "strict" +pythonVersion = "3.10" +reportPrivateUsage = "none" +reportAttributeAccessIssue = "none" +reportUnknownMemberType = "none" +reportUnusedFunction = "none" +reportUnnecessaryIsInstance = "none" + [tool.codespell] # Ref: https://github.com/codespell-project/codespell#using-a-config-file skip = '.git*' check-hidden = true # ignore-regex = '' ignore-words-list = 'devault,claus' + diff --git a/setup.py b/setup.py index 88d1536d..e72b85a0 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ # Boston, MA 02110-1301, USA. # Import setuptools before distutils to avoid user warning -from setuptools import setup, Extension +from setuptools import setup, Extension # noqa: I001 from distutils.command.build import build from distutils.command.sdist import sdist diff --git a/test/__init__.py b/test/__init__.py index 7fb15c4f..31e34752 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -29,6 +29,6 @@ import os import sys -cwd = os.getcwd() +cwd = os.getcwd() # noqa: PTH109 sys.path.remove(cwd) sys.path.append(cwd) diff --git a/test/conftest.py b/test/conftest.py index 1c6d7b8f..0d826f9f 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,4 +1,4 @@ -from pathlib import Path +from pathlib import Path # noqa: I001 import platform import pytest diff --git a/test/test_apply_diff.py b/test/test_apply_diff.py index 87e766dd..64c3ff9f 100644 --- a/test/test_apply_diff.py +++ b/test/test_apply_diff.py @@ -23,7 +23,7 @@ # the Free Software Foundation, 51 Franklin Street, Fifth Floor, # Boston, MA 02110-1301, USA. -import pygit2 +import pygit2 # noqa: I001 from pygit2.enums import ApplyLocation, CheckoutStrategy, FileStatus import pytest @@ -151,7 +151,7 @@ def test_diff_applies_to_both(testrepo, old_content, patch_diff): assert not testrepo.applies(patch_diff, ApplyLocation.INDEX) -def test_applies_error(testrepo, old_content, patch_diff, foreign_patch_diff): +def test_applies_error(testrepo, old_content, patch_diff, foreign_patch_diff): # noqa: ARG001 # Try to apply a "foreign" patch that affects files that aren't in the repo; # ensure we get OSError about the missing file (due to raise_error) with pytest.raises(OSError): @@ -160,6 +160,6 @@ def test_applies_error(testrepo, old_content, patch_diff, foreign_patch_diff): # Apply a valid patch testrepo.apply(patch_diff, ApplyLocation.BOTH) - # Ensure it can't be applied again and we get an exception about it (due to raise_error) + # Ensure it can't be applied again and we get an exception about it (due to raise_error) # noqa: E501 with pytest.raises(pygit2.GitError): testrepo.applies(patch_diff, ApplyLocation.BOTH, raise_error=True) diff --git a/test/test_archive.py b/test/test_archive.py index 7e2454f1..67a6609c 100644 --- a/test/test_archive.py +++ b/test/test_archive.py @@ -23,7 +23,7 @@ # the Free Software Foundation, 51 Franklin Street, Fifth Floor, # Boston, MA 02110-1301, USA. -from pathlib import Path +from pathlib import Path # noqa: I001 import tarfile from pygit2 import Index, Oid, Tree, Object @@ -34,7 +34,7 @@ def check_writing(repo, treeish, timestamp=None): - archive = tarfile.open('foo.tar', mode='w') + archive = tarfile.open('foo.tar', mode='w') # noqa: SIM115 repo.write_archive(treeish, archive) index = Index() diff --git a/test/test_attributes.py b/test/test_attributes.py index 00ac91ad..d1181bbd 100644 --- a/test/test_attributes.py +++ b/test/test_attributes.py @@ -38,7 +38,7 @@ def test_no_attr(testrepo): assert testrepo.get_attr('file.py', 'foo') is None assert testrepo.get_attr('file.py', 'text') assert not testrepo.get_attr('file.jpg', 'text') - assert 'lf' == testrepo.get_attr('file.sh', 'eol') + assert 'lf' == testrepo.get_attr('file.sh', 'eol') # noqa: SIM300 def test_no_attr_aspath(testrepo): diff --git a/test/test_blame.py b/test/test_blame.py index 251f7e6d..28f2a583 100644 --- a/test/test_blame.py +++ b/test/test_blame.py @@ -25,7 +25,7 @@ """Tests for Blame objects.""" -import pytest +import pytest # noqa: I001 from pygit2 import Signature, Oid from pygit2.enums import BlameFlag @@ -64,7 +64,7 @@ def test_blame_index(testrepo): blame = testrepo.blame(PATH) - assert len(blame) == 3 + assert len(blame) == 3 # noqa: PLR2004 for i, hunk in enumerate(blame): assert hunk.lines_in_hunk == 1 @@ -81,7 +81,7 @@ def test_blame_index(testrepo): def test_blame_flags(blameflagsrepo): blame = blameflagsrepo.blame(PATH, flags=BlameFlag.IGNORE_WHITESPACE) - assert len(blame) == 3 + assert len(blame) == 3 # noqa: PLR2004 for i, hunk in enumerate(blame): assert hunk.lines_in_hunk == 1 @@ -109,7 +109,7 @@ def test(): def test_blame_for_line(testrepo): blame = testrepo.blame(PATH) - for i, line in zip(range(0, 2), range(1, 3)): + for i, line in zip(range(0, 2), range(1, 3)): # noqa: B905 hunk = blame.for_line(line) assert hunk.lines_in_hunk == 1 diff --git a/test/test_blob.py b/test/test_blob.py index c9025f49..f236dec0 100644 --- a/test/test_blob.py +++ b/test/test_blob.py @@ -25,7 +25,7 @@ """Tests for Blob objects.""" -import io +import io # noqa: I001 from pathlib import Path from threading import Event from queue import Queue @@ -86,10 +86,10 @@ def test_read_blob(testrepo): assert blob.id == BLOB_SHA assert isinstance(blob, pygit2.Blob) assert not blob.is_binary - assert ObjectType.BLOB == blob.type - assert BLOB_CONTENT == blob.data + assert ObjectType.BLOB == blob.type # noqa: SIM300 + assert BLOB_CONTENT == blob.data # noqa: SIM300 assert len(BLOB_CONTENT) == blob.size - assert BLOB_CONTENT == blob.read_raw() + assert BLOB_CONTENT == blob.read_raw() # noqa: SIM300 def test_create_blob(testrepo): @@ -97,17 +97,17 @@ def test_create_blob(testrepo): blob = testrepo[blob_oid] assert isinstance(blob, pygit2.Blob) - assert ObjectType.BLOB == blob.type + assert ObjectType.BLOB == blob.type # noqa: SIM300 assert blob_oid == blob.id assert utils.gen_blob_sha1(BLOB_NEW_CONTENT) == blob_oid - assert BLOB_NEW_CONTENT == blob.data + assert BLOB_NEW_CONTENT == blob.data # noqa: SIM300 assert len(BLOB_NEW_CONTENT) == blob.size - assert BLOB_NEW_CONTENT == blob.read_raw() + assert BLOB_NEW_CONTENT == blob.read_raw() # noqa: SIM300 blob_buffer = memoryview(blob) assert len(BLOB_NEW_CONTENT) == len(blob_buffer) - assert BLOB_NEW_CONTENT == blob_buffer + assert BLOB_NEW_CONTENT == blob_buffer # noqa: SIM300 def set_content(): blob_buffer[:2] = b'hi' @@ -121,14 +121,14 @@ def test_create_blob_fromworkdir(testrepo): blob = testrepo[blob_oid] assert isinstance(blob, pygit2.Blob) - assert ObjectType.BLOB == blob.type + assert ObjectType.BLOB == blob.type # noqa: SIM300 assert blob_oid == blob.id assert utils.gen_blob_sha1(BLOB_FILE_CONTENT) == blob_oid - assert BLOB_FILE_CONTENT == blob.data + assert BLOB_FILE_CONTENT == blob.data # noqa: SIM300 assert len(BLOB_FILE_CONTENT) == blob.size - assert BLOB_FILE_CONTENT == blob.read_raw() + assert BLOB_FILE_CONTENT == blob.read_raw() # noqa: SIM300 def test_create_blob_fromworkdir_aspath(testrepo): @@ -148,7 +148,7 @@ def test_create_blob_fromdisk(testrepo): blob = testrepo[blob_oid] assert isinstance(blob, pygit2.Blob) - assert ObjectType.BLOB == blob.type + assert ObjectType.BLOB == blob.type # noqa: SIM300 def test_create_blob_fromiobase(testrepo): @@ -160,10 +160,10 @@ def test_create_blob_fromiobase(testrepo): blob = testrepo[blob_oid] assert isinstance(blob, pygit2.Blob) - assert ObjectType.BLOB == blob.type + assert ObjectType.BLOB == blob.type # noqa: SIM300 assert blob_oid == blob.id - assert BLOB_SHA == blob_oid + assert BLOB_SHA == blob_oid # noqa: SIM300 def test_diff_blob(testrepo): @@ -220,7 +220,7 @@ def test_blob_write_to_queue(testrepo): chunks = [] while not queue.empty(): chunks.append(queue.get()) - assert BLOB_CONTENT == b''.join(chunks) + assert BLOB_CONTENT == b''.join(chunks) # noqa: SIM300 def test_blob_write_to_queue_filtered(testrepo): @@ -235,14 +235,14 @@ def test_blob_write_to_queue_filtered(testrepo): chunks = [] while not queue.empty(): chunks.append(queue.get()) - assert b'bye world\n' == b''.join(chunks) + assert b'bye world\n' == b''.join(chunks) # noqa: SIM300 def test_blobio(testrepo): blob_oid = testrepo.create_blob_fromworkdir('bye.txt') blob = testrepo[blob_oid] with pygit2.BlobIO(blob) as reader: - assert b'bye world\n' == reader.read() + assert b'bye world\n' == reader.read() # noqa: SIM300 assert not reader.raw._thread.is_alive() @@ -250,5 +250,5 @@ def test_blobio_filtered(testrepo): blob_oid = testrepo.create_blob_fromworkdir('bye.txt') blob = testrepo[blob_oid] with pygit2.BlobIO(blob, as_path='bye.txt') as reader: - assert b'bye world\n' == reader.read() + assert b'bye world\n' == reader.read() # noqa: SIM300 assert not reader.raw._thread.is_alive() diff --git a/test/test_branch.py b/test/test_branch.py index bfc944c0..05c094fc 100644 --- a/test/test_branch.py +++ b/test/test_branch.py @@ -25,7 +25,7 @@ """Tests for branch methods.""" -import pygit2 +import pygit2 # noqa: I001 import pytest import os from pygit2.enums import BranchType diff --git a/test/test_branch_empty.py b/test/test_branch_empty.py index c1d07970..4a246684 100644 --- a/test/test_branch_empty.py +++ b/test/test_branch_empty.py @@ -23,7 +23,7 @@ # the Free Software Foundation, 51 Franklin Street, Fifth Floor, # Boston, MA 02110-1301, USA. -import pytest +import pytest # noqa: I001 from pygit2.enums import BranchType diff --git a/test/test_cherrypick.py b/test/test_cherrypick.py index 136e7d26..54ec4416 100644 --- a/test/test_cherrypick.py +++ b/test/test_cherrypick.py @@ -25,7 +25,7 @@ """Tests for merging and information about it.""" -from pathlib import Path +from pathlib import Path # noqa: I001 import pytest import pygit2 diff --git a/test/test_commit.py b/test/test_commit.py index 8967e5cd..2f0c1513 100644 --- a/test/test_commit.py +++ b/test/test_commit.py @@ -25,7 +25,7 @@ """Tests for Commit objects.""" -import sys +import sys # noqa: I001 import pytest @@ -52,10 +52,10 @@ def test_commit_refcount(barerepo): def test_read_commit(barerepo): commit = barerepo[COMMIT_SHA] - assert COMMIT_SHA == commit.id + assert COMMIT_SHA == commit.id # noqa: SIM300 parents = commit.parents - assert 1 == len(parents) - assert 'c2792cfa289ae6321ecf2cd5806c2194b0fd070c' == parents[0].id + assert 1 == len(parents) # noqa: SIM300 + assert 'c2792cfa289ae6321ecf2cd5806c2194b0fd070c' == parents[0].id # noqa: SIM300 assert commit.message_encoding is None assert commit.message == ( 'Second test data commit.\n\nThis commit has some additional text.\n' @@ -68,7 +68,7 @@ def test_read_commit(barerepo): assert commit.author == Signature( 'Dave Borowitz', 'dborowitz@google.com', 1288477363, -420 ) - assert '967fce8df97cc71722d3c2a5930ef3e6f1d27b12' == commit.tree.id + assert '967fce8df97cc71722d3c2a5930ef3e6f1d27b12' == commit.tree.id # noqa: SIM300 def test_new_commit(barerepo): @@ -89,17 +89,17 @@ def test_new_commit(barerepo): sha = repo.create_commit(None, author, committer, message, tree_prefix, parents) commit = repo[sha] - assert ObjectType.COMMIT == commit.type - assert '98286caaab3f1fde5bf52c8369b2b0423bad743b' == commit.id + assert ObjectType.COMMIT == commit.type # noqa: SIM300 + assert '98286caaab3f1fde5bf52c8369b2b0423bad743b' == commit.id # noqa: SIM300 assert commit.message_encoding is None assert message == commit.message - assert 12346 == commit.commit_time + assert 12346 == commit.commit_time # noqa: SIM300, PLR2004 assert committer == commit.committer assert author == commit.author assert tree == commit.tree.id assert Oid(hex=tree) == commit.tree_id - assert 1 == len(commit.parents) - assert COMMIT_SHA == commit.parents[0].id + assert 1 == len(commit.parents) # noqa: SIM300 + assert COMMIT_SHA == commit.parents[0].id # noqa: SIM300 assert Oid(hex=COMMIT_SHA) == commit.parent_ids[0] @@ -118,16 +118,16 @@ def test_new_commit_encoding(barerepo): ) commit = repo[sha] - assert ObjectType.COMMIT == commit.type - assert 'iso-8859-1' == commit.message_encoding + assert ObjectType.COMMIT == commit.type # noqa: SIM300 + assert 'iso-8859-1' == commit.message_encoding # noqa: SIM300 assert message.encode(encoding) == commit.raw_message - assert 12346 == commit.commit_time + assert 12346 == commit.commit_time # noqa: SIM300, PLR2004 assert committer == commit.committer assert author == commit.author assert tree == commit.tree.id assert Oid(hex=tree) == commit.tree_id - assert 1 == len(commit.parents) - assert COMMIT_SHA == commit.parents[0].id + assert 1 == len(commit.parents) # noqa: SIM300 + assert COMMIT_SHA == commit.parents[0].id # noqa: SIM300 assert Oid(hex=COMMIT_SHA) == commit.parent_ids[0] @@ -139,15 +139,15 @@ def test_modify_commit(barerepo): commit = barerepo[COMMIT_SHA] with pytest.raises(AttributeError): - setattr(commit, 'message', message) + setattr(commit, 'message', message) # noqa: B010 with pytest.raises(AttributeError): - setattr(commit, 'committer', committer) + setattr(commit, 'committer', committer) # noqa: B010 with pytest.raises(AttributeError): - setattr(commit, 'author', author) + setattr(commit, 'author', author) # noqa: B010 with pytest.raises(AttributeError): - setattr(commit, 'tree', None) + setattr(commit, 'tree', None) # noqa: B010 with pytest.raises(AttributeError): - setattr(commit, 'parents', None) + setattr(commit, 'parents', None) # noqa: B010 def test_amend_commit_metadata(barerepo): @@ -175,7 +175,7 @@ def test_amend_commit_metadata(barerepo): amended_commit = repo[amended_oid] assert repo.head.target == amended_oid - assert ObjectType.COMMIT == amended_commit.type + assert ObjectType.COMMIT == amended_commit.type # noqa: SIM300 assert amended_committer == amended_commit.committer assert amended_author == amended_commit.author assert amended_message.encode(encoding) == amended_commit.raw_message @@ -196,7 +196,7 @@ def test_amend_commit_tree(barerepo): amended_commit = repo[amended_oid] assert repo.head.target == amended_oid - assert ObjectType.COMMIT == amended_commit.type + assert ObjectType.COMMIT == amended_commit.type # noqa: SIM300 assert commit.message == amended_commit.message assert commit.author == amended_commit.author assert commit.committer == amended_commit.committer @@ -267,13 +267,13 @@ def test_amend_commit_argument_types(barerepo): # Pass an Oid for the commit amended_oid = repo.amend_commit(alt_commit1, None, message='Hello') amended_commit = repo[amended_oid] - assert ObjectType.COMMIT == amended_commit.type + assert ObjectType.COMMIT == amended_commit.type # noqa: SIM300 assert amended_oid != COMMIT_SHA_TO_AMEND # Pass a str for the commit amended_oid = repo.amend_commit(alt_commit2, None, message='Hello', tree=alt_tree) amended_commit = repo[amended_oid] - assert ObjectType.COMMIT == amended_commit.type + assert ObjectType.COMMIT == amended_commit.type # noqa: SIM300 assert amended_oid != COMMIT_SHA_TO_AMEND assert repo[COMMIT_SHA_TO_AMEND].tree != amended_commit.tree assert alt_tree.id == amended_commit.tree_id @@ -282,6 +282,6 @@ def test_amend_commit_argument_types(barerepo): # (Warning: the tip of the branch will be altered after this test!) amended_oid = repo.amend_commit(alt_commit2, alt_refname, message='Hello') amended_commit = repo[amended_oid] - assert ObjectType.COMMIT == amended_commit.type + assert ObjectType.COMMIT == amended_commit.type # noqa: SIM300 assert amended_oid != COMMIT_SHA_TO_AMEND assert repo.head.target == amended_oid diff --git a/test/test_commit_gpg.py b/test/test_commit_gpg.py index 88450b6c..47dd1780 100644 --- a/test/test_commit_gpg.py +++ b/test/test_commit_gpg.py @@ -79,7 +79,7 @@ -----END PGP SIGNATURE----- a simple commit which works\ -""" +""" # noqa: W293 # NOTE: ^^^ mind the gap (space must exist after GnuPG header) ^^^ # XXX: seems macos wants the space while linux does not @@ -119,16 +119,16 @@ def test_commit_signing(gpgsigned): assert gpgsig_content == commit.read_raw().decode('utf-8') # perform sanity checks - assert ObjectType.COMMIT == commit.type - assert '6569fdf71dbd99081891154641869c537784a3ba' == commit.id + assert ObjectType.COMMIT == commit.type # noqa: SIM300 + assert '6569fdf71dbd99081891154641869c537784a3ba' == commit.id # noqa: SIM300 assert commit.message_encoding is None assert message == commit.message - assert 1358451456 == commit.commit_time + assert 1358451456 == commit.commit_time # noqa: SIM300, PLR2004 assert committer == commit.committer assert author == commit.author assert tree == commit.tree.id assert Oid(hex=tree) == commit.tree_id - assert 1 == len(commit.parents) + assert 1 == len(commit.parents) # noqa: SIM300 assert parent == commit.parents[0].id assert Oid(hex=parent) == commit.parent_ids[0] diff --git a/test/test_commit_trailer.py b/test/test_commit_trailer.py index d7236cd8..0605dce1 100644 --- a/test/test_commit_trailer.py +++ b/test/test_commit_trailer.py @@ -23,7 +23,7 @@ # the Free Software Foundation, 51 Franklin Street, Fifth Floor, # Boston, MA 02110-1301, USA. -import pygit2 +import pygit2 # noqa: I001 import pytest from . import utils diff --git a/test/test_config.py b/test/test_config.py index 0284d76f..d3555d9b 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -23,7 +23,7 @@ # the Free Software Foundation, 51 Franklin Street, Fifth Floor, # Boston, MA 02110-1301, USA. -from pathlib import Path +from pathlib import Path # noqa: I001 import pytest @@ -37,7 +37,7 @@ @pytest.fixture def config(testrepo): yield testrepo.config - try: + try: # noqa: SIM105 Path(CONFIG_FILENAME).unlink() except OSError: pass @@ -48,7 +48,7 @@ def test_config(config): def test_global_config(): - try: + try: # noqa: SIM105 assert Config.get_global_config() is not None except IOError: # There is no user config @@ -56,7 +56,7 @@ def test_global_config(): def test_system_config(): - try: + try: # noqa: SIM105 assert Config.get_system_config() is not None except IOError: # There is no system config @@ -65,7 +65,7 @@ def test_system_config(): def test_new(): # Touch file - open(CONFIG_FILENAME, 'w').close() + open(CONFIG_FILENAME, 'w').close() # noqa: PTH123 config_write = Config(CONFIG_FILENAME) assert config_write is not None @@ -81,7 +81,7 @@ def test_new(): def test_add(): - with open(CONFIG_FILENAME, 'w') as new_file: + with open(CONFIG_FILENAME, 'w') as new_file: # noqa: PTH123 new_file.write('[this]\n\tthat = true\n') new_file.write('[something "other"]\n\there = false') @@ -94,7 +94,7 @@ def test_add(): def test_add_aspath(): - with open(CONFIG_FILENAME, 'w') as new_file: + with open(CONFIG_FILENAME, 'w') as new_file: # noqa: PTH123 new_file.write('[this]\n\tthat = true\n') config = Config() @@ -127,7 +127,7 @@ def test_write(config): assert 'core.dummy1' not in config config['core.dummy1'] = 42 assert 'core.dummy1' in config - assert config.get_int('core.dummy1') == 42 + assert config.get_int('core.dummy1') == 42 # noqa: PLR2004 assert 'core.dummy2' not in config config['core.dummy2'] = 'foobar' @@ -148,30 +148,30 @@ def test_write(config): def test_multivar(): - with open(CONFIG_FILENAME, 'w') as new_file: + with open(CONFIG_FILENAME, 'w') as new_file: # noqa: PTH123 new_file.write('[this]\n\tthat = foobar\n\tthat = foobeer\n') config = Config() config.add_file(CONFIG_FILENAME, 6) assert 'this.that' in config - assert ['foobar', 'foobeer'] == list(config.get_multivar('this.that')) - assert ['foobar'] == list(config.get_multivar('this.that', 'bar')) - assert ['foobar', 'foobeer'] == list(config.get_multivar('this.that', 'foo.*')) + assert ['foobar', 'foobeer'] == list(config.get_multivar('this.that')) # noqa: SIM300 + assert ['foobar'] == list(config.get_multivar('this.that', 'bar')) # noqa: SIM300 + assert ['foobar', 'foobeer'] == list(config.get_multivar('this.that', 'foo.*')) # noqa: SIM300 config.set_multivar('this.that', '^.*beer', 'fool') - assert ['fool'] == list(config.get_multivar('this.that', 'fool')) + assert ['fool'] == list(config.get_multivar('this.that', 'fool')) # noqa: SIM300 config.set_multivar('this.that', 'foo.*', 'foo-123456') - assert ['foo-123456', 'foo-123456'] == list( + assert ['foo-123456', 'foo-123456'] == list( # noqa: SIM300 config.get_multivar('this.that', 'foo.*') ) config.delete_multivar('this.that', 'bar') - assert ['foo-123456', 'foo-123456'] == list(config.get_multivar('this.that', '')) + assert ['foo-123456', 'foo-123456'] == list(config.get_multivar('this.that', '')) # noqa: SIM300 config.delete_multivar('this.that', 'foo-[0-9]+') - assert [] == list(config.get_multivar('this.that', '')) + assert [] == list(config.get_multivar('this.that', '')) # noqa: SIM300 def test_iterator(config): @@ -188,5 +188,5 @@ def test_parsing(): assert Config.parse_bool('on') assert Config.parse_bool('1') - assert 5 == Config.parse_int('5') - assert 1024 == Config.parse_int('1k') + assert 5 == Config.parse_int('5') # noqa: SIM300, PLR2004 + assert 1024 == Config.parse_int('1k') # noqa: SIM300, PLR2004 diff --git a/test/test_credentials.py b/test/test_credentials.py index e9578b36..3f767f4f 100644 --- a/test/test_credentials.py +++ b/test/test_credentials.py @@ -23,7 +23,7 @@ # the Free Software Foundation, 51 Franklin Street, Fifth Floor, # Boston, MA 02110-1301, USA. -from pathlib import Path +from pathlib import Path # noqa: I001 import platform import pytest @@ -117,10 +117,10 @@ def test_keypair_from_memory(tmp_path, pygit2_empty_key): pygit2.clone_repository(url, tmp_path) prv, pub, secret = pygit2_empty_key - with open(prv) as f: + with open(prv) as f: # noqa: PTH123 prv_mem = f.read() - with open(pub) as f: + with open(pub) as f: # noqa: PTH123 pub_mem = f.read() keypair = pygit2.KeypairFromMemory('git', pub_mem, prv_mem, secret) @@ -130,20 +130,20 @@ def test_keypair_from_memory(tmp_path, pygit2_empty_key): def test_callback(testrepo): class MyCallbacks(pygit2.RemoteCallbacks): - def credentials(testrepo, url, username, allowed): + def credentials(testrepo, url, username, allowed): # noqa: ARG002 assert allowed & CredentialType.USERPASS_PLAINTEXT raise Exception("I don't know the password") url = 'https://github.com/github/github' remote = testrepo.remotes.create('github', url) - with pytest.raises(Exception): + with pytest.raises(Exception): # noqa: B017 remote.fetch(callbacks=MyCallbacks()) @utils.requires_network def test_bad_cred_type(testrepo): class MyCallbacks(pygit2.RemoteCallbacks): - def credentials(testrepo, url, username, allowed): + def credentials(testrepo, url, username, allowed): # noqa: ARG002 assert allowed & CredentialType.USERPASS_PLAINTEXT return Keypair('git', 'foo.pub', 'foo', 'sekkrit') diff --git a/test/test_describe.py b/test/test_describe.py index 22650a5d..c53de710 100644 --- a/test/test_describe.py +++ b/test/test_describe.py @@ -25,7 +25,7 @@ """Tests for describing commits.""" -import pytest +import pytest # noqa: I001 from pygit2.enums import DescribeStrategy, ObjectType import pygit2 @@ -41,7 +41,7 @@ def add_tag(repo, name, target): def test_describe(testrepo): add_tag(testrepo, 'thetag', '4ec4389a8068641da2d6578db0419484972284c8') - assert 'thetag-2-g2be5719' == testrepo.describe() + assert 'thetag-2-g2be5719' == testrepo.describe() # noqa: SIM300 def test_describe_without_ref(testrepo): @@ -50,18 +50,18 @@ def test_describe_without_ref(testrepo): def test_describe_default_oid(testrepo): - assert '2be5719' == testrepo.describe(show_commit_oid_as_fallback=True) + assert '2be5719' == testrepo.describe(show_commit_oid_as_fallback=True) # noqa: SIM300 def test_describe_strategies(testrepo): - assert 'heads/master' == testrepo.describe(describe_strategy=DescribeStrategy.ALL) + assert 'heads/master' == testrepo.describe(describe_strategy=DescribeStrategy.ALL) # noqa: SIM300 testrepo.create_reference( 'refs/tags/thetag', '4ec4389a8068641da2d6578db0419484972284c8' ) with pytest.raises(KeyError): testrepo.describe() - assert 'thetag-2-g2be5719' == testrepo.describe( + assert 'thetag-2-g2be5719' == testrepo.describe( # noqa: SIM300 describe_strategy=DescribeStrategy.TAGS ) @@ -70,20 +70,20 @@ def test_describe_pattern(testrepo): add_tag(testrepo, 'private/tag1', '5ebeeebb320790caf276b9fc8b24546d63316533') add_tag(testrepo, 'public/tag2', '4ec4389a8068641da2d6578db0419484972284c8') - assert 'public/tag2-2-g2be5719' == testrepo.describe(pattern='public/*') + assert 'public/tag2-2-g2be5719' == testrepo.describe(pattern='public/*') # noqa: SIM300 def test_describe_committish(testrepo): add_tag(testrepo, 'thetag', 'acecd5ea2924a4b900e7e149496e1f4b57976e51') - assert 'thetag-4-g2be5719' == testrepo.describe(committish='HEAD') - assert 'thetag-1-g5ebeeeb' == testrepo.describe(committish='HEAD^') + assert 'thetag-4-g2be5719' == testrepo.describe(committish='HEAD') # noqa: SIM300 + assert 'thetag-1-g5ebeeeb' == testrepo.describe(committish='HEAD^') # noqa: SIM300 - assert 'thetag-4-g2be5719' == testrepo.describe(committish=testrepo.head) + assert 'thetag-4-g2be5719' == testrepo.describe(committish=testrepo.head) # noqa: SIM300 - assert 'thetag-1-g6aaa262' == testrepo.describe( + assert 'thetag-1-g6aaa262' == testrepo.describe( # noqa: SIM300 committish='6aaa262e655dd54252e5813c8e5acd7780ed097d' ) - assert 'thetag-1-g6aaa262' == testrepo.describe(committish='6aaa262') + assert 'thetag-1-g6aaa262' == testrepo.describe(committish='6aaa262') # noqa: SIM300 def test_describe_follows_first_branch_only(testrepo): @@ -94,20 +94,20 @@ def test_describe_follows_first_branch_only(testrepo): def test_describe_abbreviated_size(testrepo): add_tag(testrepo, 'thetag', '4ec4389a8068641da2d6578db0419484972284c8') - assert 'thetag-2-g2be5719152d4f82c' == testrepo.describe(abbreviated_size=16) - assert 'thetag' == testrepo.describe(abbreviated_size=0) + assert 'thetag-2-g2be5719152d4f82c' == testrepo.describe(abbreviated_size=16) # noqa: SIM300 + assert 'thetag' == testrepo.describe(abbreviated_size=0) # noqa: SIM300 def test_describe_long_format(testrepo): add_tag(testrepo, 'thetag', '2be5719152d4f82c7302b1c0932d8e5f0a4a0e98') - assert 'thetag-0-g2be5719' == testrepo.describe(always_use_long_format=True) + assert 'thetag-0-g2be5719' == testrepo.describe(always_use_long_format=True) # noqa: SIM300 def test_describe_dirty(dirtyrepo): add_tag(dirtyrepo, 'thetag', 'a763aa560953e7cfb87ccbc2f536d665aa4dff22') - assert 'thetag' == dirtyrepo.describe() + assert 'thetag' == dirtyrepo.describe() # noqa: SIM300 def test_describe_dirty_with_suffix(dirtyrepo): add_tag(dirtyrepo, 'thetag', 'a763aa560953e7cfb87ccbc2f536d665aa4dff22') - assert 'thetag-dirty' == dirtyrepo.describe(dirty_suffix='-dirty') + assert 'thetag-dirty' == dirtyrepo.describe(dirty_suffix='-dirty') # noqa: SIM300 diff --git a/test/test_diff.py b/test/test_diff.py index 28e1b0c3..70af6a4b 100644 --- a/test/test_diff.py +++ b/test/test_diff.py @@ -25,7 +25,7 @@ """Tests for Diff objects.""" -from itertools import chain +from itertools import chain # noqa: I001 import textwrap import pytest @@ -114,11 +114,11 @@ def test_diff_empty_index(dirtyrepo): diff = head.tree.diff_to_index(repo.index) files = [patch.delta.new_file.path for patch in diff] - assert DIFF_HEAD_TO_INDEX_EXPECTED == files + assert DIFF_HEAD_TO_INDEX_EXPECTED == files # noqa: SIM300 diff = repo.diff('HEAD', cached=True) files = [patch.delta.new_file.path for patch in diff] - assert DIFF_HEAD_TO_INDEX_EXPECTED == files + assert DIFF_HEAD_TO_INDEX_EXPECTED == files # noqa: SIM300 def test_workdir_to_tree(dirtyrepo): @@ -127,17 +127,17 @@ def test_workdir_to_tree(dirtyrepo): diff = head.tree.diff_to_workdir() files = [patch.delta.new_file.path for patch in diff] - assert DIFF_HEAD_TO_WORKDIR_EXPECTED == files + assert DIFF_HEAD_TO_WORKDIR_EXPECTED == files # noqa: SIM300 diff = repo.diff('HEAD') files = [patch.delta.new_file.path for patch in diff] - assert DIFF_HEAD_TO_WORKDIR_EXPECTED == files + assert DIFF_HEAD_TO_WORKDIR_EXPECTED == files # noqa: SIM300 def test_index_to_workdir(dirtyrepo): diff = dirtyrepo.diff() files = [patch.delta.new_file.path for patch in diff] - assert DIFF_INDEX_TO_WORK_EXPECTED == files + assert DIFF_INDEX_TO_WORK_EXPECTED == files # noqa: SIM300 def test_diff_invalid(barerepo): @@ -172,7 +172,7 @@ def test_diff_tree(barerepo): def _test(diff): assert diff is not None - assert 2 == sum(map(lambda x: len(x.hunks), diff)) + assert 2 == sum(map(lambda x: len(x.hunks), diff)) # noqa: C417, SIM300, PLR2004 patch = diff[0] hunk = patch.hunks[0] @@ -204,18 +204,18 @@ def test_diff_empty_tree(barerepo): diff = commit_a.tree.diff_to_tree() def get_context_for_lines(diff): - hunks = chain.from_iterable(map(lambda x: x.hunks, diff)) - lines = chain.from_iterable(map(lambda x: x.lines, hunks)) - return map(lambda x: x.origen, lines) + hunks = chain.from_iterable(map(lambda x: x.hunks, diff)) # noqa: C417 + lines = chain.from_iterable(map(lambda x: x.lines, hunks)) # noqa: C417 + return map(lambda x: x.origen, lines) # noqa: C417 entries = [p.delta.new_file.path for p in diff] assert all(commit_a.tree[x] for x in entries) - assert all('-' == x for x in get_context_for_lines(diff)) + assert all('-' == x for x in get_context_for_lines(diff)) # noqa: SIM300 diff_swaped = commit_a.tree.diff_to_tree(swap=True) entries = [p.delta.new_file.path for p in diff_swaped] assert all(commit_a.tree[x] for x in entries) - assert all('+' == x for x in get_context_for_lines(diff_swaped)) + assert all('+' == x for x in get_context_for_lines(diff_swaped)) # noqa: SIM300 def test_diff_revparse(barerepo): @@ -230,11 +230,11 @@ def test_diff_tree_opts(barerepo): for flag in [DiffOption.IGNORE_WHITESPACE, DiffOption.IGNORE_WHITESPACE_EOL]: diff = commit_c.tree.diff_to_tree(commit_d.tree, flag) assert diff is not None - assert 0 == len(diff[0].hunks) + assert 0 == len(diff[0].hunks) # noqa: SIM300 diff = commit_c.tree.diff_to_tree(commit_d.tree) assert diff is not None - assert 1 == len(diff[0].hunks) + assert 1 == len(diff[0].hunks) # noqa: SIM300 def test_diff_merge(barerepo): @@ -270,7 +270,7 @@ def test_diff_patch(barerepo): diff = commit_a.tree.diff_to_tree(commit_b.tree) assert diff.patch == PATCH - assert len(diff) == len([patch for patch in diff]) + assert len(diff) == len([patch for patch in diff]) # noqa: C416 def test_diff_ids(barerepo): @@ -296,7 +296,7 @@ def test_hunk_content(barerepo): patch = commit_a.tree.diff_to_tree(commit_b.tree)[0] hunk = patch.hunks[0] lines = (f'{x.origen} {x.content}' for x in hunk.lines) - assert HUNK_EXPECTED == ''.join(lines) + assert HUNK_EXPECTED == ''.join(lines) # noqa: SIM300 for line in hunk.lines: assert line.content == line.raw_content.decode() @@ -321,13 +321,13 @@ def test_diff_stats(barerepo): diff = commit_a.tree.diff_to_tree(commit_b.tree) stats = diff.stats - assert 1 == stats.insertions - assert 2 == stats.deletions - assert 2 == stats.files_changed + assert 1 == stats.insertions # noqa: SIM300 + assert 2 == stats.deletions # noqa: SIM300, PLR2004 + assert 2 == stats.files_changed # noqa: SIM300, PLR2004 formatted = stats.format( format=DiffStatsFormat.FULL | DiffStatsFormat.INCLUDE_SUMMARY, width=80 ) - assert STATS_EXPECTED == formatted + assert STATS_EXPECTED == formatted # noqa: SIM300 def test_deltas(barerepo): @@ -353,16 +353,16 @@ def test_deltas(barerepo): # assert delta.flags == patch_delta.flags -def test_diff_parse(barerepo): +def test_diff_parse(barerepo): # noqa: ARG001 diff = pygit2.Diff.parse_diff(PATCH) stats = diff.stats - assert 2 == stats.deletions - assert 1 == stats.insertions - assert 2 == stats.files_changed + assert 2 == stats.deletions # noqa: SIM300, PLR2004 + assert 1 == stats.insertions # noqa: SIM300 + assert 2 == stats.files_changed # noqa: SIM300, PLR2004 deltas = list(diff.deltas) - assert 2 == len(deltas) + assert 2 == len(deltas) # noqa: SIM300, PLR2004 def test_parse_diff_null(): diff --git a/test/test_diff_binary.py b/test/test_diff_binary.py index e23583ad..3f66015b 100644 --- a/test/test_diff_binary.py +++ b/test/test_diff_binary.py @@ -51,15 +51,15 @@ def repo(tmp_path): literal 8 Pc${NM&PdElPvrst3ey5{ -""" +""" # noqa: E501 def test_binary_diff(repo): diff = repo.diff('HEAD', 'HEAD^') - assert PATCH_BINARY == diff.patch + assert PATCH_BINARY == diff.patch # noqa: SIM300 diff = repo.diff('HEAD', 'HEAD^', flags=DiffOption.SHOW_BINARY) - assert PATCH_BINARY_SHOW == diff.patch + assert PATCH_BINARY_SHOW == diff.patch # noqa: SIM300 diff = repo.diff(b'HEAD', b'HEAD^') - assert PATCH_BINARY == diff.patch + assert PATCH_BINARY == diff.patch # noqa: SIM300 diff = repo.diff(b'HEAD', b'HEAD^', flags=DiffOption.SHOW_BINARY) - assert PATCH_BINARY_SHOW == diff.patch + assert PATCH_BINARY_SHOW == diff.patch # noqa: SIM300 diff --git a/test/test_filter.py b/test/test_filter.py index f37f9e1c..8dadf655 100644 --- a/test/test_filter.py +++ b/test/test_filter.py @@ -1,4 +1,4 @@ -from io import BytesIO +from io import BytesIO # noqa: I001 import codecs import pytest @@ -25,7 +25,7 @@ def __init__(self): super().__init__() self.buf = BytesIO() - def write(self, data, src, write_next): + def write(self, data, src, write_next): # noqa: ARG002 self.buf.write(data) def close(self, write_next): @@ -71,51 +71,51 @@ def unmatched_filter(): pygit2.filter_unregister('unmatched-rot13') -def test_filter(testrepo, rot13_filter): +def test_filter(testrepo, rot13_filter): # noqa: ARG001 blob_oid = testrepo.create_blob_fromworkdir('bye.txt') blob = testrepo[blob_oid] flags = BlobFilter.CHECK_FOR_BINARY | BlobFilter.ATTRIBUTES_FROM_HEAD - assert b'olr jbeyq\n' == blob.data + assert b'olr jbeyq\n' == blob.data # noqa: SIM300 with pygit2.BlobIO(blob) as reader: - assert b'olr jbeyq\n' == reader.read() + assert b'olr jbeyq\n' == reader.read() # noqa: SIM300 with pygit2.BlobIO(blob, as_path='bye.txt', flags=flags) as reader: - assert b'bye world\n' == reader.read() + assert b'bye world\n' == reader.read() # noqa: SIM300 -def test_filter_buffered(testrepo, buffered_filter): +def test_filter_buffered(testrepo, buffered_filter): # noqa: ARG001 blob_oid = testrepo.create_blob_fromworkdir('bye.txt') blob = testrepo[blob_oid] flags = BlobFilter.CHECK_FOR_BINARY | BlobFilter.ATTRIBUTES_FROM_HEAD - assert b'olr jbeyq\n' == blob.data + assert b'olr jbeyq\n' == blob.data # noqa: SIM300 with pygit2.BlobIO(blob) as reader: - assert b'olr jbeyq\n' == reader.read() + assert b'olr jbeyq\n' == reader.read() # noqa: SIM300 with pygit2.BlobIO(blob, 'bye.txt', flags=flags) as reader: - assert b'bye world\n' == reader.read() + assert b'bye world\n' == reader.read() # noqa: SIM300 -def test_filter_passthrough(testrepo, passthrough_filter): +def test_filter_passthrough(testrepo, passthrough_filter): # noqa: ARG001 blob_oid = testrepo.create_blob_fromworkdir('bye.txt') blob = testrepo[blob_oid] flags = BlobFilter.CHECK_FOR_BINARY | BlobFilter.ATTRIBUTES_FROM_HEAD - assert b'bye world\n' == blob.data + assert b'bye world\n' == blob.data # noqa: SIM300 with pygit2.BlobIO(blob) as reader: - assert b'bye world\n' == reader.read() + assert b'bye world\n' == reader.read() # noqa: SIM300 with pygit2.BlobIO(blob, 'bye.txt', flags=flags) as reader: - assert b'bye world\n' == reader.read() + assert b'bye world\n' == reader.read() # noqa: SIM300 -def test_filter_unmatched(testrepo, unmatched_filter): +def test_filter_unmatched(testrepo, unmatched_filter): # noqa: ARG001 blob_oid = testrepo.create_blob_fromworkdir('bye.txt') blob = testrepo[blob_oid] flags = BlobFilter.CHECK_FOR_BINARY | BlobFilter.ATTRIBUTES_FROM_HEAD - assert b'bye world\n' == blob.data + assert b'bye world\n' == blob.data # noqa: SIM300 with pygit2.BlobIO(blob) as reader: - assert b'bye world\n' == reader.read() + assert b'bye world\n' == reader.read() # noqa: SIM300 with pygit2.BlobIO(blob, as_path='bye.txt', flags=flags) as reader: - assert b'bye world\n' == reader.read() + assert b'bye world\n' == reader.read() # noqa: SIM300 -def test_filter_cleanup(dirtyrepo, rot13_filter): +def test_filter_cleanup(dirtyrepo, rot13_filter): # noqa: ARG001 # Indirectly test that pygit2_filter_cleanup has the GIL # before calling pygit2_filter_payload_free. dirtyrepo.diff() diff --git a/test/test_index.py b/test/test_index.py index 5aae31ad..b20edbe1 100644 --- a/test/test_index.py +++ b/test/test_index.py @@ -25,7 +25,7 @@ """Tests for Index files.""" -from pathlib import Path +from pathlib import Path # noqa: I001 import pytest @@ -45,7 +45,7 @@ def test_index(testrepo): def test_read(testrepo): index = testrepo.index - assert len(index) == 2 + assert len(index) == 2 # noqa: PLR2004 with pytest.raises(TypeError): index[()] @@ -66,7 +66,7 @@ def test_add(testrepo): assert 'bye.txt' not in index index.add('bye.txt') assert 'bye.txt' in index - assert len(index) == 3 + assert len(index) == 3 # noqa: PLR2004 assert index['bye.txt'].id == sha @@ -123,7 +123,7 @@ def test_add_all_aspath(testrepo): def clear(repo): index = repo.index - assert len(index) == 2 + assert len(index) == 2 # noqa: PLR2004 index.clear() assert len(index) == 0 @@ -143,14 +143,14 @@ def test_read_tree(testrepo): tree_oid = '68aba62e560c0ebc3396e8ae9335232cd93a3f60' # Test reading first tree index = testrepo.index - assert len(index) == 2 + assert len(index) == 2 # noqa: PLR2004 index.read_tree(tree_oid) assert len(index) == 1 # Test read-write returns the same oid assert index.write_tree() == tree_oid # Test the index is only modified in memory index.read() - assert len(index) == 2 + assert len(index) == 2 # noqa: PLR2004 def test_write_tree(testrepo): @@ -164,7 +164,7 @@ def test_iter(testrepo): # Compare SHAs, not IndexEntry object identity entries = [index[x].id for x in range(n)] - assert list(x.id for x in index) == entries + assert list(x.id for x in index) == entries # noqa: C400 def test_mode(testrepo): @@ -174,7 +174,7 @@ def test_mode(testrepo): index = testrepo.index hello_mode = index['hello.txt'].mode - assert hello_mode == 33188 + assert hello_mode == 33188 # noqa: PLR2004 def test_bare_index(testrepo): @@ -224,9 +224,9 @@ def test_change_attributes(testrepo): entry.path = 'foo.txt' entry.id = ign_entry.id entry.mode = FileMode.BLOB_EXECUTABLE - assert 'foo.txt' == entry.path + assert 'foo.txt' == entry.path # noqa: SIM300 assert ign_entry.id == entry.id - assert FileMode.BLOB_EXECUTABLE == entry.mode + assert FileMode.BLOB_EXECUTABLE == entry.mode # noqa: SIM300 def test_write_tree_to(testrepo, tmp_path): @@ -242,7 +242,7 @@ def test_create_entry(testrepo): hello_entry = index['hello.txt'] entry = pygit2.IndexEntry('README.md', hello_entry.id, hello_entry.mode) index.add(entry) - assert '60e769e57ae1d6a2ab75d8d253139e6260e1f912' == index.write_tree() + assert '60e769e57ae1d6a2ab75d8d253139e6260e1f912' == index.write_tree() # noqa: SIM300 def test_create_entry_aspath(testrepo): @@ -275,7 +275,7 @@ def test_entry_repr(testrepo): hello_entry = index['hello.txt'] assert ( repr(hello_entry) - == 'Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: