Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit914bbdd

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 parent4f99fb4 commit914bbdd

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

‎git/test/test_docs.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
fromgit.test.libimportTestBase
1010
fromgit.test.lib.helperimportwith_rw_directory
1111

12-
importos.pathasosp
12+
importos.path
1313

1414

1515
classTutorials(TestBase):
@@ -25,7 +25,7 @@ def tearDown(self):
2525
deftest_init_repo_object(self,rw_dir):
2626
# [1-test_init_repo_object]
2727
fromgitimportRepo
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
assertbare_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
assertcloned_repo.__class__isRepo# clone an existing repository
57-
assertRepo.init(join(rw_dir,'path/for/new/repo')).__class__isRepo
57+
assertRepo.init(os.path.join(rw_dir,'path/for/new/repo')).__class__isRepo
5858
# ![5-test_init_repo_object]
5959

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

6565
# repository paths
6666
# [7-test_init_repo_object]
67-
assertosp.isdir(cloned_repo.working_tree_dir)# directory with your work files
67+
assertos.path.isdir(cloned_repo.working_tree_dir)# directory with your work files
6868
assertcloned_repo.git_dir.startswith(cloned_repo.working_tree_dir)# directory containing the git repository
6969
assertbare_repo.working_tree_dirisNone# 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-
assertosp.basename(new_file_path)innew_branch.commit.tree# new file is now in tree
167+
assertos.path.basename(new_file_path)innew_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
deftest_references_and_objects(self,rw_dir):
195195
# [1-test_references_and_objects]
196196
importgit
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),entryinindex.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-
assertosp.isfile(osp.join(repo.working_tree_dir,'LICENSE'))# working tree is untouched
359+
assertos.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
assertorigin.exists()
385385
assertorigin==empty_repo.remotes.origin==empty_repo.remotes['origin']
@@ -482,8 +482,8 @@ def test_submodules(self):
482482
deftest_add_file_and_commit(self,rw_dir):
483483
importgit
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)

[8]ページ先頭

©2009-2025 Movatter.jp