Ejemplo n.º 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))
Ejemplo n.º 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('.')
Ejemplo n.º 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('.'))
Ejemplo n.º 4
0
 def setUp(self):
     self.object = Filters.UsernameFilter()
Ejemplo n.º 5
0
 def setUp(self):
     self.object = Filters.URLFilter()
Ejemplo n.º 6
0
 def test_happy_path_number(self):
     self.obj = Filters.PunctuationFilter()
     test = 5
     self.assertTrue(self.obj.run(test))
Ejemplo n.º 7
0
 def test_happy_path_num_string(self):
     self.obj = Filters.PunctuationFilter()
     test = '5'
     self.assertTrue(self.obj.run(test))
Ejemplo n.º 8
0
 def test_happy_path_punctuation(self):
     self.obj = Filters.PunctuationFilter()
     for i in list(string.punctuation):
         with self.assertRaises(ExcludedString):
             self.obj.run(i)
Ejemplo n.º 9
0
 def test_happy_path_num_string(self):
     self.obj = Filters.NumeralFilter()
     test = '5'
     self.assertFalse(self.obj.run(test))
Ejemplo n.º 10
0
    def test_happy_path_is_string(self):
        self.obj = Filters.NumeralFilter()
        test = 'taco'
        self.assertRaises()

        self.assertTrue(self.obj.run(test))
Ejemplo n.º 11
0
 def test_add_to_ignorelist_string(self):
     self.obj = Filters.IgnoreListFilter()
     test = 'taco'
     self.obj.add_to_ignorelist(test)
     self.assertIsInstance(self.obj._ignore, tuple)
     self.assertEqual(self.obj._ignore, tuple([test]))
Ejemplo n.º 12
0
 def test_add_to_ignorelist_list(self):
     self.obj = Filters.IgnoreListFilter()
     test = ['taco', 'cat', 'fish']
     self.obj.add_to_ignorelist(test)
     self.assertIsInstance(self.obj._ignore, tuple)
     [self.assertIn(w, self.obj._ignore) for w in test]
Ejemplo n.º 13
0
 def setUp(self):
     self.object = Filters.StopwordFilter()
     self.stopwords = english_stops
Ejemplo n.º 14
0
 def setUp(self):
     self.object = Filters.NumeralFilter()
Ejemplo n.º 15
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))
Ejemplo n.º 16
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])