summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Kempter <peter.kempter@rohde-schwarz.com>2021-09-29 12:08:30 +0200
committerSebastian Thiel <sebastian.thiel@icloud.com>2022-01-07 09:54:53 +0800
commitcdf7ffc33fa05ba5afcb915a374c140c7658c839 (patch)
tree863244a0d4da91ee39e85572abdb5062adbb9203
parent01f09888208341876d1480bd22dc8f4107c100f1 (diff)
downloadgitpython-cdf7ffc33fa05ba5afcb915a374c140c7658c839.tar.gz
Add failing unit test
-rw-r--r--test/test_commit.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/test_commit.py b/test/test_commit.py
index 67dc7d73..5aeef2e6 100644
--- a/test/test_commit.py
+++ b/test/test_commit.py
@@ -4,6 +4,7 @@
#
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
+import copy
from datetime import datetime
from io import BytesIO
import re
@@ -429,3 +430,48 @@ JzJMZDRLQLFvnzqZuCjE
datetime(2009, 10, 8, 20, 22, 51, tzinfo=tzoffset(-7200)))
self.assertEqual(commit.committed_datetime,
datetime(2009, 10, 8, 18, 22, 51, tzinfo=utc), commit.committed_datetime)
+
+ def test_trailers(self):
+ KEY_1 = "Hello"
+ VALUE_1 = "World"
+ KEY_2 = "Key"
+ VALUE_2 = "Value"
+
+ # Check if KEY 1 & 2 with Value 1 & 2 is extracted from multiple msg variations
+ msgs = []
+ msgs.append(f"Subject\n\n{KEY_1}: {VALUE_1}\n{KEY_2}: {VALUE_2}\n")
+ msgs.append(f"Subject\n \nSome body of a function\n \n{KEY_1}: {VALUE_1}\n{KEY_2}: {VALUE_2}\n")
+ 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")
+ 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")
+
+ for msg in msgs:
+ commit = self.rorepo.commit('master')
+ commit = copy.copy(commit)
+ commit.message = msg
+ assert KEY_1 in commit.trailers.keys()
+ assert KEY_2 in commit.trailers.keys()
+ assert commit.trailers[KEY_1] == VALUE_1
+ assert commit.trailers[KEY_2] == VALUE_2
+
+ # Check that trailer stays empty for multiple msg combinations
+ msgs = []
+ msgs.append(f"Subject\n")
+ msgs.append(f"Subject\n\nBody with some\nText\n")
+ msgs.append(f"Subject\n\nBody with\nText\n\nContinuation but\n doesn't contain colon\n")
+ msgs.append(f"Subject\n\nBody with\nText\n\nContinuation but\n only contains one :\n")
+ msgs.append(f"Subject\n\nBody with\nText\n\nKey: Value\nLine without colon\n")
+ msgs.append(f"Subject\n\nBody with\nText\n\nLine without colon\nKey: Value\n")
+
+ for msg in msgs:
+ commit = self.rorepo.commit('master')
+ commit = copy.copy(commit)
+ commit.message = msg
+ assert len(commit.trailers.keys()) == 0
+
+ # check that only the last key value paragraph is evaluated
+ commit = self.rorepo.commit('master')
+ commit = copy.copy(commit)
+ commit.message = f"Subject\n\nMultiline\nBody\n\n{KEY_1}: {VALUE_1}\n\n{KEY_2}: {VALUE_2}\n"
+ assert KEY_1 not in commit.trailers.keys()
+ assert KEY_2 in commit.trailers.keys()
+ assert commit.trailers[KEY_2] == VALUE_2