import sys
import unittest

from scrubadub.filth import NameFilth
from base import BaseTestCase


class SpacyExpandPersonTitleTestCase(unittest.TestCase, BaseTestCase):
    """
    Tests whether the detector is performing correctly from a function point of view.
    For accuracy tests use .benchmark_accuracy instead
    """

    def setUp(self):
        unsupported_spacy_version = False
        try:
            from scrubadub.detectors.spacy_name_title import SpacyNameTitleDetector
            SpacyNameTitleDetector.check_spacy_version()
        except (ImportError, NameError):
            unsupported_spacy_version = True

        unsupported_python_version = (
                ((sys.version_info.major, sys.version_info.minor) < (3, 6)) or
                ((sys.version_info.major, sys.version_info.minor) >= (3, 9))
        )
        print("HERE")
        if unsupported_python_version:
            print("SKIPPED")
            self.skipTest(
                "Spacy detector supported for 3.6 <= python version < 3.9"
            )
        elif unsupported_spacy_version:
            self.skipTest(
                "Need spacy version >= 3"
            )
        else:
            from scrubadub.detectors.spacy_name_title import SpacyNameTitleDetector
            self.detector = SpacyNameTitleDetector(model='en_core_web_sm')

    def _assert_filth_type_and_pos(self, doc_list, beg_end_list, filth_class):
        doc_names = [str(x) for x in range(len(doc_list))]

        filth_list = list(self.detector.iter_filth_documents(document_list=doc_list, document_names=doc_names))
        for filth, beg_end in zip(filth_list, beg_end_list):
            self.assertIsInstance(filth, filth_class)
            self.assertEqual((filth.beg, filth.end), beg_end)

    def test_expand_names(self):
        doc_list = ["Mr Nadhim Zahawi said the measures would help our economy.",
                    "The name is Mrs Nasrin Muhib.",
                    "Can you please ask Mr lan Chase?",
                    "Please see Dr Alex Smith in room 1."]
        beg_end_list = [(0, 16),
                        (12, 28),
                        (19, 31),
                        (11, 24)]
        self._assert_filth_type_and_pos(doc_list, beg_end_list, NameFilth)

import sys
import unittest

from scrubadub.filth import NameFilth
from base import BaseTestCase


class SpacyExpandPersonTitleTestCase(unittest.TestCase, BaseTestCase):
    """
    Tests whether the detector is performing correctly from a function point of view.
    For accuracy tests use .benchmark_accuracy instead
    """

    def setUp(self):
        unsupported_spacy_version = False
        try:
            from scrubadub.detectors.spacy_name_title import SpacyNameTitleDetector
            SpacyNameTitleDetector.check_spacy_version()
        except (ImportError, NameError):
            unsupported_spacy_version = True

        unsupported_python_version = (
                ((sys.version_info.major, sys.version_info.minor) < (3, 6)) or
                ((sys.version_info.major, sys.version_info.minor) >= (3, 9))
        )
        if unsupported_python_version:
            print("SKIPPED")
            self.skipTest(
                "Spacy detector supported for 3.6 <= python version < 3.9"
            )
        elif unsupported_spacy_version:
            self.skipTest(
                "Need spacy version >= 3"
            )
        else:
            from scrubadub.detectors.spacy_name_title import SpacyNameTitleDetector
            self.detector = SpacyNameTitleDetector()

    def test_expand_names(self):
        doc_list = [
            "Mr Jake Doe said the measures would help our economy.",
            "The name is Mrs Nasrin Muhib.",
            "Can you please ask Mr lan Chase?",
            "Please see Dr Alex Smith in room 1."
        ]
        beg_end_list = [
            (0, 11),
            (12, 28),
            (19, 31),
            (11, 24)
        ]
        for doc, beg_end in zip(doc_list, beg_end_list):
            filth_list = list(self.detector.iter_filth(doc))
            print(filth_list)
            self.assertLessEqual(1, len(filth_list), doc)
            self.assertIsInstance(filth_list[0], NameFilth, doc)
            self.assertEqual((filth_list[0].beg, filth_list[0].end), beg_end, doc)

fix tests to prevent sorting breking the results and rm print statement