| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 01f0988 commit cdf7ffc
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,7 @@ | |||
| 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 | + import copy | ||
| 7 | 8 | from datetime import datetime | |
| 8 | 9 | from io import BytesIO | |
| 9 | 10 | import re | |
@@ -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 | + def test_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 | + for msg in msgs: | ||
| 448 | + commit = self.rorepo.commit('master') | ||
| 449 | + commit = copy.copy(commit) | ||
| 450 | + commit.message = msg | ||
| 451 | + assert KEY_1 in commit.trailers.keys() | ||
| 452 | + assert KEY_2 in commit.trailers.keys() | ||
| 453 | + assert commit.trailers[KEY_1] == VALUE_1 | ||
| 454 | + assert commit.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 | + for msg in msgs: | ||
| 466 | + commit = self.rorepo.commit('master') | ||
| 467 | + commit = copy.copy(commit) | ||
| 468 | + commit.message = msg | ||
| 469 | + assert len(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 | + assert KEY_1 not in commit.trailers.keys() | ||
| 476 | + assert KEY_2 in commit.trailers.keys() | ||
| 477 | + assert commit.trailers[KEY_2] == VALUE_2 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments