How to use the scrubadub.exceptions.FilthMergeError function in scrubadub

To help you get started, we’ve selected a few scrubadub examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github datascopeanalytics / scrubadub / tests / test_filth.py View on Github external
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)
github datascopeanalytics / scrubadub / tests / test_filth.py View on Github external
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)
github datascopeanalytics / scrubadub / scrubadub / filth / base.py View on Github external
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