Skip to content

Commit 914bbdd

Browse files
markrowsoftByron
authored andcommitted
Update test_docs.py
Using "import as" is normally a time saver but for usability of the documentation, please consider removing osp and join with fully qualified calls for better snippet readability.
1 parent 4f99fb4 commit 914bbdd

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

git/test/test_docs.py

+17-17
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from git.test.lib import TestBase
1010
from git.test.lib.helper import with_rw_directory
1111

12-
import os.path as osp
12+
import os.path
1313

1414

1515
class Tutorials(TestBase):
@@ -25,7 +25,7 @@ def tearDown(self):
2525
def test_init_repo_object(self, rw_dir):
2626
# [1-test_init_repo_object]
2727
from git import Repo
28-
join = osp.join
28+
2929

3030
# rorepo is a Repo instance pointing to the git-python repository.
3131
# For all you know, the first argument to Repo is a path to the repository
@@ -35,7 +35,7 @@ def test_init_repo_object(self, rw_dir):
3535
# ![1-test_init_repo_object]
3636

3737
# [2-test_init_repo_object]
38-
bare_repo = Repo.init(join(rw_dir, 'bare-repo'), bare=True)
38+
bare_repo = Repo.init(os.path.join(rw_dir, 'bare-repo'), bare=True)
3939
assert bare_repo.bare
4040
# ![2-test_init_repo_object]
4141

@@ -52,19 +52,19 @@ def test_init_repo_object(self, rw_dir):
5252
# ![4-test_init_repo_object]
5353

5454
# [5-test_init_repo_object]
55-
cloned_repo = repo.clone(join(rw_dir, 'to/this/path'))
55+
cloned_repo = repo.clone(os.path.join(rw_dir, 'to/this/path'))
5656
assert cloned_repo.__class__ is Repo # clone an existing repository
57-
assert Repo.init(join(rw_dir, 'path/for/new/repo')).__class__ is Repo
57+
assert Repo.init(os.path.join(rw_dir, 'path/for/new/repo')).__class__ is Repo
5858
# ![5-test_init_repo_object]
5959

6060
# [6-test_init_repo_object]
61-
with open(join(rw_dir, 'repo.tar'), 'wb') as fp:
61+
with open(os.path.join(rw_dir, 'repo.tar'), 'wb') as fp:
6262
repo.archive(fp)
6363
# ![6-test_init_repo_object]
6464

6565
# repository paths
6666
# [7-test_init_repo_object]
67-
assert osp.isdir(cloned_repo.working_tree_dir) # directory with your work files
67+
assert os.path.isdir(cloned_repo.working_tree_dir) # directory with your work files
6868
assert cloned_repo.git_dir.startswith(cloned_repo.working_tree_dir) # directory containing the git repository
6969
assert bare_repo.working_tree_dir is None # bare repositories have no working tree
7070
# ![7-test_init_repo_object]
@@ -148,7 +148,7 @@ def update(self, op_code, cur_count, max_count=None, message=''):
148148
self.assertEqual(new_branch.checkout(), cloned_repo.active_branch) # checking out branch adjusts the wtree
149149
self.assertEqual(new_branch.commit, past.commit) # Now the past is checked out
150150

151-
new_file_path = osp.join(cloned_repo.working_tree_dir, 'my-new-file')
151+
new_file_path = os.path.join(cloned_repo.working_tree_dir, 'my-new-file')
152152
open(new_file_path, 'wb').close() # create new file in working tree
153153
cloned_repo.index.add([new_file_path]) # add it to the index
154154
# Commit the changes to deviate masters history
@@ -164,7 +164,7 @@ def update(self, op_code, cur_count, max_count=None, message=''):
164164
# now new_branch is ahead of master, which probably should be checked out and reset softly.
165165
# note that all these operations didn't touch the working tree, as we managed it ourselves.
166166
# This definitely requires you to know what you are doing :) !
167-
assert osp.basename(new_file_path) in new_branch.commit.tree # new file is now in tree
167+
assert os.path.basename(new_file_path) in new_branch.commit.tree # new file is now in tree
168168
master.commit = new_branch.commit # let master point to most recent commit
169169
cloned_repo.head.reference = master # we adjusted just the reference, not the working tree or index
170170
# ![13-test_init_repo_object]
@@ -194,7 +194,7 @@ def update(self, op_code, cur_count, max_count=None, message=''):
194194
def test_references_and_objects(self, rw_dir):
195195
# [1-test_references_and_objects]
196196
import git
197-
repo = git.Repo.clone_from(self._small_repo_url(), osp.join(rw_dir, 'repo'), branch='master')
197+
repo = git.Repo.clone_from(self._small_repo_url(), os.path.join(rw_dir, 'repo'), branch='master')
198198

199199
heads = repo.heads
200200
master = heads.master # lists can be accessed by name for convenience
@@ -266,7 +266,7 @@ def test_references_and_objects(self, rw_dir):
266266

267267
# [11-test_references_and_objects]
268268
hct.blobs[0].data_stream.read() # stream object to read data from
269-
hct.blobs[0].stream_data(open(osp.join(rw_dir, 'blob_data'), 'wb')) # write data to given stream
269+
hct.blobs[0].stream_data(open(os.path.join(rw_dir, 'blob_data'), 'wb')) # write data to given stream
270270
# ![11-test_references_and_objects]
271271

272272
# [12-test_references_and_objects]
@@ -352,11 +352,11 @@ def test_references_and_objects(self, rw_dir):
352352
# Access blob objects
353353
for (path, stage), entry in index.entries.items(): # @UnusedVariable
354354
pass
355-
new_file_path = osp.join(repo.working_tree_dir, 'new-file-name')
355+
new_file_path = os.path.join(repo.working_tree_dir, 'new-file-name')
356356
open(new_file_path, 'w').close()
357357
index.add([new_file_path]) # add a new file to the index
358358
index.remove(['LICENSE']) # remove an existing one
359-
assert osp.isfile(osp.join(repo.working_tree_dir, 'LICENSE')) # working tree is untouched
359+
assert os.path.isfile(os.path.join(repo.working_tree_dir, 'LICENSE')) # working tree is untouched
360360

361361
self.assertEqual(index.commit("my commit message").type, 'commit') # commit changed index
362362
repo.active_branch.commit = repo.commit('HEAD~1') # forget last commit
@@ -375,11 +375,11 @@ def test_references_and_objects(self, rw_dir):
375375
# merge two trees three-way into memory
376376
merge_index = IndexFile.from_tree(repo, 'HEAD~10', 'HEAD', repo.merge_base('HEAD~10', 'HEAD'))
377377
# and persist it
378-
merge_index.write(osp.join(rw_dir, 'merged_index'))
378+
merge_index.write(os.path.join(rw_dir, 'merged_index'))
379379
# ![24-test_references_and_objects]
380380

381381
# [25-test_references_and_objects]
382-
empty_repo = git.Repo.init(osp.join(rw_dir, 'empty'))
382+
empty_repo = git.Repo.init(os.path.join(rw_dir, 'empty'))
383383
origin = empty_repo.create_remote('origin', repo.remotes.origin.url)
384384
assert origin.exists()
385385
assert origin == empty_repo.remotes.origin == empty_repo.remotes['origin']
@@ -482,8 +482,8 @@ def test_submodules(self):
482482
def test_add_file_and_commit(self, rw_dir):
483483
import git
484484

485-
repo_dir = osp.join(rw_dir, 'my-new-repo')
486-
file_name = osp.join(repo_dir, 'new-file')
485+
repo_dir = os.path.join(rw_dir, 'my-new-repo')
486+
file_name = os.path.join(repo_dir, 'new-file')
487487

488488
r = git.Repo.init(repo_dir)
489489
# This function just creates an empty file ...

0 commit comments

Comments
 (0)