diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2015-01-04 13:48:29 +0100 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2015-01-04 13:48:29 +0100 |
commit | c80d727e374321573bb00e23876a67c77ff466e3 (patch) | |
tree | 7590d6ae544eac56e83639d27e1f9013b38d8a4b /git/test | |
parent | 965a08c3f9f2fbd62691d533425c699c943cb865 (diff) | |
download | gitpython-c80d727e374321573bb00e23876a67c77ff466e3.tar.gz |
Bumped version, updated changelog, reduced code smell
There is more work to do though, as many imports are still incorrect.
Also, there are still print statements
Diffstat (limited to 'git/test')
-rw-r--r-- | git/test/lib/asserts.py | 1 | ||||
-rw-r--r-- | git/test/lib/helper.py | 17 | ||||
-rw-r--r-- | git/test/performance/lib.py | 3 | ||||
-rw-r--r-- | git/test/performance/test_odb.py | 5 | ||||
-rw-r--r-- | git/test/performance/test_streams.py | 20 | ||||
-rw-r--r-- | git/test/test_actor.py | 1 | ||||
-rw-r--r-- | git/test/test_base.py | 3 | ||||
-rw-r--r-- | git/test/test_blob.py | 1 | ||||
-rw-r--r-- | git/test/test_config.py | 4 | ||||
-rw-r--r-- | git/test/test_diff.py | 2 | ||||
-rw-r--r-- | git/test/test_index.py | 37 | ||||
-rw-r--r-- | git/test/test_refs.py | 4 | ||||
-rw-r--r-- | git/test/test_remote.py | 4 | ||||
-rw-r--r-- | git/test/test_repo.py | 13 | ||||
-rw-r--r-- | git/test/test_submodule.py | 4 | ||||
-rw-r--r-- | git/test/test_tree.py | 5 | ||||
-rw-r--r-- | git/test/test_util.py | 1 |
17 files changed, 59 insertions, 66 deletions
diff --git a/git/test/lib/asserts.py b/git/test/lib/asserts.py index 351901dc..6f6d8960 100644 --- a/git/test/lib/asserts.py +++ b/git/test/lib/asserts.py @@ -5,7 +5,6 @@ # the BSD License: http://www.opensource.org/licenses/bsd-license.php import re -import unittest from nose import tools from nose.tools import * import stat diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py index 341f5789..a18f22ef 100644 --- a/git/test/lib/helper.py +++ b/git/test/lib/helper.py @@ -75,7 +75,7 @@ def _rmtree_onerror(osremove, fullpath, exec_info): if os.name != 'nt' or osremove is not os.remove: raise - os.chmod(fullpath, 0777) + os.chmod(fullpath, 0o777) os.remove(fullpath) @@ -194,26 +194,27 @@ def with_rw_and_rw_remote_repo(working_tree_ref): gd = Git().daemon(temp_dir, as_process=True) # yes, I know ... fortunately, this is always going to work if sleep time is just large enough time.sleep(0.5) - except Exception as err: + except Exception: gd = None # end # try to list remotes to diagnoes whether the server is up try: rw_repo.git.ls_remote(d_remote) - except GitCommandError, e: + except GitCommandError as e: # We assume in good faith that we didn't start the daemon - but make sure we kill it anyway # Of course we expect it to work here already, but maybe there are timing constraints # on some platforms ? if gd is not None: os.kill(gd.proc.pid, 15) - print str(e) + print(str(e)) if os.name == 'nt': - raise AssertionError( - 'git-daemon needs to run this test, but windows does not have one. Otherwise, run: git-daemon "%s"' % temp_dir) + msg = "git-daemon needs to run this test, but windows does not have one. " + msg += 'Otherwise, run: git-daemon "%s"' % temp_dir + raise AssertionError(msg) else: - raise AssertionError( - 'Please start a git-daemon to run this test, execute: git-daemon "%s"' % temp_dir) + msg = 'Please start a git-daemon to run this test, execute: git-daemon "%s"' % temp_dir + raise AssertionError(msg) # END make assertion # END catch ls remote error diff --git a/git/test/performance/lib.py b/git/test/performance/lib.py index e92e2b2d..928821ed 100644 --- a/git/test/performance/lib.py +++ b/git/test/performance/lib.py @@ -50,7 +50,8 @@ class TestBigRepoR(TestBase): repo_path = os.environ.get(k_env_git_repo) if repo_path is None: logging.info( - "You can set the %s environment variable to a .git repository of your choice - defaulting to the gitpython repository", k_env_git_repo) + ("You can set the %s environment variable to a .git repository of" % k_env_git_repo) + + "your choice - defaulting to the gitpython repository") repo_path = os.path.dirname(__file__) # end set some repo path self.gitrorepo = Repo(repo_path, odbt=GitCmdObjectDB) diff --git a/git/test/performance/test_odb.py b/git/test/performance/test_odb.py index 9d857260..1b570fa7 100644 --- a/git/test/performance/test_odb.py +++ b/git/test/performance/test_odb.py @@ -61,9 +61,10 @@ class TestObjDBPerformance(TestBigRepoR): # END for each bloblist elapsed = time() - st - print >> sys.stderr, "%s: Retrieved %i blob (%i KiB) and their data in %g s ( %f blobs / s, %f KiB / s )" % ( - type(repo.odb), nb, data_bytes / 1000, elapsed, nb / elapsed, (data_bytes / 1000) / elapsed) + msg = "%s: Retrieved %i blob (%i KiB) and their data in %g s ( %f blobs / s, %f KiB / s )"\ + % (type(repo.odb), nb, data_bytes / 1000, elapsed, nb / elapsed, (data_bytes / 1000) / elapsed) results[2].append(elapsed) + print >> sys.stderr, msg # END for each repo type # final results diff --git a/git/test/performance/test_streams.py b/git/test/performance/test_streams.py index facf9eed..18f19db3 100644 --- a/git/test/performance/test_streams.py +++ b/git/test/performance/test_streams.py @@ -44,8 +44,9 @@ class TestObjDBPerformance(TestBigRepoR): fsize_kib = os.path.getsize(db_file) / 1000 size_kib = size / 1000 - print >> sys.stderr, "Added %i KiB (filesize = %i KiB) of %s data to loose odb in %f s ( %f Write KiB / s)" % ( - size_kib, fsize_kib, desc, elapsed_add, size_kib / elapsed_add) + msg = "Added %i KiB (filesize = %i KiB) of %s data to loose odb in %f s ( %f Write KiB / s)" + msg %= (size_kib, fsize_kib, desc, elapsed_add, size_kib / elapsed_add) + print >> sys.stderr, msg # reading all at once st = time() @@ -55,8 +56,9 @@ class TestObjDBPerformance(TestBigRepoR): stream.seek(0) assert shadata == stream.getvalue() - print >> sys.stderr, "Read %i KiB of %s data at once from loose odb in %f s ( %f Read KiB / s)" % ( - size_kib, desc, elapsed_readall, size_kib / elapsed_readall) + msg = "Read %i KiB of %s data at once from loose odb in %f s ( %f Read KiB / s)" + msg %= (size_kib, desc, elapsed_readall, size_kib / elapsed_readall) + print >> sys.stderr, msg # reading in chunks of 1 MiB cs = 512 * 1000 @@ -99,8 +101,9 @@ class TestObjDBPerformance(TestBigRepoR): # as its the same sha, we reuse our path fsize_kib = os.path.getsize(db_file) / 1000 - print >> sys.stderr, "Added %i KiB (filesize = %i KiB) of %s data to using git-hash-object in %f s ( %f Write KiB / s)" % ( - size_kib, fsize_kib, desc, gelapsed_add, size_kib / gelapsed_add) + msg = "Added %i KiB (filesize = %i KiB) of %s data to using git-hash-object in %f s ( %f Write KiB / s)" + msg %= (size_kib, fsize_kib, desc, gelapsed_add, size_kib / gelapsed_add) + print >> sys.stderr, msg # compare ... print >> sys.stderr, "Git-Python is %f %% faster than git when adding big %s files" % ( @@ -126,8 +129,9 @@ class TestObjDBPerformance(TestBigRepoR): break # END read stream gelapsed_readchunks = time() - st - print >> sys.stderr, "Read %i KiB of %s data in %i KiB chunks from git-cat-file in %f s ( %f Read KiB / s)" % ( - size_kib, desc, cs_kib, gelapsed_readchunks, size_kib / gelapsed_readchunks) + msg = "Read %i KiB of %s data in %i KiB chunks from git-cat-file in %f s ( %f Read KiB / s)" + msg %= (size_kib, desc, cs_kib, gelapsed_readchunks, size_kib / gelapsed_readchunks) + print >> sys.stderr, msg # compare print >> sys.stderr, "Git-Python is %f %% faster than git when reading big %s files in chunks" % ( diff --git a/git/test/test_actor.py b/git/test/test_actor.py index 5ccf1d2e..ee968455 100644 --- a/git/test/test_actor.py +++ b/git/test/test_actor.py @@ -4,7 +4,6 @@ # This module is part of GitPython and is released under # the BSD License: http://www.opensource.org/licenses/bsd-license.php -import os from git.test.lib import * from git import * diff --git a/git/test/test_base.py b/git/test/test_base.py index d1b57984..ea241f4c 100644 --- a/git/test/test_base.py +++ b/git/test/test_base.py @@ -5,15 +5,12 @@ # the BSD License: http://www.opensource.org/licenses/bsd-license.php import git.objects.base as base -import git.refs as refs import os from git.test.lib import * from git import * -from itertools import chain from git.objects.util import get_object_type_by_name from gitdb.util import hex_to_bin -import tempfile class TestBase(TestBase): diff --git a/git/test/test_blob.py b/git/test/test_blob.py index ddd2893f..cf45d82a 100644 --- a/git/test/test_blob.py +++ b/git/test/test_blob.py @@ -6,7 +6,6 @@ from git.test.lib import * from git import * -from gitdb.util import hex_to_bin class TestBlob(TestBase): diff --git a/git/test/test_config.py b/git/test/test_config.py index 0e5396a3..3e435c47 100644 --- a/git/test/test_config.py +++ b/git/test/test_config.py @@ -74,7 +74,7 @@ class TestBase(TestCase): num_options = 0 # test reader methods - assert r_config._is_initialized == False + assert r_config._is_initialized is False for section in r_config.sections(): num_sections += 1 for option in r_config.options(section): @@ -93,7 +93,7 @@ class TestBase(TestCase): self.failUnlessRaises(IOError, r_config.remove_section, section) # END for each section assert num_sections and num_options - assert r_config._is_initialized == True + assert r_config._is_initialized is True # get value which doesnt exist, with default default = "my default value" diff --git a/git/test/test_diff.py b/git/test/test_diff.py index 151a3d14..8e2cef4b 100644 --- a/git/test/test_diff.py +++ b/git/test/test_diff.py @@ -54,7 +54,7 @@ class TestDiff(TestBase): for fixture_name in fixtures: diff_proc = StringProcessAdapter(fixture(fixture_name)) - diffs = Diff._index_from_patch_format(self.rorepo, diff_proc.stdout) + Diff._index_from_patch_format(self.rorepo, diff_proc.stdout) # END for each fixture def test_diff_interface(self): diff --git a/git/test/test_index.py b/git/test/test_index.py index 3f85ea90..08dfdd12 100644 --- a/git/test/test_index.py +++ b/git/test/test_index.py @@ -7,13 +7,14 @@ from git.test.lib import * from git import * from gitdb.util import hex_to_bin -import inspect import os import sys import tempfile -import glob import shutil -from stat import * +from stat import ( + S_ISLNK, + ST_MODE +) from StringIO import StringIO from gitdb.base import IStream @@ -60,7 +61,7 @@ class TestIndex(TestBase): for entry in entries: assert isinstance(entry, BaseIndexEntry) assert not os.path.isabs(entry.path) - assert not "\\" in entry.path + assert "\\" not in entry.path # END for each entry def test_index_file_base(self): @@ -70,11 +71,10 @@ class TestIndex(TestBase): assert index.version > 0 # test entry - last_val = None entry = index.entries.itervalues().next() for attr in ("path", "ctime", "mtime", "dev", "inode", "mode", "uid", "gid", "size", "binsha", "hexsha", "stage"): - val = getattr(entry, attr) + getattr(entry, attr) # END for each method # test update @@ -100,7 +100,6 @@ class TestIndex(TestBase): if isinstance(tree, str): tree = self.rorepo.commit(tree).tree - num_blobs = 0 blist = list() for blob in tree.traverse(predicate=lambda e, d: e.type == "blob", branch_first=False): assert (blob.path, 0) in index.entries @@ -240,7 +239,7 @@ class TestIndex(TestBase): # resetting the head will leave the index in a different state, and the # diff will yield a few changes cur_head_commit = rw_repo.head.reference.commit - ref = rw_repo.head.reset('HEAD~6', index=True, working_tree=False) + rw_repo.head.reset('HEAD~6', index=True, working_tree=False) # diff against same index is 0 diff = index.diff() @@ -468,7 +467,7 @@ class TestIndex(TestBase): entries = index.reset(new_commit).add( [os.path.abspath(os.path.join('lib', 'git', 'head.py'))] * 2, fprogress=self._fprogress_add) self._assert_entries(entries) - assert entries[0].mode & 0644 == 0644 + assert entries[0].mode & 0o644 == 0o644 # would fail, test is too primitive to handle this case # self._assert_fprogress(entries) self._reset_progress() @@ -492,9 +491,9 @@ class TestIndex(TestBase): # add new file new_file_relapath = "my_new_file" - new_file_path = self._make_file(new_file_relapath, "hello world", rw_repo) + self._make_file(new_file_relapath, "hello world", rw_repo) entries = index.reset(new_commit).add( - [BaseIndexEntry((010644, null_bin_sha, 0, new_file_relapath))], fprogress=self._fprogress_add) + [BaseIndexEntry((0o10644, null_bin_sha, 0, new_file_relapath))], fprogress=self._fprogress_add) self._assert_entries(entries) self._assert_fprogress(entries) assert len(entries) == 1 and entries[0].hexsha != null_hex_sha @@ -519,7 +518,7 @@ class TestIndex(TestBase): fake_symlink_relapath = "my_fake_symlink" link_target = "/etc/that" fake_symlink_path = self._make_file(fake_symlink_relapath, link_target, rw_repo) - fake_entry = BaseIndexEntry((0120000, null_bin_sha, 0, fake_symlink_relapath)) + fake_entry = BaseIndexEntry((0o120000, null_bin_sha, 0, fake_symlink_relapath)) entries = index.reset(new_commit).add([fake_entry], fprogress=self._fprogress_add) self._assert_entries(entries) self._assert_fprogress(entries) @@ -527,7 +526,7 @@ class TestIndex(TestBase): assert len(entries) == 1 and S_ISLNK(entries[0].mode) # assure this also works with an alternate method - full_index_entry = IndexEntry.from_base(BaseIndexEntry((0120000, entries[0].binsha, 0, entries[0].path))) + full_index_entry = IndexEntry.from_base(BaseIndexEntry((0o120000, entries[0].binsha, 0, entries[0].path))) entry_key = index.entry_key(full_index_entry) index.reset(new_commit) @@ -605,7 +604,7 @@ class TestIndex(TestBase): for fid in range(3): fname = 'newfile%i' % fid open(fname, 'wb').write("abcd") - yield Blob(rw_repo, Blob.NULL_BIN_SHA, 0100644, fname) + yield Blob(rw_repo, Blob.NULL_BIN_SHA, 0o100644, fname) # END for each new file # END path producer paths = list(make_paths()) @@ -627,7 +626,7 @@ class TestIndex(TestBase): files = (arela, brela) for fkey in keys: - assert not fkey in index.entries + assert fkey not in index.entries index.add(files, write=True) nc = index.commit("2 files committed", head=False) @@ -637,7 +636,7 @@ class TestIndex(TestBase): # just the index index.reset(paths=(arela, afile)) - assert not akey in index.entries + assert akey not in index.entries assert bkey in index.entries # now with working tree - files on disk as well as entries must be recreated @@ -690,10 +689,10 @@ class TestIndex(TestBase): filename = 'my-imaginary-file' istream = rw_bare_repo.odb.store( IStream(Blob.type, filesize, fileobj)) - entry = BaseIndexEntry((100644, istream.binsha, 0, filename)) + entry = BaseIndexEntry((0o100644, istream.binsha, 0, filename)) try: rw_bare_repo.index.add([entry]) - except AssertionError, e: + except AssertionError: self.fail("Adding to the index of a bare repo is not allowed.") # Adding using a path should still require a non-bare repository. @@ -701,6 +700,6 @@ class TestIndex(TestBase): path = os.path.join('git', 'test', 'test_index.py') try: rw_bare_repo.index.add([path]) - except Exception, e: + except Exception as e: asserted = "does not have a working tree" in e.message assert asserted, "Adding using a filename is not correctly asserted." diff --git a/git/test/test_refs.py b/git/test/test_refs.py index c4f7077b..4df3fa8a 100644 --- a/git/test/test_refs.py +++ b/git/test/test_refs.py @@ -155,10 +155,10 @@ class TestRefs(TestBase): assert len(types_found) >= 3 def test_is_valid(self): - assert Reference(self.rorepo, 'refs/doesnt/exist').is_valid() == False + assert not Reference(self.rorepo, 'refs/doesnt/exist').is_valid() assert self.rorepo.head.is_valid() assert self.rorepo.head.reference.is_valid() - assert SymbolicReference(self.rorepo, 'hellothere').is_valid() == False + assert not SymbolicReference(self.rorepo, 'hellothere').is_valid() def test_orig_head(self): assert type(self.rorepo.head.orig_head()) == SymbolicReference diff --git a/git/test/test_remote.py b/git/test/test_remote.py index c9329f25..d49a9061 100644 --- a/git/test/test_remote.py +++ b/git/test/test_remote.py @@ -259,7 +259,6 @@ class TestRemote(TestBase): def _assert_push_and_pull(self, remote, rw_repo, remote_repo): # push our changes lhead = rw_repo.head - lindex = rw_repo.index # assure we are on master and it is checked out where the remote is try: lhead.reference = rw_repo.heads.master @@ -448,7 +447,8 @@ class TestRemote(TestBase): def test_fetch_info(self): # assure we can handle remote-tracking branches - fetch_info_line_fmt = "c437ee5deb8d00cf02f03720693e4c802e99f390 not-for-merge %s '0.3' of git://github.com/gitpython-developers/GitPython" + fetch_info_line_fmt = "c437ee5deb8d00cf02f03720693e4c802e99f390 not-for-merge %s '0.3' of " + fetch_info_line_fmt += "git://github.com/gitpython-developers/GitPython" remote_info_line_fmt = "* [new branch] nomatter -> %s" fi = FetchInfo._from_line(self.rorepo, remote_info_line_fmt % "local/master", diff --git a/git/test/test_repo.py b/git/test/test_repo.py index d4069670..3f1a3a3c 100644 --- a/git/test/test_repo.py +++ b/git/test/test_repo.py @@ -7,7 +7,6 @@ from git.test.lib import (patch, TestBase, with_rw_repo, fixture, - GIT_REPO, assert_false, assert_equal, assert_true, @@ -15,7 +14,7 @@ from git.test.lib import (patch, from git import * from git.util import join_path_native from git.exc import BadObject -from gitdb.util import hex_to_bin, bin_to_hex +from gitdb.util import bin_to_hex import os import sys @@ -143,7 +142,7 @@ class TestRepo(TestBase): for path in (git_dir_rela, git_dir_abs): r = Repo.init(path=path, bare=True) assert isinstance(r, Repo) - assert r.bare == True + assert r.bare is True assert os.path.isdir(r.git_dir) self._assert_empty_repo(r) @@ -179,7 +178,7 @@ class TestRepo(TestBase): os.makedirs(git_dir_rela) os.chdir(git_dir_rela) r = Repo.init(bare=False) - r.bare == False + assert r.bare is False self._assert_empty_repo(r) finally: @@ -230,7 +229,7 @@ class TestRepo(TestBase): # END index orig_val = self.rorepo._bare self.rorepo._bare = True - assert self.rorepo.is_dirty() == False + assert self.rorepo.is_dirty() is False self.rorepo._bare = orig_val def test_head(self): @@ -280,7 +279,7 @@ class TestRepo(TestBase): for item in self.rorepo.head.commit.tree.traverse( predicate=lambda i, d: i.type == 'blob' and i.path.endswith('.py')): c += 1 - b = self.rorepo.blame(self.rorepo.head, item.path) + self.rorepo.blame(self.rorepo.head, item.path) # END for each item to traverse assert c @@ -503,7 +502,7 @@ class TestRepo(TestBase): assert obj.type == ref.object.type num_resolved += 1 except BadObject: - print "failed on %s" % path_section + print ("failed on %s" % path_section) # is fine, in case we have something like 112, which belongs to remotes/rname/merge-requests/112 pass # END exception handling diff --git a/git/test/test_submodule.py b/git/test/test_submodule.py index 9c0085e8..e3223c42 100644 --- a/git/test/test_submodule.py +++ b/git/test/test_submodule.py @@ -32,7 +32,7 @@ class TestRootProgress(RootUpdateProgress): """Just prints messages, for now without checking the correctness of the states""" def update(self, op, index, max_count, message=''): - print message + print(message) prog = TestRootProgress() @@ -107,7 +107,6 @@ class TestSubmodule(TestBase): # END handle bare repo # make the old into a new - this doesn't work as the name changed - prev_parent_commit = smold.parent_commit self.failUnlessRaises(ValueError, smold.set_parent_commit, self.k_subm_current) # the sha is properly updated smold.set_parent_commit(self.k_subm_changed + "~1") @@ -343,7 +342,6 @@ class TestSubmodule(TestBase): # rename a module nmp = join_path_native("new", "module", "dir") + "/" # new module path pmp = nsm.path - abspmp = nsm.abspath assert nsm.move(nmp) is nsm nmp = nmp[:-1] # cut last / nmpl = to_native_path_linux(nmp) diff --git a/git/test/test_tree.py b/git/test/test_tree.py index 2c740f1a..adcb854f 100644 --- a/git/test/test_tree.py +++ b/git/test/test_tree.py @@ -7,10 +7,7 @@ import os from git.test.lib import * from git import * -from git.objects.fun import ( - traverse_tree_recursive, - traverse_trees_recursive -) + from cStringIO import StringIO diff --git a/git/test/test_util.py b/git/test/test_util.py index 1ba855af..28aefa61 100644 --- a/git/test/test_util.py +++ b/git/test/test_util.py @@ -4,7 +4,6 @@ # This module is part of GitPython and is released under # the BSD License: http://www.opensource.org/licenses/bsd-license.php -import os import tempfile from git.util import * |