| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent df5095c commit 31ad0a0
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -130,7 +130,8 @@ def __init__(self, repo, binsha, tree=None, author=None, authored_date=None, aut | |||
| 130 | 130 | self.parents = parents | |
| 131 | 131 | if encoding is not None: | |
| 132 | 132 | self.encoding = encoding | |
| 133 | - self.gpgsig = gpgsig | ||
| 133 | + if gpgsig is not None: | ||
| 134 | + self.gpgsig = gpgsig | ||
| 134 | 135 | ||
| 135 | 136 | @classmethod | |
| 136 | 137 | def _get_intermediate_items(cls, commit): | |
@@ -425,10 +426,13 @@ def _serialize(self, stream): | |||
| 425 | 426 | if self.encoding != self.default_encoding: | |
| 426 | 427 | write(("encoding %s\n" % self.encoding).encode('ascii')) | |
| 427 | 428 | ||
| 428 | - if self.gpgsig: | ||
| 429 | - write(b"gpgsig") | ||
| 430 | - for sigline in self.gpgsig.rstrip("\n").split("\n"): | ||
| 431 | - write((" " + sigline + "\n").encode('ascii')) | ||
| 429 | + try: | ||
| 430 | + if self.__getattribute__('gpgsig') is not None: | ||
| 431 | + write(b"gpgsig") | ||
| 432 | + for sigline in self.gpgsig.rstrip("\n").split("\n"): | ||
| 433 | + write((" " + sigline + "\n").encode('ascii')) | ||
| 434 | + except AttributeError: | ||
| 435 | + pass | ||
| 432 | 436 | ||
| 433 | 437 | write(b"\n") | |
| 434 | 438 | ||
@@ -473,6 +477,7 @@ def _deserialize(self, stream): | |||
| 473 | 477 | # now we can have the encoding line, or an empty line followed by the optional | |
| 474 | 478 | # message. | |
| 475 | 479 | self.encoding = self.default_encoding | |
| 480 | + self.gpgsig = None | ||
| 476 | 481 | ||
| 477 | 482 | # read headers | |
| 478 | 483 | enc = next_line | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,6 +34,7 @@ | |||
| 34 | 34 | import os | |
| 35 | 35 | from datetime import datetime | |
| 36 | 36 | from git.objects.util import tzoffset, utc | |
| 37 | + from mock import Mock | ||
| 37 | 38 | ||
| 38 | 39 | ||
| 39 | 40 | def assert_commit_serialization(rwrepo, commit_id, print_performance_info=False): | |
@@ -342,7 +343,9 @@ def test_gpgsig(self): | |||
| 342 | 343 | cstream = BytesIO() | |
| 343 | 344 | cmt._serialize(cstream) | |
| 344 | 345 | assert re.search(r"^gpgsig <test\n dummy\n sig>$", cstream.getvalue().decode('ascii'), re.MULTILINE) | |
| 345 | - | ||
| 346 | + | ||
| 347 | + self.assert_gpgsig_deserialization(cstream) | ||
| 348 | + | ||
| 346 | 349 | cstream.seek(0) | |
| 347 | 350 | cmt.gpgsig = None | |
| 348 | 351 | cmt._deserialize(cstream) | |
@@ -352,6 +355,31 @@ def test_gpgsig(self): | |||
| 352 | 355 | cstream = BytesIO() | |
| 353 | 356 | cmt._serialize(cstream) | |
| 354 | 357 | assert not re.search(r"^gpgsig ", cstream.getvalue().decode('ascii'), re.MULTILINE) | |
| 358 | + | ||
| 359 | + def assert_gpgsig_deserialization(self, cstream): | ||
| 360 | + assert 'gpgsig' in 'precondition: need gpgsig' | ||
| 361 | + | ||
| 362 | + class RepoMock: | ||
| 363 | + def __init__(self, bytestr): | ||
| 364 | + self.bytestr = bytestr | ||
| 365 | + | ||
| 366 | + @property | ||
| 367 | + def odb(self): | ||
| 368 | + class ODBMock: | ||
| 369 | + def __init__(self, bytestr): | ||
| 370 | + self.bytestr = bytestr | ||
| 371 | + | ||
| 372 | + def stream(self, *args): | ||
| 373 | + stream = Mock(spec_set=['read'], return_value=self.bytestr) | ||
| 374 | + stream.read.return_value = self.bytestr | ||
| 375 | + return ('binsha', 'typename', 'size', stream) | ||
| 376 | + | ||
| 377 | + return ODBMock(self.bytestr) | ||
| 378 | + | ||
| 379 | + repo_mock = RepoMock(cstream.getvalue()) | ||
| 380 | + for field in Commit.__slots__: | ||
| 381 | + c = Commit(repo_mock, b'x' * 20) | ||
| 382 | + assert getattr(c, field) is not None | ||
| 355 | 383 | ||
| 356 | 384 | def test_datetimes(self): | |
| 357 | 385 | commit = self.rorepo.commit('4251bd5') | |
| Back | FazBrowse Home | New Git URL |
0 commit comments