summaryrefslogtreecommitdiff
path: root/git/test
diff options
context:
space:
mode:
Diffstat (limited to 'git/test')
-rw-r--r--git/test/performance/lib.py18
-rw-r--r--git/test/performance/test_streams.py23
-rw-r--r--git/test/test_base.py26
-rw-r--r--git/test/test_commit.py42
-rw-r--r--git/test/test_config.py13
-rw-r--r--git/test/test_db.py9
-rw-r--r--git/test/test_diff.py24
-rw-r--r--git/test/test_docs.py26
-rw-r--r--git/test/test_git.py28
-rw-r--r--git/test/test_index.py50
-rw-r--r--git/test/test_reflog.py18
-rw-r--r--git/test/test_refs.py28
-rw-r--r--git/test/test_repo.py24
-rw-r--r--git/test/test_tree.py9
14 files changed, 177 insertions, 161 deletions
diff --git a/git/test/performance/lib.py b/git/test/performance/lib.py
index b57b9b71..700fee98 100644
--- a/git/test/performance/lib.py
+++ b/git/test/performance/lib.py
@@ -1,21 +1,23 @@
"""Contains library functions"""
+import logging
import os
-from git.test.lib import (
- TestBase
-)
import tempfile
-import logging
+from git import (
+ Repo
+)
from git.db import (
GitCmdObjectDB,
GitDB
)
-
-from git import (
- Repo
+from git.test.lib import (
+ TestBase
)
from git.util import rmtree
+import os.path as osp
+
+
#{ Invvariants
k_env_git_repo = "GIT_PYTHON_TEST_GIT_REPO_BASE"
@@ -52,7 +54,7 @@ class TestBigRepoR(TestBase):
logging.info(
("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__)
+ repo_path = osp.dirname(__file__)
# end set some repo path
self.gitrorepo = Repo(repo_path, odbt=GitCmdObjectDB, search_parent_directories=True)
self.puregitrorepo = Repo(repo_path, odbt=GitDB, search_parent_directories=True)
diff --git a/git/test/performance/test_streams.py b/git/test/performance/test_streams.py
index 42cbade5..699aa25b 100644
--- a/git/test/performance/test_streams.py
+++ b/git/test/performance/test_streams.py
@@ -1,26 +1,27 @@
"""Performance data streaming performance"""
from __future__ import print_function
-from time import time
import os
-import sys
import subprocess
+import sys
+from time import time
from git.test.lib import (
with_rw_repo
)
-from gitdb.util import bin_to_hex
+from gitdb import (
+ LooseObjectDB,
+ IStream
+)
from gitdb.test.lib import make_memory_file
+from gitdb.util import bin_to_hex
+
+import os.path as osp
from .lib import (
TestBigRepoR
)
-from gitdb import (
- LooseObjectDB,
- IStream
-)
-
class TestObjDBPerformance(TestBigRepoR):
@@ -31,7 +32,7 @@ class TestObjDBPerformance(TestBigRepoR):
def test_large_data_streaming(self, rwrepo):
# TODO: This part overlaps with the same file in gitdb.test.performance.test_stream
# It should be shared if possible
- ldb = LooseObjectDB(os.path.join(rwrepo.git_dir, 'objects'))
+ ldb = LooseObjectDB(osp.join(rwrepo.git_dir, 'objects'))
for randomize in range(2):
desc = (randomize and 'random ') or ''
@@ -47,7 +48,7 @@ class TestObjDBPerformance(TestBigRepoR):
elapsed_add = time() - st
assert ldb.has_object(binsha)
db_file = ldb.readable_db_object_path(bin_to_hex(binsha))
- fsize_kib = os.path.getsize(db_file) / 1000
+ fsize_kib = osp.getsize(db_file) / 1000
size_kib = size / 1000
msg = "Added %i KiB (filesize = %i KiB) of %s data to loose odb in %f s ( %f Write KiB / s)"
@@ -109,7 +110,7 @@ class TestObjDBPerformance(TestBigRepoR):
assert gitsha == bin_to_hex(binsha) # we do it the same way, right ?
# as its the same sha, we reuse our path
- fsize_kib = os.path.getsize(db_file) / 1000
+ fsize_kib = osp.getsize(db_file) / 1000
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(msg, file=sys.stderr)
diff --git a/git/test/test_base.py b/git/test/test_base.py
index 7fc3096f..576df961 100644
--- a/git/test/test_base.py
+++ b/git/test/test_base.py
@@ -9,22 +9,24 @@ import sys
import tempfile
from unittest import skipIf
-import git.objects.base as base
-from git.test.lib import (
- TestBase,
- assert_raises,
- with_rw_repo,
- with_rw_and_rw_remote_repo
-)
from git import (
Blob,
Tree,
Commit,
TagObject
)
+from git.compat import is_win
from git.objects.util import get_object_type_by_name
+from git.test.lib import (
+ TestBase,
+ assert_raises,
+ with_rw_repo,
+ with_rw_and_rw_remote_repo
+)
from gitdb.util import hex_to_bin
-from git.compat import is_win
+
+import git.objects.base as base
+import os.path as osp
class TestBase(TestBase):
@@ -103,19 +105,19 @@ class TestBase(TestBase):
@with_rw_repo('HEAD', bare=True)
def test_with_bare_rw_repo(self, bare_rw_repo):
assert bare_rw_repo.config_reader("repository").getboolean("core", "bare")
- assert os.path.isfile(os.path.join(bare_rw_repo.git_dir, 'HEAD'))
+ assert osp.isfile(osp.join(bare_rw_repo.git_dir, 'HEAD'))
@with_rw_repo('0.1.6')
def test_with_rw_repo(self, rw_repo):
assert not rw_repo.config_reader("repository").getboolean("core", "bare")
- assert os.path.isdir(os.path.join(rw_repo.working_tree_dir, 'lib'))
+ assert osp.isdir(osp.join(rw_repo.working_tree_dir, 'lib'))
#@skipIf(HIDE_WINDOWS_FREEZE_ERRORS, "FIXME: Freezes! sometimes...")
@with_rw_and_rw_remote_repo('0.1.6')
def test_with_rw_remote_and_rw_repo(self, rw_repo, rw_remote_repo):
assert not rw_repo.config_reader("repository").getboolean("core", "bare")
assert rw_remote_repo.config_reader("repository").getboolean("core", "bare")
- assert os.path.isdir(os.path.join(rw_repo.working_tree_dir, 'lib'))
+ assert osp.isdir(osp.join(rw_repo.working_tree_dir, 'lib'))
@skipIf(sys.version_info < (3,) and is_win,
"Unicode woes, see https://github.com/gitpython-developers/GitPython/pull/519")
@@ -123,7 +125,7 @@ class TestBase(TestBase):
def test_add_unicode(self, rw_repo):
filename = u"שלום.txt"
- file_path = os.path.join(rw_repo.working_dir, filename)
+ file_path = osp.join(rw_repo.working_dir, filename)
# verify first that we could encode file name in this environment
try:
diff --git a/git/test/test_commit.py b/git/test/test_commit.py
index fd9777fb..fbb1c244 100644
--- a/git/test/test_commit.py
+++ b/git/test/test_commit.py
@@ -6,34 +6,36 @@
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
from __future__ import print_function
-from git.test.lib import (
- TestBase,
- assert_equal,
- assert_not_equal,
- with_rw_repo,
- fixture_path,
- StringProcessAdapter
-)
+from datetime import datetime
+from io import BytesIO
+import re
+import sys
+import time
+
from git import (
Commit,
Actor,
)
-from gitdb import IStream
-from git.test.lib import with_rw_directory
+from git import Repo
from git.compat import (
string_types,
text_type
)
-from git import Repo
+from git.objects.util import tzoffset, utc
from git.repo.fun import touch
+from git.test.lib import (
+ TestBase,
+ assert_equal,
+ assert_not_equal,
+ with_rw_repo,
+ fixture_path,
+ StringProcessAdapter
+)
+from git.test.lib import with_rw_directory
+from gitdb import IStream
+
+import os.path as osp
-from io import BytesIO
-import time
-import sys
-import re
-import os
-from datetime import datetime
-from git.objects.util import tzoffset, utc
try:
from unittest.mock import Mock
@@ -232,8 +234,8 @@ class TestCommit(TestBase):
@with_rw_directory
def test_ambiguous_arg_iteration(self, rw_dir):
- rw_repo = Repo.init(os.path.join(rw_dir, 'test_ambiguous_arg'))
- path = os.path.join(rw_repo.working_tree_dir, 'master')
+ rw_repo = Repo.init(osp.join(rw_dir, 'test_ambiguous_arg'))
+ path = osp.join(rw_repo.working_tree_dir, 'master')
touch(path)
rw_repo.index.add([path])
rw_repo.index.commit('initial commit')
diff --git a/git/test/test_config.py b/git/test/test_config.py
index 32873f24..0dfadda6 100644
--- a/git/test/test_config.py
+++ b/git/test/test_config.py
@@ -6,7 +6,6 @@
import glob
import io
-import os
from git import (
GitConfigParser
@@ -91,7 +90,7 @@ class TestBase(TestCase):
@with_rw_directory
def test_lock_reentry(self, rw_dir):
- fpl = os.path.join(rw_dir, 'l')
+ fpl = osp.join(rw_dir, 'l')
gcp = GitConfigParser(fpl, read_only=False)
with gcp as cw:
cw.set_value('include', 'some_value', 'a')
@@ -103,7 +102,7 @@ class TestBase(TestCase):
GitConfigParser(fpl, read_only=False)
# but work when the lock is removed
with GitConfigParser(fpl, read_only=False):
- assert os.path.exists(fpl)
+ assert osp.exists(fpl)
# reentering with an existing lock must fail due to exclusive access
with self.assertRaises(IOError):
gcp.__enter__()
@@ -178,17 +177,17 @@ class TestBase(TestCase):
# end
# PREPARE CONFIG FILE A
- fpa = os.path.join(rw_dir, 'a')
+ fpa = osp.join(rw_dir, 'a')
with GitConfigParser(fpa, read_only=False) as cw:
write_test_value(cw, 'a')
- fpb = os.path.join(rw_dir, 'b')
- fpc = os.path.join(rw_dir, 'c')
+ fpb = osp.join(rw_dir, 'b')
+ fpc = osp.join(rw_dir, 'c')
cw.set_value('include', 'relative_path_b', 'b')
cw.set_value('include', 'doesntexist', 'foobar')
cw.set_value('include', 'relative_cycle_a_a', 'a')
cw.set_value('include', 'absolute_cycle_a_a', fpa)
- assert os.path.exists(fpa)
+ assert osp.exists(fpa)
# PREPARE CONFIG FILE B
with GitConfigParser(fpb, read_only=False) as cw:
diff --git a/git/test/test_db.py b/git/test/test_db.py
index 5dcf592a..1741e7b9 100644
--- a/git/test/test_db.py
+++ b/git/test/test_db.py
@@ -3,17 +3,18 @@
#
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
-from git.test.lib import TestBase
from git.db import GitCmdObjectDB
-from gitdb.util import bin_to_hex
from git.exc import BadObject
-import os
+from git.test.lib import TestBase
+from gitdb.util import bin_to_hex
+
+import os.path as osp
class TestDB(TestBase):
def test_base(self):
- gdb = GitCmdObjectDB(os.path.join(self.rorepo.git_dir, 'objects'), self.rorepo.git)
+ gdb = GitCmdObjectDB(osp.join(self.rorepo.git_dir, 'objects'), self.rorepo.git)
# partial to complete - works with everything
hexsha = bin_to_hex(gdb.partial_to_complete_sha_hex("0.1.6"))
diff --git a/git/test/test_diff.py b/git/test/test_diff.py
index d5f5b721..48a5a641 100644
--- a/git/test/test_diff.py
+++ b/git/test/test_diff.py
@@ -4,8 +4,15 @@
#
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
-import os
-
+import ddt
+from git import (
+ Repo,
+ GitCommandError,
+ Diff,
+ DiffIndex,
+ NULL_TREE,
+)
+from git.cmd import Git
from git.test.lib import (
TestBase,
StringProcessAdapter,
@@ -14,18 +21,9 @@ from git.test.lib import (
assert_true,
)
-
from git.test.lib import with_rw_directory
-from git import (
- Repo,
- GitCommandError,
- Diff,
- DiffIndex,
- NULL_TREE,
-)
-import ddt
-from git.cmd import Git
+import os.path as osp
@ddt.ddt
@@ -54,7 +52,7 @@ class TestDiff(TestBase):
def test_diff_with_staged_file(self, rw_dir):
# SETUP INDEX WITH MULTIPLE STAGES
r = Repo.init(rw_dir)
- fp = os.path.join(rw_dir, 'hello.txt')
+ fp = osp.join(rw_dir, 'hello.txt')
with open(fp, 'w') as fs:
fs.write("hello world")
r.git.add(Git.polish_url(fp))
diff --git a/git/test/test_docs.py b/git/test/test_docs.py
index f3c75f79..bb937d93 100644
--- a/git/test/test_docs.py
+++ b/git/test/test_docs.py
@@ -9,6 +9,8 @@ import os
from git.test.lib import TestBase
from git.test.lib.helper import with_rw_directory
+import os.path as osp
+
class Tutorials(TestBase):
@@ -23,7 +25,7 @@ class Tutorials(TestBase):
def test_init_repo_object(self, rw_dir):
# [1-test_init_repo_object]
from git import Repo
- join = os.path.join
+ join = osp.join
# rorepo is a Repo instance pointing to the git-python repository.
# For all you know, the first argument to Repo is a path to the repository
@@ -62,7 +64,7 @@ class Tutorials(TestBase):
# repository paths
# [7-test_init_repo_object]
- assert os.path.isdir(cloned_repo.working_tree_dir) # directory with your work files
+ assert osp.isdir(cloned_repo.working_tree_dir) # directory with your work files
assert cloned_repo.git_dir.startswith(cloned_repo.working_tree_dir) # directory containing the git repository
assert bare_repo.working_tree_dir is None # bare repositories have no working tree
# ![7-test_init_repo_object]
@@ -146,7 +148,7 @@ class Tutorials(TestBase):
self.assertEqual(new_branch.checkout(), cloned_repo.active_branch) # checking out branch adjusts the wtree
self.assertEqual(new_branch.commit, past.commit) # Now the past is checked out
- new_file_path = os.path.join(cloned_repo.working_tree_dir, 'my-new-file')
+ new_file_path = osp.join(cloned_repo.working_tree_dir, 'my-new-file')
open(new_file_path, 'wb').close() # create new file in working tree
cloned_repo.index.add([new_file_path]) # add it to the index
# Commit the changes to deviate masters history
@@ -162,7 +164,7 @@ class Tutorials(TestBase):
# now new_branch is ahead of master, which probably should be checked out and reset softly.
# note that all these operations didn't touch the working tree, as we managed it ourselves.
# This definitely requires you to know what you are doing :) !
- assert os.path.basename(new_file_path) in new_branch.commit.tree # new file is now in tree
+ assert osp.basename(new_file_path) in new_branch.commit.tree # new file is now in tree
master.commit = new_branch.commit # let master point to most recent commit
cloned_repo.head.reference = master # we adjusted just the reference, not the working tree or index
# ![13-test_init_repo_object]
@@ -192,7 +194,7 @@ class Tutorials(TestBase):
def test_references_and_objects(self, rw_dir):
# [1-test_references_and_objects]
import git
- repo = git.Repo.clone_from(self._small_repo_url(), os.path.join(rw_dir, 'repo'), branch='master')
+ repo = git.Repo.clone_from(self._small_repo_url(), osp.join(rw_dir, 'repo'), branch='master')
heads = repo.heads
master = heads.master # lists can be accessed by name for convenience
@@ -264,7 +266,7 @@ class Tutorials(TestBase):
# [11-test_references_and_objects]
hct.blobs[0].data_stream.read() # stream object to read data from
- hct.blobs[0].stream_data(open(os.path.join(rw_dir, 'blob_data'), 'wb')) # write data to given stream
+ hct.blobs[0].stream_data(open(osp.join(rw_dir, 'blob_data'), 'wb')) # write data to given stream
# ![11-test_references_and_objects]
# [12-test_references_and_objects]
@@ -350,11 +352,11 @@ class Tutorials(TestBase):
# Access blob objects
for (path, stage), entry in index.entries.items(): # @UnusedVariable
pass
- new_file_path = os.path.join(repo.working_tree_dir, 'new-file-name')
+ new_file_path = osp.join(repo.working_tree_dir, 'new-file-name')
open(new_file_path, 'w').close()
index.add([new_file_path]) # add a new file to the index
index.remove(['LICENSE']) # remove an existing one
- assert os.path.isfile(os.path.join(repo.working_tree_dir, 'LICENSE')) # working tree is untouched
+ assert osp.isfile(osp.join(repo.working_tree_dir, 'LICENSE')) # working tree is untouched
self.assertEqual(index.commit("my commit message").type, 'commit') # commit changed index
repo.active_branch.commit = repo.commit('HEAD~1') # forget last commit
@@ -373,11 +375,11 @@ class Tutorials(TestBase):
# merge two trees three-way into memory
merge_index = IndexFile.from_tree(repo, 'HEAD~10', 'HEAD', repo.merge_base('HEAD~10', 'HEAD'))
# and persist it
- merge_index.write(os.path.join(rw_dir, 'merged_index'))
+ merge_index.write(osp.join(rw_dir, 'merged_index'))
# ![24-test_references_and_objects]
# [25-test_references_and_objects]
- empty_repo = git.Repo.init(os.path.join(rw_dir, 'empty'))
+ empty_repo = git.Repo.init(osp.join(rw_dir, 'empty'))
origin = empty_repo.create_remote('origin', repo.remotes.origin.url)
assert origin.exists()
assert origin == empty_repo.remotes.origin == empty_repo.remotes['origin']
@@ -480,8 +482,8 @@ class Tutorials(TestBase):
def test_add_file_and_commit(self, rw_dir):
import git
- repo_dir = os.path.join(rw_dir, 'my-new-repo')
- file_name = os.path.join(repo_dir, 'new-file')
+ repo_dir = osp.join(rw_dir, 'my-new-repo')
+ file_name = osp.join(repo_dir, 'new-file')
r = git.Repo.init(repo_dir)
# This function just creates an empty file ...
diff --git a/git/test/test_git.py b/git/test/test_git.py
index bd8ebee2..7d713022 100644
--- a/git/test/test_git.py
+++ b/git/test/test_git.py
@@ -5,9 +5,17 @@
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
import os
-import sys
import subprocess
+import sys
+from git import (
+ Git,
+ GitCommandError,
+ GitCommandNotFound,
+ Repo,
+ cmd
+)
+from git.compat import PY3, is_darwin
from git.test.lib import (
TestBase,
patch,
@@ -17,18 +25,12 @@ from git.test.lib import (
assert_match,
fixture_path
)
-from git import (
- Git,
- GitCommandError,
- GitCommandNotFound,
- Repo,
- cmd
-)
from git.test.lib import with_rw_directory
-
-from git.compat import PY3, is_darwin
from git.util import finalize_process
+import os.path as osp
+
+
try:
from unittest import mock
except ImportError:
@@ -147,7 +149,7 @@ class TestGit(TestBase):
exc = GitCommandNotFound
try:
# set it to something that doens't exist, assure it raises
- type(self.git).GIT_PYTHON_GIT_EXECUTABLE = os.path.join(
+ type(self.git).GIT_PYTHON_GIT_EXECUTABLE = osp.join(
"some", "path", "which", "doesn't", "exist", "gitbinary")
self.failUnlessRaises(exc, self.git.version)
finally:
@@ -198,13 +200,13 @@ class TestGit(TestBase):
self.assertEqual(new_env, {'VARKEY': 'VARVALUE'})
self.assertEqual(self.git.environment(), {})
- path = os.path.join(rw_dir, 'failing-script.sh')
+ path = osp.join(rw_dir, 'failing-script.sh')
with open(path, 'wt') as stream:
stream.write("#!/usr/bin/env sh\n"
"echo FOO\n")
os.chmod(path, 0o777)
- rw_repo = Repo.init(os.path.join(rw_dir, 'repo'))
+ rw_repo = Repo.init(osp.join(rw_dir, 'repo'))
remote = rw_repo.create_remote('ssh-origin', "ssh://git@server/foo")
with rw_repo.git.custom_environment(GIT_SSH=path):
diff --git a/git/test/test_index.py b/git/test/test_index.py
index d851743e..0fdc120c 100644
--- a/git/test/test_index.py
+++ b/git/test/test_index.py
@@ -43,12 +43,14 @@ from git.test.lib import (
fixture,
with_rw_repo
)
-from git.util import HIDE_WINDOWS_KNOWN_ERRORS
from git.test.lib import with_rw_directory
from git.util import Actor, rmtree
+from git.util import HIDE_WINDOWS_KNOWN_ERRORS
from gitdb.base import IStream
from gitdb.util import hex_to_bin
+import os.path as osp
+
class TestIndex(TestBase):
@@ -85,7 +87,7 @@ class TestIndex(TestBase):
def _assert_entries(self, entries):
for entry in entries:
assert isinstance(entry, BaseIndexEntry)
- assert not os.path.isabs(entry.path)
+ assert not osp.isabs(entry.path)
assert "\\" not in entry.path
# END for each entry
@@ -329,7 +331,7 @@ class TestIndex(TestBase):
# reset the working copy as well to current head,to pull 'back' as well
new_data = b"will be reverted"
- file_path = os.path.join(rw_repo.working_tree_dir, "CHANGES")
+ file_path = osp.join(rw_repo.working_tree_dir, "CHANGES")
with open(file_path, "wb") as fp:
fp.write(new_data)
index.reset(rev_head_parent, working_tree=True)
@@ -340,26 +342,26 @@ class TestIndex(TestBase):
assert fp.read() != new_data
# test full checkout
- test_file = os.path.join(rw_repo.working_tree_dir, "CHANGES")
+ test_file = osp.join(rw_repo.working_tree_dir, "CHANGES")
with open(test_file, 'ab') as fd:
fd.write(b"some data")
rval = index.checkout(None, force=True, fprogress=self._fprogress)
assert 'CHANGES' in list(rval)
self._assert_fprogress([None])
- assert os.path.isfile(test_file)
+ assert osp.isfile(test_file)
os.remove(test_file)
rval = index.checkout(None, force=False, fprogress=self._fprogress)
assert 'CHANGES' in list(rval)
self._assert_fprogress([None])
- assert os.path.isfile(test_file)
+ assert osp.isfile(test_file)
# individual file
os.remove(test_file)
rval = index.checkout(test_file, fprogress=self._fprogress)
self.assertEqual(list(rval)[0], 'CHANGES')
self._assert_fprogress([test_file])
- assert os.path.exists(test_file)
+ assert osp.exists(test_file)
# checking out non-existing file throws
self.failUnlessRaises(CheckoutError, index.checkout, "doesnt_exist_ever.txt.that")
@@ -373,7 +375,7 @@ class TestIndex(TestBase):
index.checkout(test_file)
except CheckoutError as e:
self.assertEqual(len(e.failed_files), 1)
- self.assertEqual(e.failed_files[0], os.path.basename(test_file))
+ self.assertEqual(e.failed_files[0], osp.basename(test_file))
self.assertEqual(len(e.failed_files), len(e.failed_reasons))
self.assertIsInstance(e.failed_reasons[0], string_types)
self.assertEqual(len(e.valid_files), 0)
@@ -388,7 +390,7 @@ class TestIndex(TestBase):
assert not open(test_file, 'rb').read().endswith(append_data)
# checkout directory
- rmtree(os.path.join(rw_repo.working_tree_dir, "lib"))
+ rmtree(osp.join(rw_repo.working_tree_dir, "lib"))
rval = index.checkout('lib')
assert len(list(rval)) > 1
@@ -399,7 +401,7 @@ class TestIndex(TestBase):
existing = 0
basedir = repo.working_tree_dir
for f in files:
- existing += os.path.isfile(os.path.join(basedir, f))
+ existing += osp.isfile(osp.join(basedir, f))
# END for each deleted file
return existing
# END num existing helper
@@ -458,7 +460,7 @@ class TestIndex(TestBase):
self.failUnlessRaises(TypeError, index.remove, [1])
# absolute path
- deleted_files = index.remove([os.path.join(rw_repo.working_tree_dir, "lib")], r=True)
+ deleted_files = index.remove([osp.join(rw_repo.working_tree_dir, "lib")], r=True)
assert len(deleted_files) > 1
self.failUnlessRaises(ValueError, index.remove, ["/doesnt/exists"])
@@ -525,9 +527,9 @@ class TestIndex(TestBase):
# re-add all files in lib
# get the lib folder back on disk, but get an index without it
index.reset(new_commit.parents[0], working_tree=True).reset(new_commit, working_tree=False)
- lib_file_path = os.path.join("lib", "git", "__init__.py")
+ lib_file_path = osp.join("lib", "git", "__init__.py")
assert (lib_file_path, 0) not in index.entries
- assert os.path.isfile(os.path.join(rw_repo.working_tree_dir, lib_file_path))
+ assert osp.isfile(osp.join(rw_repo.working_tree_dir, lib_file_path))
# directory
entries = index.add(['lib'], fprogress=self._fprogress_add)
@@ -536,14 +538,14 @@ class TestIndex(TestBase):
assert len(entries) > 1
# glob
- entries = index.reset(new_commit).add([os.path.join('lib', 'git', '*.py')], fprogress=self._fprogress_add)
+ entries = index.reset(new_commit).add([osp.join('lib', 'git', '*.py')], fprogress=self._fprogress_add)
self._assert_entries(entries)
self._assert_fprogress(entries)
self.assertEqual(len(entries), 14)
# same file
entries = index.reset(new_commit).add(
- [os.path.join(rw_repo.working_tree_dir, 'lib', 'git', 'head.py')] * 2, fprogress=self._fprogress_add)
+ [osp.join(rw_repo.working_tree_dir, 'lib', 'git', 'head.py')] * 2, fprogress=self._fprogress_add)
self._assert_entries(entries)
self.assertEqual(entries[0].mode & 0o644, 0o644)
# would fail, test is too primitive to handle this case
@@ -583,7 +585,7 @@ class TestIndex(TestBase):
for target in ('/etc/nonexisting', '/etc/passwd', '/etc'):
basename = "my_real_symlink"
- link_file = os.path.join(rw_repo.working_tree_dir, basename)
+ link_file = osp.join(rw_repo.working_tree_dir, basename)
os.symlink(target, link_file)
entries = index.reset(new_commit).add([link_file], fprogress=self._fprogress_add)
self._assert_entries(entries)
@@ -645,7 +647,7 @@ class TestIndex(TestBase):
# TEST RENAMING
def assert_mv_rval(rval):
for source, dest in rval:
- assert not os.path.exists(source) and os.path.exists(dest)
+ assert not osp.exists(source) and osp.exists(dest)
# END for each renamed item
# END move assertion utility
@@ -661,7 +663,7 @@ class TestIndex(TestBase):
paths = ['LICENSE', 'VERSION', 'doc']
rval = index.move(paths, dry_run=True)
self.assertEqual(len(rval), 2)
- assert os.path.exists(paths[0])
+ assert osp.exists(paths[0])
# again, no dry run
rval = index.move(paths)
@@ -719,8 +721,8 @@ class TestIndex(TestBase):
index.add(files, write=True)
if is_win:
hp = hook_path('pre-commit', index.repo.git_dir)
- hpd = os.path.dirname(hp)
- if not os.path.isdir(hpd):
+ hpd = osp.dirname(hp)
+ if not osp.isdir(hpd):
os.mkdir(hpd)
with open(hp, "wt") as fp:
fp.write("#!/usr/bin/env sh\necho stdout; echo stderr 1>&2; exit 1")
@@ -766,7 +768,7 @@ class TestIndex(TestBase):
for fkey in keys:
assert fkey in index.entries
for absfile in absfiles:
- assert os.path.isfile(absfile)
+ assert osp.isfile(absfile)
@with_rw_repo('HEAD')
def test_compare_write_tree(self, rw_repo):
@@ -815,7 +817,7 @@ class TestIndex(TestBase):
# Adding using a path should still require a non-bare repository.
asserted = False
- path = os.path.join('git', 'test', 'test_index.py')
+ path = osp.join('git', 'test', 'test_index.py')
try:
rw_bare_repo.index.add([path])
except InvalidGitRepositoryError:
@@ -829,7 +831,7 @@ class TestIndex(TestBase):
@with_rw_directory
def test_add_utf8P_path(self, rw_dir):
# NOTE: fp is not a Unicode object in python 2 (which is the source of the problem)
- fp = os.path.join(rw_dir, 'ø.txt')
+ fp = osp.join(rw_dir, 'ø.txt')
with open(fp, 'wb') as fs:
fs.write(u'content of ø'.encode('utf-8'))
@@ -840,7 +842,7 @@ class TestIndex(TestBase):
@with_rw_directory
def test_add_a_file_with_wildcard_chars(self, rw_dir):
# see issue #407
- fp = os.path.join(rw_dir, '[.exe')
+ fp = osp.join(rw_dir, '[.exe')
with open(fp, "wb") as f:
f.write(b'something')
diff --git a/git/test/test_reflog.py b/git/test/test_reflog.py
index dffedf3b..e43a1dc0 100644
--- a/git/test/test_reflog.py
+++ b/git/test/test_reflog.py
@@ -1,17 +1,19 @@
-from git.test.lib import (
- TestBase,
- fixture_path
-)
+import os
+import tempfile
+
from git.objects import IndexObject
from git.refs import (
RefLogEntry,
RefLog
)
+from git.test.lib import (
+ TestBase,
+ fixture_path
+)
from git.util import Actor, rmtree
from gitdb.util import hex_to_bin
-import tempfile
-import os
+import os.path as osp
class TestRefLog(TestBase):
@@ -42,7 +44,7 @@ class TestRefLog(TestBase):
os.mkdir(tdir)
rlp_master_ro = RefLog.path(self.rorepo.head)
- assert os.path.isfile(rlp_master_ro)
+ assert osp.isfile(rlp_master_ro)
# simple read
reflog = RefLog.from_file(rlp_master_ro)
@@ -70,7 +72,7 @@ class TestRefLog(TestBase):
cr = self.rorepo.config_reader()
for rlp in (rlp_head, rlp_master):
reflog = RefLog.from_file(rlp)
- tfile = os.path.join(tdir, os.path.basename(rlp))
+ tfile = osp.join(tdir, osp.basename(rlp))
reflog.to_file(tfile)
assert reflog.write() is reflog
diff --git a/git/test/test_refs.py b/git/test/test_refs.py
index 43f1dcc7..fd0be108 100644
--- a/git/test/test_refs.py
+++ b/git/test/test_refs.py
@@ -4,10 +4,8 @@
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
-from git.test.lib import (
- TestBase,
- with_rw_repo
-)
+from itertools import chain
+
from git import (
Reference,
Head,
@@ -18,11 +16,15 @@ from git import (
GitCommandError,
RefLog
)
-import git.refs as refs
-from git.util import Actor
from git.objects.tag import TagObject
-from itertools import chain
-import os
+from git.test.lib import (
+ TestBase,
+ with_rw_repo
+)
+from git.util import Actor
+
+import git.refs as refs
+import os.path as osp
class TestRefs(TestBase):
@@ -268,10 +270,10 @@ class TestRefs(TestBase):
assert tmp_head == new_head and tmp_head.object == new_head.object
logfile = RefLog.path(tmp_head)
- assert os.path.isfile(logfile)
+ assert osp.isfile(logfile)
Head.delete(rw_repo, tmp_head)
# deletion removes the log as well
- assert not os.path.isfile(logfile)
+ assert not osp.isfile(logfile)
heads = rw_repo.heads
assert tmp_head not in heads and new_head not in heads
# force on deletion testing would be missing here, code looks okay though ;)
@@ -450,12 +452,12 @@ class TestRefs(TestBase):
symbol_ref_path = "refs/symbol_ref"
symref = SymbolicReference(rw_repo, symbol_ref_path)
assert symref.path == symbol_ref_path
- symbol_ref_abspath = os.path.join(rw_repo.git_dir, symref.path)
+ symbol_ref_abspath = osp.join(rw_repo.git_dir, symref.path)
# set it
symref.reference = new_head
assert symref.reference == new_head
- assert os.path.isfile(symbol_ref_abspath)
+ assert osp.isfile(symbol_ref_abspath)
assert symref.commit == new_head.commit
for name in ('absname', 'folder/rela_name'):
@@ -507,7 +509,7 @@ class TestRefs(TestBase):
rw_repo.head.reference = Head.create(rw_repo, "master")
# At least the head should still exist
- assert os.path.isfile(os.path.join(rw_repo.git_dir, 'HEAD'))
+ assert osp.isfile(osp.join(rw_repo.git_dir, 'HEAD'))
refs = list(SymbolicReference.iter_items(rw_repo))
assert len(refs) == 1
diff --git a/git/test/test_repo.py b/git/test/test_repo.py
index 314201ea..4b21db4b 100644
--- a/git/test/test_repo.py
+++ b/git/test/test_repo.py
@@ -203,8 +203,8 @@ class TestRepo(TestBase):
prev_cwd = os.getcwd()
os.chdir(tempfile.gettempdir())
git_dir_rela = "repos/foo/bar.git"
- del_dir_abs = os.path.abspath("repos")
- git_dir_abs = os.path.abspath(git_dir_rela)
+ del_dir_abs = osp.abspath("repos")
+ git_dir_abs = osp.abspath(git_dir_rela)
try:
# with specific path
for path in (git_dir_rela, git_dir_abs):
@@ -212,7 +212,7 @@ class TestRepo(TestBase):
self.assertIsInstance(r, Repo)
assert r.bare is True
assert not r.has_separate_working_tree()
- assert os.path.isdir(r.git_dir)
+ assert osp.isdir(r.git_dir)
self._assert_empty_repo(r)
@@ -306,16 +306,16 @@ class TestRepo(TestBase):
def test_is_dirty_with_path(self, rwrepo):
assert rwrepo.is_dirty(path="git") is False
- with open(os.path.join(rwrepo.working_dir, "git", "util.py"), "at") as f:
+ with open(osp.join(rwrepo.working_dir, "git", "util.py"), "at") as f:
f.write("junk")
assert rwrepo.is_dirty(path="git") is True
assert rwrepo.is_dirty(path="doc") is False
- rwrepo.git.add(os.path.join("git", "util.py"))
+ rwrepo.git.add(osp.join("git", "util.py"))
assert rwrepo.is_dirty(index=False, path="git") is False
assert rwrepo.is_dirty(path="git") is True
- with open(os.path.join(rwrepo.working_dir, "doc", "no-such-file.txt"), "wt") as f:
+ with open(osp.join(rwrepo.working_dir, "doc", "no-such-file.txt"), "wt") as f:
f.write("junk")
assert rwrepo.is_dirty(path="doc") is False
assert rwrepo.is_dirty(untracked_files=True, path="doc") is True
@@ -494,10 +494,10 @@ class TestRepo(TestBase):
ph = os.environ.get('HOME')
try:
os.environ['HOME'] = rw_dir
- Repo.init(os.path.join('~', 'test.git'), bare=True)
+ Repo.init(osp.join('~', 'test.git'), bare=True)
os.environ['FOO'] = rw_dir
- Repo.init(os.path.join('$FOO', 'test.git'), bare=True)
+ Repo.init(osp.join('$FOO', 'test.git'), bare=True)
finally:
if ph:
os.environ['HOME'] = ph
@@ -785,7 +785,7 @@ class TestRepo(TestBase):
@with_rw_repo('HEAD')
def test_git_file(self, rwrepo):
# Move the .git directory to another location and create the .git file.
- real_path_abs = os.path.abspath(join_path_native(rwrepo.working_tree_dir, '.real'))
+ real_path_abs = osp.abspath(join_path_native(rwrepo.working_tree_dir, '.real'))
os.rename(rwrepo.git_dir, real_path_abs)
git_file_path = join_path_native(rwrepo.working_tree_dir, '.git')
with open(git_file_path, 'wb') as fp:
@@ -793,13 +793,13 @@ class TestRepo(TestBase):
# Create a repo and make sure it's pointing to the relocated .git directory.
git_file_repo = Repo(rwrepo.working_tree_dir)
- self.assertEqual(os.path.abspath(git_file_repo.git_dir), real_path_abs)
+ self.assertEqual(osp.abspath(git_file_repo.git_dir), real_path_abs)
# Test using an absolute gitdir path in the .git file.
with open(git_file_path, 'wb') as fp:
fp.write(('gitdir: %s\n' % real_path_abs).encode('ascii'))
git_file_repo = Repo(rwrepo.working_tree_dir)
- self.assertEqual(os.path.abspath(git_file_repo.git_dir), real_path_abs)
+ self.assertEqual(osp.abspath(git_file_repo.git_dir), real_path_abs)
@skipIf(HIDE_WINDOWS_KNOWN_ERRORS and PY3,
"FIXME: smmp fails with: TypeError: Can't convert 'bytes' object to str implicitly")
@@ -840,7 +840,7 @@ class TestRepo(TestBase):
# It's expected to not be able to access a tree
self.failUnlessRaises(ValueError, r.tree)
- new_file_path = os.path.join(rw_dir, "new_file.ext")
+ new_file_path = osp.join(rw_dir, "new_file.ext")
touch(new_file_path)
r.index.add([new_file_path])
r.index.commit("initial commit\nBAD MESSAGE 1\n")
diff --git a/git/test/test_tree.py b/git/test/test_tree.py
index f36c4337..f9259874 100644
--- a/git/test/test_tree.py
+++ b/git/test/test_tree.py
@@ -5,7 +5,6 @@
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
from io import BytesIO
-import os
import sys
from unittest.case import skipIf
@@ -13,8 +12,10 @@ from git import (
Tree,
Blob
)
-from git.util import HIDE_WINDOWS_KNOWN_ERRORS
from git.test.lib import TestBase
+from git.util import HIDE_WINDOWS_KNOWN_ERRORS
+
+import os.path as osp
class TestTree(TestBase):
@@ -90,12 +91,12 @@ class TestTree(TestBase):
assert len(set(b for b in root if isinstance(b, Blob)) | set(root.blobs)) == len(root.blobs)
subitem = trees[0][0]
assert "/" in subitem.path
- assert subitem.name == os.path.basename(subitem.path)
+ assert subitem.name == osp.basename(subitem.path)
# assure that at some point the traversed paths have a slash in them
found_slash = False
for item in root.traverse():
- assert os.path.isabs(item.abspath)
+ assert osp.isabs(item.abspath)
if '/' in item.path:
found_slash = True
# END check for slash