summaryrefslogtreecommitdiff
path: root/git/test
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 /git/test
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
Diffstat (limited to 'git/test')
-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
12 files changed, 101 insertions, 92 deletions
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')