Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_nonoverlapping_filth(self):
"""can't merge non-overlapping filth"""
a_filth = Filth(beg=0, end=3, text="the")
b_filth = Filth(beg=4, end=7, text="end")
with self.assertRaises(FilthMergeError):
a_filth.merge(b_filth)
with self.assertRaises(FilthMergeError):
b_filth.merge(a_filth)
def test_nonoverlapping_filth(self):
"""can't merge non-overlapping filth"""
a_filth = Filth(beg=0, end=3, text="the")
b_filth = Filth(beg=4, end=7, text="end")
with self.assertRaises(FilthMergeError):
a_filth.merge(b_filth)
with self.assertRaises(FilthMergeError):
b_filth.merge(a_filth)
def _update_content(self, other_filth):
"""this updates the bounds, text and placeholder for the merged
filth
"""
if self.end < other_filth.beg or other_filth.end < self.beg:
raise exceptions.FilthMergeError(
"a_filth goes from [%s, %s) and b_filth goes from [%s, %s)" % (
self.beg, self.end, other_filth.beg, other_filth.end
))
# get the text over lap correct
if self.beg < other_filth.beg:
first = self
second = other_filth
else:
second = self
first = other_filth
end_offset = second.end - first.end
if end_offset > 0:
self.text = first.text + second.text[-end_offset:]
# update the beg/end strings