Пример #1
0
 def test_problematic_patterns(self):
     self.obj._modifiers = [
         Modifiers.CaseConverter(),
         Modifiers.RegexpReplacer()
     ]
     self.obj._filters = [
         Filters.NumeralFilter(),
         Filters.PunctuationFilter()
     ]
     # patterns which had problems in testing of program
     problem_strings = ['..']
     for ps in problem_strings:
         self.assertEqual(None, self.obj.process(ps))
Пример #2
0
    def test_happy_run_filters(self):
        test = self.faker.word()
        nf = Filters.NumeralFilter()
        print(type(nf))
        self.assertTrue(isinstance(nf, Filters.IFilter))
        self.obj.add_filters(nf)
        self.obj.add_filters(Filters.PunctuationFilter())

        self.assertTrue(len(self.obj._filters) is 2)

        self.assertEqual(True, self.obj._run_filters(test))
        with self.assertRaises(ExcludedString):
            self.obj._run_filters('5')

        with self.assertRaises(ExcludedString):
            self.obj._run_filters('.')
Пример #3
0
 def test_happy_process(self):
     self.obj._modifiers = [
         Modifiers.CaseConverter(),
         Modifiers.RegexpReplacer()
     ]
     self.obj._filters = [
         Filters.NumeralFilter(),
         Filters.PunctuationFilter()
     ]
     # should make lowercase and replace contraction
     self.assertEqual('taco', self.obj.process('Taco'))
     self.assertEqual("will not", self.obj.process("WON'T"))
     # with self.assertRaises(ExcludedString):
     self.assertEqual(None, self.obj.process(43))
     # with self.assertRaises(ExcludedString):
     self.assertEqual(None, self.obj.process('.'))
Пример #4
0
 def test_happy_path_num_string(self):
     self.obj = Filters.NumeralFilter()
     test = '5'
     self.assertFalse(self.obj.run(test))
Пример #5
0
    def test_happy_path_is_string(self):
        self.obj = Filters.NumeralFilter()
        test = 'taco'
        self.assertRaises()

        self.assertTrue(self.obj.run(test))
Пример #6
0
 def setUp(self):
     self.object = Filters.NumeralFilter()
Пример #7
0
 def test_expected_inheritance(self):
     obj = Filters.NumeralFilter()
     print(type(obj))
     # self.assertTrue(inspect.isclass(obj))
     # self.assertTrue(issubclass(obj, Filters.IFilter))
     self.assertTrue(isinstance(obj, Filters.IFilter))
Пример #8
0
import unittest

from TextProcessingTools.TextTools.Filtration import Filters
from TextProcessingTools.TextTools.Replacement import Modifiers
from TextProcessingTools.StatisticalTools import Counters as C

filters = [
    Filters.UsernameFilter(),
    Filters.PunctuationFilter(),
    Filters.URLFilter(),
    Filters.NumeralFilter()
]

modifiers = [Modifiers.WierdBPrefixConverter(), Modifiers.CaseConverter()]


class SelectedCounterTests(unittest.TestCase):
    def setUp(self):
        self.obj = C.SelectedWordCounter()
        self.obj.add_filters(filters)
        self.obj.add_modifiers(modifiers)

    def test_process_count(self):
        test = "My cat eats food of cat"
        self.obj.set_words_to_count(['my', 'cat', 'eats'])
        expected = {'my': 1, 'cat': 2, 'eats': 1}
        self.obj.process(test)

        # check
        for k in expected.keys():
            self.assertEqual(self.obj.counts[k], expected[k])