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))
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('.')
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('.'))
def setUp(self): self.object = Filters.UsernameFilter()
def setUp(self): self.object = Filters.URLFilter()
def test_happy_path_number(self): self.obj = Filters.PunctuationFilter() test = 5 self.assertTrue(self.obj.run(test))
def test_happy_path_num_string(self): self.obj = Filters.PunctuationFilter() test = '5' self.assertTrue(self.obj.run(test))
def test_happy_path_punctuation(self): self.obj = Filters.PunctuationFilter() for i in list(string.punctuation): with self.assertRaises(ExcludedString): self.obj.run(i)
def test_happy_path_num_string(self): self.obj = Filters.NumeralFilter() test = '5' self.assertFalse(self.obj.run(test))
def test_happy_path_is_string(self): self.obj = Filters.NumeralFilter() test = 'taco' self.assertRaises() self.assertTrue(self.obj.run(test))
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]))
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]
def setUp(self): self.object = Filters.StopwordFilter() self.stopwords = english_stops
def setUp(self): self.object = Filters.NumeralFilter()
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))
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])