summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostis Anagnostopoulos <ankostis@gmail.com>2016-10-03 23:35:55 +0200
committerKostis Anagnostopoulos <ankostis@gmail.com>2016-10-04 02:10:48 +0200
commita469af892b3e929cbe9d29e414b6fcd59bec246e (patch)
treef1ab9ed8946b3be2bb7ed1d3529ad5c0f348f550
parentbe44602b633cfb49a472e192f235ba6de0055d38 (diff)
downloadgitpython-a469af892b3e929cbe9d29e414b6fcd59bec246e.tar.gz
src: No PyDev warnings
+ Mark all unused vars and other non-pep8 (PyDev) warnings + test_utils: + enable & fix forgotten IterableList looped path. + unittestize all assertions. + remote: minor fix progress dispatching unknown err-lines
-rw-r--r--git/__init__.py24
-rw-r--r--git/compat.py23
-rw-r--r--git/config.py4
-rw-r--r--git/db.py4
-rw-r--r--git/exc.py2
-rw-r--r--git/index/base.py13
-rw-r--r--git/index/fun.py2
-rw-r--r--git/objects/__init__.py16
-rw-r--r--git/objects/base.py2
-rw-r--r--git/objects/commit.py4
-rw-r--r--git/objects/fun.py4
-rw-r--r--git/objects/tag.py6
-rw-r--r--git/refs/reference.py2
-rw-r--r--git/refs/symbolic.py6
-rw-r--r--git/remote.py8
-rw-r--r--git/repo/fun.py2
-rw-r--r--git/test/lib/asserts.py14
-rw-r--r--git/test/performance/test_streams.py4
-rw-r--r--git/test/test_commit.py2
-rw-r--r--git/test/test_docs.py11
-rw-r--r--git/test/test_exc.py14
-rw-r--r--git/test/test_git.py4
-rw-r--r--git/test/test_index.py4
-rw-r--r--git/test/test_refs.py4
-rw-r--r--git/test/test_remote.py6
-rw-r--r--git/test/test_repo.py2
-rw-r--r--git/test/test_submodule.py6
-rw-r--r--git/test/test_util.py122
-rw-r--r--git/util.py14
29 files changed, 172 insertions, 157 deletions
diff --git a/git/__init__.py b/git/__init__.py
index e8dae272..58e4e7b6 100644
--- a/git/__init__.py
+++ b/git/__init__.py
@@ -4,7 +4,7 @@
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
# flake8: noqa
-
+#@PydevCodeAnalysisIgnore
import os
import sys
import inspect
@@ -32,17 +32,17 @@ _init_externals()
#{ Imports
-from git.config import GitConfigParser
-from git.objects import *
-from git.refs import *
-from git.diff import *
-from git.exc import *
-from git.db import *
-from git.cmd import Git
-from git.repo import Repo
-from git.remote import *
-from git.index import *
-from git.util import (
+from git.config import GitConfigParser # @NoMove @IgnorePep8
+from git.objects import * # @NoMove @IgnorePep8
+from git.refs import * # @NoMove @IgnorePep8
+from git.diff import * # @NoMove @IgnorePep8
+from git.exc import * # @NoMove @IgnorePep8
+from git.db import * # @NoMove @IgnorePep8
+from git.cmd import Git # @NoMove @IgnorePep8
+from git.repo import Repo # @NoMove @IgnorePep8
+from git.remote import * # @NoMove @IgnorePep8
+from git.index import * # @NoMove @IgnorePep8
+from git.util import ( # @NoMove @IgnorePep8
LockFile,
BlockingLockFile,
Stats,
diff --git a/git/compat.py b/git/compat.py
index 441a3761..e7243e25 100644
--- a/git/compat.py
+++ b/git/compat.py
@@ -13,14 +13,14 @@ import sys
from gitdb.utils.compat import (
xrange,
- MAXSIZE,
- izip,
+ MAXSIZE, # @UnusedImport
+ izip, # @UnusedImport
)
from gitdb.utils.encoding import (
- string_types,
- text_type,
- force_bytes,
- force_text
+ string_types, # @UnusedImport
+ text_type, # @UnusedImport
+ force_bytes, # @UnusedImport
+ force_text # @UnusedImport
)
@@ -33,17 +33,21 @@ defenc = sys.getdefaultencoding()
if PY3:
import io
FileType = io.IOBase
+
def byte_ord(b):
return b
+
def bchr(n):
return bytes([n])
+
def mviter(d):
return d.values()
- range = xrange
+
+ range = xrange # @ReservedAssignment
unicode = str
binary_type = bytes
else:
- FileType = file
+ FileType = file # @UndefinedVariable on PY3
# usually, this is just ascii, which might not enough for our encoding needs
# Unless it's set specifically, we override it to be utf-8
if defenc == 'ascii':
@@ -52,7 +56,8 @@ else:
bchr = chr
unicode = unicode
binary_type = str
- range = xrange
+ range = xrange # @ReservedAssignment
+
def mviter(d):
return d.itervalues()
diff --git a/git/config.py b/git/config.py
index 3c6a32eb..eddfac15 100644
--- a/git/config.py
+++ b/git/config.py
@@ -40,7 +40,7 @@ log.addHandler(logging.NullHandler())
class MetaParserBuilder(abc.ABCMeta):
"""Utlity class wrapping base-class methods into decorators that assure read-only properties"""
- def __new__(metacls, name, bases, clsdict):
+ def __new__(cls, name, bases, clsdict):
"""
Equip all base-class methods with a needs_values decorator, and all non-const methods
with a set_dirty_and_flush_changes decorator in addition to that."""
@@ -62,7 +62,7 @@ class MetaParserBuilder(abc.ABCMeta):
# END for each base
# END if mutating methods configuration is set
- new_type = super(MetaParserBuilder, metacls).__new__(metacls, name, bases, clsdict)
+ new_type = super(MetaParserBuilder, cls).__new__(cls, name, bases, clsdict)
return new_type
diff --git a/git/db.py b/git/db.py
index c4e19858..39b9872a 100644
--- a/git/db.py
+++ b/git/db.py
@@ -7,7 +7,7 @@ from gitdb.util import (
bin_to_hex,
hex_to_bin
)
-from gitdb.db import GitDB
+from gitdb.db import GitDB # @UnusedImport
from gitdb.db import LooseObjectDB
from .exc import (
@@ -54,7 +54,7 @@ class GitCmdObjectDB(LooseObjectDB):
:note: currently we only raise BadObject as git does not communicate
AmbiguousObjects separately"""
try:
- hexsha, typename, size = self._git.get_object_header(partial_hexsha)
+ hexsha, typename, size = self._git.get_object_header(partial_hexsha) # @UnusedVariable
return hex_to_bin(hexsha)
except (GitCommandError, ValueError):
raise BadObject(partial_hexsha)
diff --git a/git/exc.py b/git/exc.py
index 47215c21..eb7c3c0e 100644
--- a/git/exc.py
+++ b/git/exc.py
@@ -5,7 +5,7 @@
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
""" Module containing all exceptions thrown througout the git package, """
-from gitdb.exc import * # NOQA
+from gitdb.exc import * # NOQA @UnusedWildImport
from git.compat import UnicodeMixin, safe_decode, string_types
diff --git a/git/index/base.py b/git/index/base.py
index 9b6d28ab..ac2d3019 100644
--- a/git/index/base.py
+++ b/git/index/base.py
@@ -170,7 +170,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
def _deserialize(self, stream):
"""Initialize this instance with index values read from the given stream"""
- self.version, self.entries, self._extension_data, conten_sha = read_cache(stream)
+ self.version, self.entries, self._extension_data, conten_sha = read_cache(stream) # @UnusedVariable
return self
def _entries_sorted(self):
@@ -404,7 +404,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
continue
# END glob handling
try:
- for root, dirs, files in os.walk(abs_path, onerror=raise_exc):
+ for root, dirs, files in os.walk(abs_path, onerror=raise_exc): # @UnusedVariable
for rela_file in files:
# add relative paths only
yield os.path.join(root.replace(rs, ''), rela_file)
@@ -599,7 +599,6 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
"""Store file at filepath in the database and return the base index entry
Needs the git_working_dir decorator active ! This must be assured in the calling code"""
st = os.lstat(filepath) # handles non-symlinks as well
- stream = None
if S_ISLNK(st.st_mode):
# in PY3, readlink is string, but we need bytes. In PY2, it's just OS encoded bytes, we assume UTF-8
open_stream = lambda: BytesIO(force_bytes(os.readlink(filepath), encoding=defenc))
@@ -1102,11 +1101,11 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
try:
self.entries[(co_path, 0)]
except KeyError:
- dir = co_path
- if not dir.endswith('/'):
- dir += '/'
+ folder = co_path
+ if not folder.endswith('/'):
+ folder += '/'
for entry in mviter(self.entries):
- if entry.path.startswith(dir):
+ if entry.path.startswith(folder):
p = entry.path
self._write_path_to_stdin(proc, p, p, make_exc,
fprogress, read_from_stdout=False)
diff --git a/git/index/fun.py b/git/index/fun.py
index 74ac929e..7a7593fe 100644
--- a/git/index/fun.py
+++ b/git/index/fun.py
@@ -264,7 +264,7 @@ def write_tree_from_cache(entries, odb, sl, si=0):
# enter recursion
# ci - 1 as we want to count our current item as well
- sha, tree_entry_list = write_tree_from_cache(entries, odb, slice(ci - 1, xi), rbound + 1)
+ sha, tree_entry_list = write_tree_from_cache(entries, odb, slice(ci - 1, xi), rbound + 1) # @UnusedVariable
tree_items_append((sha, S_IFDIR, base))
# skip ahead
diff --git a/git/objects/__init__.py b/git/objects/__init__.py
index ee642876..23b2416a 100644
--- a/git/objects/__init__.py
+++ b/git/objects/__init__.py
@@ -3,22 +3,24 @@ Import all submodules main classes into the package space
"""
# flake8: noqa
from __future__ import absolute_import
+
import inspect
+
from .base import *
+from .blob import *
+from .commit import *
+from .submodule import util as smutil
+from .submodule.base import *
+from .submodule.root import *
+from .tag import *
+from .tree import *
# Fix import dependency - add IndexObject to the util module, so that it can be
# imported by the submodule.base
-from .submodule import util as smutil
smutil.IndexObject = IndexObject
smutil.Object = Object
del(smutil)
-from .submodule.base import *
-from .submodule.root import *
# must come after submodule was made available
-from .tag import *
-from .blob import *
-from .commit import *
-from .tree import *
__all__ = [name for name, obj in locals().items()
if not (name.startswith('_') or inspect.ismodule(obj))]
diff --git a/git/objects/base.py b/git/objects/base.py
index 77d0ed63..0b849960 100644
--- a/git/objects/base.py
+++ b/git/objects/base.py
@@ -40,7 +40,7 @@ class Object(LazyMixin):
assert len(binsha) == 20, "Require 20 byte binary sha, got %r, len = %i" % (binsha, len(binsha))
@classmethod
- def new(cls, repo, id):
+ def new(cls, repo, id): # @ReservedAssignment
"""
:return: New Object instance of a type appropriate to the object type behind
id. The id of the newly created object will be a binsha even though
diff --git a/git/objects/commit.py b/git/objects/commit.py
index 000ab3d0..1534c552 100644
--- a/git/objects/commit.py
+++ b/git/objects/commit.py
@@ -140,7 +140,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
def _set_cache_(self, attr):
if attr in Commit.__slots__:
# read the data in a chunk, its faster - then provide a file wrapper
- binsha, typename, self.size, stream = self.repo.odb.stream(self.binsha)
+ binsha, typename, self.size, stream = self.repo.odb.stream(self.binsha) # @UnusedVariable
self._deserialize(BytesIO(stream.read()))
else:
super(Commit, self)._set_cache_(attr)
@@ -267,7 +267,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
hexsha = line.strip()
if len(hexsha) > 40:
# split additional information, as returned by bisect for instance
- hexsha, rest = line.split(None, 1)
+ hexsha, _ = line.split(None, 1)
# END handle extra info
assert len(hexsha) == 40, "Invalid line: %s" % hexsha
diff --git a/git/objects/fun.py b/git/objects/fun.py
index c04f80b5..5c0f4819 100644
--- a/git/objects/fun.py
+++ b/git/objects/fun.py
@@ -157,9 +157,9 @@ def traverse_trees_recursive(odb, tree_shas, path_prefix):
if not item:
continue
# END skip already done items
- entries = [None for n in range(nt)]
+ entries = [None for _ in range(nt)]
entries[ti] = item
- sha, mode, name = item # its faster to unpack
+ sha, mode, name = item # its faster to unpack @UnusedVariable
is_dir = S_ISDIR(mode) # type mode bits
# find this item in all other tree data items
diff --git a/git/objects/tag.py b/git/objects/tag.py
index c8684447..cefff083 100644
--- a/git/objects/tag.py
+++ b/git/objects/tag.py
@@ -21,7 +21,7 @@ class TagObject(base.Object):
type = "tag"
__slots__ = ("object", "tag", "tagger", "tagged_date", "tagger_tz_offset", "message")
- def __init__(self, repo, binsha, object=None, tag=None,
+ def __init__(self, repo, binsha, object=None, tag=None, # @ReservedAssignment
tagger=None, tagged_date=None, tagger_tz_offset=None, message=None):
"""Initialize a tag object with additional data
@@ -55,8 +55,8 @@ class TagObject(base.Object):
ostream = self.repo.odb.stream(self.binsha)
lines = ostream.read().decode(defenc).splitlines()
- obj, hexsha = lines[0].split(" ") # object <hexsha>
- type_token, type_name = lines[1].split(" ") # type <type_name>
+ obj, hexsha = lines[0].split(" ") # object <hexsha> @UnusedVariable
+ type_token, type_name = lines[1].split(" ") # type <type_name> @UnusedVariable
self.object = \
get_object_type_by_name(type_name.encode('ascii'))(self.repo, hex_to_bin(hexsha))
diff --git a/git/refs/reference.py b/git/refs/reference.py
index 3e132aef..cc99dc26 100644
--- a/git/refs/reference.py
+++ b/git/refs/reference.py
@@ -50,7 +50,7 @@ class Reference(SymbolicReference, LazyMixin, Iterable):
#{ Interface
- def set_object(self, object, logmsg=None):
+ def set_object(self, object, logmsg=None): # @ReservedAssignment
"""Special version which checks if the head-log needs an update as well
:return: self"""
oldbinsha = None
diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py
index 894b26d5..ebaff8ca 100644
--- a/git/refs/symbolic.py
+++ b/git/refs/symbolic.py
@@ -218,7 +218,7 @@ class SymbolicReference(object):
return self
- def set_object(self, object, logmsg=None):
+ def set_object(self, object, logmsg=None): # @ReservedAssignment
"""Set the object we point to, possibly dereference our symbolic reference first.
If the reference does not exist, it will be created
@@ -229,7 +229,7 @@ class SymbolicReference(object):
:note: plain SymbolicReferences may not actually point to objects by convention
:return: self"""
if isinstance(object, SymbolicReference):
- object = object.object
+ object = object.object # @ReservedAssignment
# END resolve references
is_detached = True
@@ -595,7 +595,7 @@ class SymbolicReference(object):
# END for each directory to walk
# read packed refs
- for sha, rela_path in cls._iter_packed_refs(repo):
+ for sha, rela_path in cls._iter_packed_refs(repo): # @UnusedVariable
if rela_path.startswith(common_path):
rela_paths.add(rela_path)
# END relative path matches common path
diff --git a/git/remote.py b/git/remote.py
index c2ffcc1a..d35e1fad 100644
--- a/git/remote.py
+++ b/git/remote.py
@@ -176,7 +176,7 @@ class PushInfo(object):
split_token = "..."
if control_character == " ":
split_token = ".."
- old_sha, new_sha = summary.split(' ')[0].split(split_token)
+ old_sha, new_sha = summary.split(' ')[0].split(split_token) # @UnusedVariable
# have to use constructor here as the sha usually is abbreviated
old_commit = old_sha
# END message handling
@@ -262,7 +262,7 @@ class FetchInfo(object):
# parse lines
control_character, operation, local_remote_ref, remote_local_ref, note = match.groups()
try:
- new_hex_sha, fetch_operation, fetch_note = fetch_line.split("\t")
+ new_hex_sha, fetch_operation, fetch_note = fetch_line.split("\t") # @UnusedVariable
ref_type_name, fetch_note = fetch_note.split(' ', 1)
except ValueError: # unpack error
raise ValueError("Failed to parse FETCH_HEAD line: %r" % fetch_line)
@@ -625,8 +625,8 @@ class Remote(LazyMixin, Iterable):
for pline in progress_handler(line):
# END handle special messages
for cmd in cmds:
- if len(line) > 1 and line[0] == ' ' and line[1] == cmd:
- fetch_info_lines.append(line)
+ if len(pline) > 1 and pline[0] == ' ' and pline[1] == cmd:
+ fetch_info_lines.append(pline)
continue
# end find command code
# end for each comand code we know
diff --git a/git/repo/fun.py b/git/repo/fun.py
index 0483eaa9..320eb1c8 100644
--- a/git/repo/fun.py
+++ b/git/repo/fun.py
@@ -284,7 +284,7 @@ def rev_parse(repo, rev):
try:
if token == "~":
obj = to_commit(obj)
- for item in xrange(num):
+ for _ in xrange(num):
obj = obj.parents[0]
# END for each history item to walk
elif token == "^":
diff --git a/git/test/lib/asserts.py b/git/test/lib/asserts.py
index 9edc49e0..6f5ba714 100644
--- a/git/test/lib/asserts.py
+++ b/git/test/lib/asserts.py
@@ -8,18 +8,18 @@ import re
import stat
from nose.tools import (
- assert_equal,
- assert_not_equal,
- assert_raises,
- raises,
- assert_true,
- assert_false
+ assert_equal, # @UnusedImport
+ assert_not_equal, # @UnusedImport
+ assert_raises, # @UnusedImport
+ raises, # @UnusedImport
+ assert_true, # @UnusedImport
+ assert_false # @UnusedImport
)
try:
from unittest.mock import patch
except ImportError:
- from mock import patch
+ from mock import patch # @NoMove @UnusedImport
__all__ = ['assert_instance_of', 'assert_not_instance_of',
'assert_none', 'assert_not_none',
diff --git a/git/test/performance/test_streams.py b/git/test/performance/test_streams.py
index 8194547c..42cbade5 100644
--- a/git/test/performance/test_streams.py
+++ b/git/test/performance/test_streams.py
@@ -120,7 +120,7 @@ class TestObjDBPerformance(TestBigRepoR):
# read all
st = time()
- s, t, size, data = rwrepo.git.get_object_data(gitsha)
+ hexsha, typename, size, data = rwrepo.git.get_object_data(gitsha) # @UnusedVariable
gelapsed_readall = time() - st
print("Read %i KiB of %s data at once using git-cat-file in %f s ( %f Read KiB / s)"
% (size_kib, desc, gelapsed_readall, size_kib / gelapsed_readall), file=sys.stderr)
@@ -131,7 +131,7 @@ class TestObjDBPerformance(TestBigRepoR):
# read chunks
st = time()
- s, t, size, stream = rwrepo.git.stream_object_data(gitsha)
+ hexsha, typename, size, stream = rwrepo.git.stream_object_data(gitsha) # @UnusedVariable
while True:
data = stream.read(cs)
if len(data) < cs:
diff --git a/git/test/test_commit.py b/git/test/test_commit.py
index 66d988a3..fd9777fb 100644
--- a/git/test/test_commit.py
+++ b/git/test/test_commit.py
@@ -123,7 +123,7 @@ class TestCommit(TestBase):
check_entries(stats.total)
assert "files" in stats.total
- for filepath, d in stats.files.items():
+ for filepath, d in stats.files.items(): # @UnusedVariable
check_entries(d)
# END for each stated file
diff --git a/git/test/test_docs.py b/git/test/test_docs.py
index 6e505dd9..5c7ae7f0 100644
--- a/git/test/test_docs.py
+++ b/git/test/test_docs.py
@@ -70,7 +70,8 @@ class Tutorials(TestBase):
# heads, tags and references
# heads are branches in git-speak
# [8-test_init_repo_object]
- self.assertEqual(repo.head.ref, repo.heads.master) # head is a sym-ref pointing to master
+ self.assertEqual(repo.head.ref, repo.heads.master, # head is a sym-ref pointing to master
+ "It's ok if TC not running from `master`.")
self.assertEqual(repo.tags['0.3.5'], repo.tag('refs/tags/0.3.5')) # you can access tags in various ways too
self.assertEqual(repo.refs.master, repo.heads['master']) # .refs provides all refs, ie heads ...
@@ -242,9 +243,9 @@ class Tutorials(TestBase):
# [8-test_references_and_objects]
hc = repo.head.commit
hct = hc.tree
- hc != hct
- hc != repo.tags[0]
- hc == repo.head.reference.commit
+ hc != hct # @NoEffect
+ hc != repo.tags[0] # @NoEffect
+ hc == repo.head.reference.commit # @NoEffect
# ![8-test_references_and_objects]
# [9-test_references_and_objects]
@@ -347,7 +348,7 @@ class Tutorials(TestBase):
# The index contains all blobs in a flat list
assert len(list(index.iter_blobs())) == len([o for o in repo.head.commit.tree.traverse() if o.type == 'blob'])
# Access blob objects
- for (path, stage), entry in index.entries.items():
+ for (path, stage), entry in index.entries.items(): # @UnusedVariable
pass
new_file_path = os.path.join(repo.working_tree_dir, 'new-file-name')
open(new_file_path, 'w').close()
diff --git a/git/test/test_exc.py b/git/test/test_exc.py
index 7e6b023e..33f44034 100644
--- a/git/test/test_exc.py
+++ b/git/test/test_exc.py
@@ -29,13 +29,13 @@ _cmd_argvs = (
('θνιψοδε', 'κι', 'αλλα', 'non-unicode', 'args'),
)
_causes_n_substrings = (
- (None, None), # noqa: E241
- (7, "exit code(7)"), # noqa: E241
- ('Some string', "'Some string'"), # noqa: E241
- ('παλιο string', "'παλιο string'"), # noqa: E241
- (Exception("An exc."), "Exception('An exc.')"), # noqa: E241
- (Exception("Κακια exc."), "Exception('Κακια exc.')"), # noqa: E241
- (object(), "<object object at "), # noqa: E241
+ (None, None), # noqa: E241 @IgnorePep8
+ (7, "exit code(7)"), # noqa: E241 @IgnorePep8
+ ('Some string', "'Some string'"), # noqa: E241 @IgnorePep8
+ ('παλιο string', "'παλιο string'"), # noqa: E241 @IgnorePep8
+ (Exception("An exc."), "Exception('An exc.')"), # noqa: E241 @IgnorePep8
+ (Exception("Κακια exc."), "Exception('Κακια exc.')"), # noqa: E241 @IgnorePep8
+ (object(), "<object object at "), # noqa: E241 @IgnorePep8
)
_streams_n_substrings = (None, 'steram', 'ομορφο stream', )
diff --git a/git/test/test_git.py b/git/test/test_git.py
index 94614cd1..58ee8e9c 100644
--- a/git/test/test_git.py
+++ b/git/test/test_git.py
@@ -121,7 +121,7 @@ class TestGit(TestBase):
# read data - have to read it in one large chunk
size = int(obj_info.split()[2])
- data = g.stdout.read(size)
+ g.stdout.read(size)
g.stdout.read(1)
# now we should be able to read a new object
@@ -131,7 +131,7 @@ class TestGit(TestBase):
# same can be achived using the respective command functions
hexsha, typename, size = self.git.get_object_header(hexsha)
- hexsha, typename_two, size_two, data = self.git.get_object_data(hexsha)
+ hexsha, typename_two, size_two, data = self.git.get_object_data(hexsha) # @UnusedVariable
self.assertEqual(typename, typename_two)
self.assertEqual(size, size_two)
diff --git a/git/test/test_index.py b/git/test/test_index.py
index c9c68b9e..01506c6f 100644
--- a/git/test/test_index.py
+++ b/git/test/test_index.py
@@ -58,7 +58,7 @@ class TestIndex(TestBase):
def _assert_fprogress(self, entries):
self.assertEqual(len(entries), len(self._fprogress_map))
- for path, call_count in self._fprogress_map.items():
+ for path, call_count in self._fprogress_map.items(): # @UnusedVariable
self.assertEqual(call_count, 2)
# END for each item in progress map
self._reset_progress()
@@ -188,7 +188,7 @@ class TestIndex(TestBase):
# test BlobFilter
prefix = 'lib/git'
- for stage, blob in base_index.iter_blobs(BlobFilter([prefix])):
+ for stage, blob in base_index.iter_blobs(BlobFilter([prefix])): # @UnusedVariable
assert blob.path.startswith(prefix)
# writing a tree should fail with an unmerged index
diff --git a/git/test/test_refs.py b/git/test/test_refs.py
index 9816fb50..00b5232a 100644
--- a/git/test/test_refs.py
+++ b/git/test/test_refs.py
@@ -282,7 +282,7 @@ class TestRefs(TestBase):
# tag ref
tag_name = "5.0.2"
- light_tag = TagReference.create(rw_repo, tag_name)
+ TagReference.create(rw_repo, tag_name)
self.failUnlessRaises(GitCommandError, TagReference.create, rw_repo, tag_name)
light_tag = TagReference.create(rw_repo, tag_name, "HEAD~1", force=True)
assert isinstance(light_tag, TagReference)
@@ -442,7 +442,7 @@ class TestRefs(TestBase):
self.failUnlessRaises(OSError, SymbolicReference.create, rw_repo, symref_path, cur_head.reference.commit)
# it works if the new ref points to the same reference
- SymbolicReference.create(rw_repo, symref.path, symref.reference).path == symref.path
+ SymbolicReference.create(rw_repo, symref.path, symref.reference).path == symref.path # @NoEffect
SymbolicReference.delete(rw_repo, symref)
# would raise if the symref wouldn't have been deletedpbl
symref = SymbolicReference.create(rw_repo, symref_path, cur_head.reference)
diff --git a/git/test/test_remote.py b/git/test/test_remote.py
index b99e49cf..3fd71a1f 100644
--- a/git/test/test_remote.py
+++ b/git/test/test_remote.py
@@ -90,7 +90,7 @@ class TestRemoteProgress(RemoteProgress):
assert self._stages_per_op
# must have seen all stages
- for op, stages in self._stages_per_op.items():
+ for op, stages in self._stages_per_op.items(): # @UnusedVariable
assert stages & self.STAGE_MASK == self.STAGE_MASK
# END for each op/stage
@@ -331,7 +331,7 @@ class TestRemote(TestBase):
# push new tags
progress = TestRemoteProgress()
to_be_updated = "my_tag.1.0RV"
- new_tag = TagReference.create(rw_repo, to_be_updated)
+ new_tag = TagReference.create(rw_repo, to_be_updated) # @UnusedVariable
other_tag = TagReference.create(rw_repo, "my_obj_tag.2.1aRV", message="my message")
res = remote.push(progress=progress, tags=True)
assert res[-1].flags & PushInfo.NEW_TAG
@@ -432,7 +432,7 @@ class TestRemote(TestBase):
assert remote.rename(other_name) == remote
assert prev_name != remote.name
# multiple times
- for time in range(2):
+ for _ in range(2):
assert remote.rename(prev_name).name == prev_name
# END for each rename ( back to prev_name )
diff --git a/git/test/test_repo.py b/git/test/test_repo.py
index 28cc45d9..1d537e93 100644
--- a/git/test/test_repo.py
+++ b/git/test/test_repo.py
@@ -809,7 +809,7 @@ class TestRepo(TestBase):
# And we expect to set max handles to a low value, like 64
# You should set ulimit -n X, see .travis.yml
# The loops below would easily create 500 handles if these would leak (4 pipes + multiple mapped files)
- for i in range(64):
+ for _ in range(64):
for repo_type in (GitCmdObjectDB, GitDB):
repo = Repo(self.rorepo.working_tree_dir, odbt=repo_type)
last_commit(repo, 'master', 'git/test/test_base.py')
diff --git a/git/test/test_submodule.py b/git/test/test_submodule.py
index 481783a6..be388e5d 100644
--- a/git/test/test_submodule.py
+++ b/git/test/test_submodule.py
@@ -30,7 +30,7 @@ from git.util import to_native_path_linux, join_path_native
# closed due to mmap bugs on windows (as it appears)
if is_win:
try:
- import smmap.util
+ import smmap.util # @UnusedImport
smmap.util.MapRegion._test_read_into_memory = True
except ImportError:
sys.stderr.write("The submodule tests will fail as some files cannot be removed due to open file handles.\n")
@@ -98,7 +98,7 @@ class TestSubmodule(TestBase):
# force it to reread its information
del(smold._url)
- smold.url == sm.url
+ smold.url == sm.url # @NoEffect
# test config_reader/writer methods
sm.config_reader()
@@ -225,7 +225,7 @@ class TestSubmodule(TestBase):
assert csm.module_exists()
# tracking branch once again
- csm.module().head.ref.tracking_branch() is not None
+ csm.module().head.ref.tracking_branch() is not None # @NoEffect
# this flushed in a sub-submodule
assert len(list(rwrepo.iter_submodules())) == 2
diff --git a/git/test/test_util.py b/git/test/test_util.py
index 36fb5be3..e07417b4 100644
--- a/git/test/test_util.py
+++ b/git/test/test_util.py
@@ -27,18 +27,22 @@ from git.cmd import dashify
from git.compat import string_types, is_win
import time
+import ddt
class TestIterableMember(object):
"""A member of an iterable list"""
- __slots__ = ("name", "prefix_name")
+ __slots__ = "name"
def __init__(self, name):
self.name = name
- self.prefix_name = name
+ def __repr__(self):
+ return "TestIterableMember(%r)" % self.name
+
+@ddt.ddt
class TestUtils(TestBase):
def setup(self):
@@ -97,20 +101,21 @@ class TestUtils(TestBase):
self.assertLess(elapsed, wait_time + extra_time)
def test_user_id(self):
- assert '@' in get_user_id()
+ self.assertIn('@', get_user_id())
def test_parse_date(self):
# test all supported formats
def assert_rval(rval, veri_time, offset=0):
- assert len(rval) == 2
- assert isinstance(rval[0], int) and isinstance(rval[1], int)
- assert rval[0] == veri_time
- assert rval[1] == offset
+ self.assertEqual(len(rval), 2)
+ self.assertIsInstance(rval[0], int)
+ self.assertIsInstance(rval[1], int)
+ self.assertEqual(rval[0], veri_time)
+ self.assertEqual(rval[1], offset)
# now that we are here, test our conversion functions as well
utctz = altz_to_utctz_str(offset)
- assert isinstance(utctz, string_types)
- assert utctz_to_altz(verify_utctz(utctz)) == offset
+ self.assertIsInstance(utctz, string_types)
+ self.assertEqual(utctz_to_altz(verify_utctz(utctz)), offset)
# END assert rval utility
rfc = ("Thu, 07 Apr 2005 22:13:11 +0000", 0)
@@ -131,53 +136,56 @@ class TestUtils(TestBase):
def test_actor(self):
for cr in (None, self.rorepo.config_reader()):
- assert isinstance(Actor.committer(cr), Actor)
- assert isinstance(Actor.author(cr), Actor)
+ self.assertIsInstance(Actor.committer(cr), Actor)
+ self.assertIsInstance(Actor.author(cr), Actor)
# END assure config reader is handled
- def test_iterable_list(self):
- for args in (('name',), ('name', 'prefix_')):
- l = IterableList('name')
-
- m1 = TestIterableMember('one')
- m2 = TestIterableMember('two')
-
- l.extend((m1, m2))
-
- assert len(l) == 2
-
- # contains works with name and identity
- assert m1.name in l
- assert m2.name in l
- assert m2 in l
- assert m2 in l
- assert 'invalid' not in l
-
- # with string index
- assert l[m1.name] is m1
- assert l[m2.name] is m2
-
- # with int index
- assert l[0] is m1
- assert l[1] is m2
-
- # with getattr
- assert l.one is m1
- assert l.two is m2
-
- # test exceptions
- self.failUnlessRaises(AttributeError, getattr, l, 'something')
- self.failUnlessRaises(IndexError, l.__getitem__, 'something')
-
- # delete by name and index
- self.failUnlessRaises(IndexError, l.__delitem__, 'something')
- del(l[m2.name])
- assert len(l) == 1
- assert m2.name not in l and m1.name in l
- del(l[0])
- assert m1.name not in l
- assert len(l) == 0
-
- self.failUnlessRaises(IndexError, l.__delitem__, 0)
- self.failUnlessRaises(IndexError, l.__delitem__, 'something')
- # END for each possible mode
+ @ddt.data(('name', ''), ('name', 'prefix_'))
+ def test_iterable_list(self, case):
+ name, prefix = case
+ l = IterableList(name, prefix)
+
+ name1 = "one"
+ name2 = "two"
+ m1 = TestIterableMember(prefix + name1)
+ m2 = TestIterableMember(prefix + name2)
+
+ l.extend((m1, m2))
+
+ self.assertEqual(len(l), 2)
+
+ # contains works with name and identity
+ self.assertIn(name1, l)
+ self.assertIn(name2, l)
+ self.assertIn(m2, l)
+ self.assertIn(m2, l)
+ self.assertNotIn('invalid', l)
+
+ # with string index
+ self.assertIs(l[name1], m1)
+ self.assertIs(l[name2], m2)
+
+ # with int index
+ self.assertIs(l[0], m1)
+ self.assertIs(l[1], m2)
+
+ # with getattr
+ self.assertIs(l.one, m1)
+ self.assertIs(l.two, m2)
+
+ # test exceptions
+ self.failUnlessRaises(AttributeError, getattr, l, 'something')
+ self.failUnlessRaises(IndexError, l.__getitem__, 'something')
+
+ # delete by name and index
+ self.failUnlessRaises(IndexError, l.__delitem__, 'something')
+ del(l[name2])
+ self.assertEqual(len(l), 1)
+ self.assertNotIn(name2, l)
+ self.assertIn(name1, l)
+ del(l[0])
+ self.assertNotIn(name1, l)
+ self.assertEqual(len(l), 0)
+
+ self.failUnlessRaises(IndexError, l.__delitem__, 0)
+ self.failUnlessRaises(IndexError, l.__delitem__, 'something')
diff --git a/git/util.py b/git/util.py
index 1fa080a0..c96a6b08 100644
--- a/git/util.py
+++ b/git/util.py
@@ -17,13 +17,13 @@ import time
from functools import wraps
from git.compat import is_win
-from gitdb.util import ( # NOQA
+from gitdb.util import ( # NOQA
make_sha,
- LockedFD,
- file_contents_ro,
- LazyMixin,
- to_hex_sha,
- to_bin_sha
+ LockedFD, # @UnusedImport
+ file_contents_ro, # @UnusedImport
+ LazyMixin, # @UnusedImport
+ to_hex_sha, # @UnusedImport
+ to_bin_sha # @UnusedImport
)
import os.path as osp
@@ -251,7 +251,7 @@ class RemoteProgress(object):
# END could not get match
op_code = 0
- remote, op_name, percent, cur_count, max_count, message = match.groups()
+ remote, op_name, percent, cur_count, max_count, message = match.groups() # @UnusedVariable
# get operation id
if op_name == "Counting objects":