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

Commit54c99cb

Browse files
committed
Return bytes from Contents.decoded for empty files
According to the docs, Contents.decoded should return bytes. However, in thecase of empty files, it currently returns str. Make it return bytes also forempty files.
1 parentf642a27 commit54c99cb

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

‎src/github3/repos/contents.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def _update_attributes(self, content):
8585
self.content=content.get("content")
8686
self.encoding=content.get("encoding")
8787
self.decoded=self.content
88-
ifself.encoding=="base64"andself.content:
88+
ifself.encoding=="base64"andself.contentisnotNone:
8989
self.decoded=b64decode(self.content.encode())
9090
self.download_url=content["download_url"]
9191
self.git_url=content["git_url"]

‎tests/unit/test_repos_repo.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,30 @@ def test_file_contents(self):
582582
url_for("contents/path/to/file.txt"),params={"ref":"some-sha"}
583583
)
584584

585+
deftest_file_contents_works_for_empty_file(self):
586+
"""Verify file_contents works for an empty file edge case."""
587+
mock_response=unittest.mock.MagicMock(status_code=200)
588+
mock_response.json.return_value= {
589+
"content":"",
590+
"download_url":"",
591+
"encoding":"base64",
592+
"git_url":"",
593+
"html_url":"",
594+
"name":"",
595+
"path":"",
596+
"sha":"",
597+
"size":"",
598+
"type":"",
599+
"url":"",
600+
"_links":"",
601+
}
602+
self.session.get.return_value=mock_response
603+
604+
file_contents=self.instance.file_contents(
605+
"path/to/empty_file.txt",ref="some-sha"
606+
)
607+
assertfile_contents.decoded==b""
608+
585609
deftest_git_commit_required_sha(self):
586610
"""Verify the request for retrieving a git commit from a repository."""
587611
self.instance.git_commit("")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp