Merge branch 'main' into allowlist-thresholds

This commit is contained in:
Justin Warren 2023-02-12 16:11:00 +11:00
commit 1e377099f0
No known key found for this signature in database
2 changed files with 74 additions and 2 deletions

View File

@ -307,10 +307,14 @@ def merge_comments(oldcomment:str, newcomment:str) -> str:
if oldcomment in ['', None] and newcomment in ['', None]:
return ''
# If both comments are the same, don't merge
if oldcomment == newcomment:
# If both comments are the same, or new comment is empty, don't merge
if oldcomment == newcomment or newcomment in ['', None]:
return oldcomment
# If old comment is empty, just return the new one
if oldcomment in ['', None]:
return newcomment
# We want to skip duplicate fragments so we don't end up
# re-concatenating the same strings every time there's an
# update, causing the comment to grow without bound.

View File

@ -0,0 +1,68 @@
""" Test merging of comments
"""
import pytest
from fediblockhole import merge_comments
def test_merge_blank_comments():
oldcomment = ''
newcomment = ''
merged_comment = merge_comments(oldcomment, newcomment)
assert merged_comment == ''
def test_merge_None_comments():
oldcomment = None
newcomment = None
merged_comment = merge_comments(oldcomment, newcomment)
assert merged_comment == ''
def test_merge_oldstr_newNone():
oldcomment = 'fred, bibble'
newcomment = None
merged_comment = merge_comments(oldcomment, newcomment)
assert merged_comment == 'fred, bibble'
def test_merge_oldempty_newcomment():
oldcomment = ''
newcomment = 'fred, bibble'
merged_comment = merge_comments(oldcomment, newcomment)
assert merged_comment == 'fred, bibble'
def test_merge_oldNone_newcomment():
oldcomment = None
newcomment = 'fred, bibble'
merged_comment = merge_comments(oldcomment, newcomment)
assert merged_comment == 'fred, bibble'
def test_merge_two_different():
oldcomment = 'happy, medium, spinning'
newcomment = 'fred, bibble'
merged_comment = merge_comments(oldcomment, newcomment)
assert merged_comment == 'happy, medium, spinning, fred, bibble'
def test_merge_overlaps():
oldcomment = 'happy, medium, spinning'
newcomment = 'fred, medium, bibble, spinning'
merged_comment = merge_comments(oldcomment, newcomment)
assert merged_comment == 'happy, medium, spinning, fred, bibble'