|
4 | 4 | #
|
5 | 5 | # This module is part of GitPython and is released under
|
6 | 6 | # the BSD License: http://www.opensource.org/licenses/bsd-license.php
|
| 7 | +importcopy |
7 | 8 | fromdatetimeimportdatetime
|
8 | 9 | fromioimportBytesIO
|
9 | 10 | importre
|
@@ -429,3 +430,48 @@ def test_datetimes(self):
|
429 | 430 | datetime(2009,10,8,20,22,51,tzinfo=tzoffset(-7200)))
|
430 | 431 | self.assertEqual(commit.committed_datetime,
|
431 | 432 | datetime(2009,10,8,18,22,51,tzinfo=utc),commit.committed_datetime)
|
| 433 | + |
| 434 | +deftest_trailers(self): |
| 435 | +KEY_1="Hello" |
| 436 | +VALUE_1="World" |
| 437 | +KEY_2="Key" |
| 438 | +VALUE_2="Value" |
| 439 | + |
| 440 | +# Check if KEY 1 & 2 with Value 1 & 2 is extracted from multiple msg variations |
| 441 | +msgs= [] |
| 442 | +msgs.append(f"Subject\n\n{KEY_1}:{VALUE_1}\n{KEY_2}:{VALUE_2}\n") |
| 443 | +msgs.append(f"Subject\n\nSome body of a function\n\n{KEY_1}:{VALUE_1}\n{KEY_2}:{VALUE_2}\n") |
| 444 | +msgs.append(f"Subject\n\nSome body of a function\n\nnon-key: non-value\n\n{KEY_1}:{VALUE_1}\n{KEY_2}:{VALUE_2}\n") |
| 445 | +msgs.append(f"Subject\n\nSome multiline\n body of a function\n\nnon-key: non-value\n\n{KEY_1}:{VALUE_1}\n{KEY_2}:{VALUE_2}\n") |
| 446 | + |
| 447 | +formsginmsgs: |
| 448 | +commit=self.rorepo.commit('master') |
| 449 | +commit=copy.copy(commit) |
| 450 | +commit.message=msg |
| 451 | +assertKEY_1incommit.trailers.keys() |
| 452 | +assertKEY_2incommit.trailers.keys() |
| 453 | +assertcommit.trailers[KEY_1]==VALUE_1 |
| 454 | +assertcommit.trailers[KEY_2]==VALUE_2 |
| 455 | + |
| 456 | +# Check that trailer stays empty for multiple msg combinations |
| 457 | +msgs= [] |
| 458 | +msgs.append(f"Subject\n") |
| 459 | +msgs.append(f"Subject\n\nBody with some\nText\n") |
| 460 | +msgs.append(f"Subject\n\nBody with\nText\n\nContinuation but\n doesn't contain colon\n") |
| 461 | +msgs.append(f"Subject\n\nBody with\nText\n\nContinuation but\n only contains one :\n") |
| 462 | +msgs.append(f"Subject\n\nBody with\nText\n\nKey: Value\nLine without colon\n") |
| 463 | +msgs.append(f"Subject\n\nBody with\nText\n\nLine without colon\nKey: Value\n") |
| 464 | + |
| 465 | +formsginmsgs: |
| 466 | +commit=self.rorepo.commit('master') |
| 467 | +commit=copy.copy(commit) |
| 468 | +commit.message=msg |
| 469 | +assertlen(commit.trailers.keys())==0 |
| 470 | + |
| 471 | +# check that only the last key value paragraph is evaluated |
| 472 | +commit=self.rorepo.commit('master') |
| 473 | +commit=copy.copy(commit) |
| 474 | +commit.message=f"Subject\n\nMultiline\nBody\n\n{KEY_1}:{VALUE_1}\n\n{KEY_2}:{VALUE_2}\n" |
| 475 | +assertKEY_1notincommit.trailers.keys() |
| 476 | +assertKEY_2incommit.trailers.keys() |
| 477 | +assertcommit.trailers[KEY_2]==VALUE_2 |