def test_score_text2(self): """Tests score_text weights phrases correctly""" #import pdb; pdb.set_trace() test = sentiment.LibraryRun(self.text3, self.lib) matches = test.find_phrase_matches(self.tokens_generator3)[0] obj_ut, _ = test.score_text(matches, end_threshold=0.5) self.assertEqual(obj_ut, -1.25)
def test_make_results_verbose1(self): """Tests that make_results_verbose() correctly creates results""" test = sentiment.LibraryRun(self.text3, self.lib) test.do_run() test.make_results_verbose() obj_ut = test.results_verbose self.assertEqual(obj_ut, [['100', 'not good', 2, -1, 0], ['100', 'not very good', 4, -1, 0]])
def test_find_phrase_matches3(self): """Tests find_phrase_matches finds negation phrases correctly""" test = sentiment.LibraryRun(self.text3, self.lib) obj_ut = test.find_phrase_matches(self.tokens_generator3)[0] self.assertEqual(dict(obj_ut), { 'not good': [[2, -1, 0]], 'not very good': [[4, -1, 0]] })
def test_get_results_simple(self): """Tests that get_results() makes simple results correctly""" test = sentiment.LibraryRun(self.text3, self.lib) test.do_run() obj_ut = test.get_results() self.assertEqual(obj_ut, [ '.text id\t.text score\tneg hits\t\ pos hits\ttotal hits\ttotal wordcount\n', '100\t-1\t2\t0\t2\t7\n' ])
def test_score_text4(self): """Tests that score_text creates matches_weighted correctly when weights are applied""" test = sentiment.LibraryRun(self.text3, self.lib) matches = test.find_phrase_matches(self.tokens_generator3)[0] _, obj_ut = test.score_text(matches, end_threshold=0.5) self.assertEqual(obj_ut, { 'not good': [[2, -1, 0]], 'not very good': [[4, -1.5, 0]] })
def test_make_results_simple(self): """Tests that make_results_simple() correctly creates results""" test = sentiment.LibraryRun(self.text3, self.lib) test.do_run() test.make_results_simple() obj_ut = test.results_simple self.assertEqual( obj_ut, { '.text id': '100', '.text score': -1, 'total wordcount': 7, 'total hits': 2, 'pos hits': 0, 'neg hits': 2 })
def test_score_text1(self): """Tests score_text scores text correctly""" test = sentiment.LibraryRun(self.text3, self.lib) matches = test.find_phrase_matches(self.tokens_generator3)[0] obj_ut, _ = test.score_text(matches) self.assertEqual(obj_ut, -1)
def test_find_phrase_matches2(self): """Tests find_phrase_matches finds multiple matches of same phrase correctly""" test = sentiment.LibraryRun(self.text2, self.lib) obj_ut = test.find_phrase_matches(self.tokens_generator2)[0] self.assertEqual(dict(obj_ut), {'not good': [[2, -1, 0], [4, -1, 0]]})
def test_find_phrase_matches1(self): """Tests find_phrase_matches finds correct matches in text using negation library and normal library""" test = sentiment.LibraryRun(self.text1, self.lib) obj_ut = test.find_phrase_matches(self.tokens_generator1)[0] self.assertEqual(dict(obj_ut), {'not good': [[2, -1, 0]]})
def test_instantiate_library_run2(self): """Tests that LibraryRun class correctly creates word count""" obj_ut = sentiment.LibraryRun(self.text3, self.lib) self.assertEqual(obj_ut.wordcount, 7)
def test_instantiate_library_run1(self): """Tests that LibraryRun class instantiates""" obj_ut = sentiment.LibraryRun(self.text1, self.lib) self.assertIsInstance(obj_ut, sentiment.LibraryRun)