def test_whole_line(self): # Дурацкие вообще context = Context( [Position(0, 43, 49), Position(0, 67, 75)], TEST3, 0, 81) result = context.cut_and_highlight() ideal = 'Я не люблю красные бобы, белые бобы и бобы <b>вообще</b>. Противные бобы. <b>Дурацкие</b> бобы.' self.assertEqual(result, ideal)
def test_search_to_sentence_2(self): query = "Я Дурацкие" result = self.se.search_to_sentence(query, 0) ideal = { 'test3.txt': [ Context([Position(0, 0, 1)], TEST3, 0, 50), Context([Position(0, 67, 75)], TEST3, 67, 81) ] } self.assertEqual(result, ideal)
def test_many_words(self): #бобы context = Context([ Position(0, 19, 23), Position(0, 31, 35), Position(0, 38, 42), Position(0, 61, 65), Position(0, 76, 80) ], TEST3, 0, 81) result = context.cut_and_highlight() ideal = "Я не люблю красные <b>бобы</b>, белые <b>бобы</b> и <b>бобы</b> вообще. Противные <b>бобы</b>. Дурацкие <b>бобы</b>." self.assertEqual(result, ideal)
def test_middle_of_sentence(self): # бобы +1 context = Context( [Position(0, 19, 23), Position(0, 31, 35), Position(0, 38, 42)], TEST3, 11, 49) context.to_sentence() ideal = Context( [Position(0, 19, 23), Position(0, 31, 35), Position(0, 38, 42)], TEST3, 0, 50) self.assertEqual(context, ideal)
def test_search_to_context(self): result = self.se.search_to_context("to test") ideal = { 'test.txt': [ Context([Position(0, 10, 14)], TEST[:19], 0, 19), Context( [Position(1, 6, 8), Position(1, 9, 13)], TEST[20:], 0, 27) ], 'test1.txt': [ Context([Position(0, 13, 15), Position(0, 16, 20)], TEST1, 0, 38) ] } self.assertEqual(result, ideal)
def test_two_words_intersection(self): result = self.se.get_context_windows(self.search_result3, 2) ideal = { 'test.txt': [ Context([Position(0, 10, 14)], TEST[0:19], 5, 19), Context( [Position(1, 6, 8), Position(1, 9, 13)], TEST[20:], 0, 27) ], 'test1.txt': [ Context([Position(0, 13, 15), Position(0, 16, 20)], TEST1, 0, 31) ] } self.assertEqual(result, ideal)
def test_join_two_contexts(self): # вообще Дурацкие input_dict = { 'test3.txt': [ Context([Position(0, 43, 49)], TEST3, 0, 66), Context([Position(0, 67, 75)], TEST3, 51, 81) ] } ideal = { 'test3.txt': [ Context([Position(0, 43, 49), Position(0, 67, 75)], TEST3, 0, 81) ] } result = self.se.join_contexts(input_dict) self.assertEqual(result, ideal)
def test_search_to_sentence(self): query = "Дурацкие вообще" result = self.se.search_to_sentence(query) ideal = { 'test3.txt': [ Context([Position(0, 43, 49), Position(0, 67, 75)], TEST3, 0, 81) ] } self.assertEqual(result, ideal)
def test_join(self): a = Context([Position(0, 13, 15)], TEST1, 0, 24) b = Context([Position(0, 16, 20)], TEST1, 0, 31) a.join(b) self.assertEqual( a, Context( [Position(0, 13, 15), Position(0, 16, 20)], TEST1, 0, 31))
def test_beginning_of_the_line(self): # Я +2 context = Context([Position(0, 0, 1)], TEST3, 0, 10) context.to_sentence() ideal = Context([Position(0, 0, 1)], TEST3, 0, 50) self.assertEqual(context, ideal)
def test_end_of_sentence(self): #(Дурацкие) бобы +0 context = Context([Position(0, 76, 80)], TEST3, 76, 80) context.to_sentence() ideal = Context([Position(0, 76, 80)], TEST3, 67, 81) self.assertEqual(context, ideal)
def test_beginning_of_sentence(self): # Противные +0 context = Context([Position(0, 51, 60)], TEST3, 51, 60) context.to_sentence() ideal = Context([Position(0, 51, 60)], TEST3, 51, 66) self.assertEqual(context, ideal)
def test_last_line(self): result = Context.from_file("test.txt", Position(1, 14, 20), 2) self.assertEqual(result.positions, [Position(1, 14, 20)]) self.assertEqual(result.start, 6) self.assertEqual(result.end, 27) self.assertEqual(result.line, "it is to test search engine")
def test_zero_context(self): result = Context.from_file("test1.txt", Position(0, 8, 12), 0) self.assertEqual(result.positions, [Position(0, 8, 12)]) self.assertEqual(result.start, 8) self.assertEqual(result.end, 12) self.assertEqual(result.line, TEST1)
def test_short_context(self): # engine +1 context = Context([Position(0, 32, 38)], TEST1, 25, 38) result = context.cut_and_highlight() self.assertEqual(result, 'search <b>engine</b>')
def test_word_in_the_end(self): result = Context.from_file("test1.txt", Position(0, 32, 38), 3) self.assertEqual(result.positions, [Position(0, 32, 38)]) self.assertEqual(result.start, 16) self.assertEqual(result.end, 38) self.assertEqual(result.line, TEST1)
def test_first_line(self): result = Context.from_file("test.txt", Position(0, 8, 9), 0) self.assertEqual(result.positions, [Position(0, 8, 9)]) self.assertEqual(result.start, 8) self.assertEqual(result.end, 9) self.assertEqual(result.line, "this is a test text")
def test_end_of_the_line(self): # engine +1 context = Context([Position(0, 32, 38)], TEST1, 25, 38) context.to_sentence() ideal = Context([Position(0, 32, 38)], TEST1, 0, 38)
def test_eq(self): a = Context([Position(0, 8, 9)], TEST[0:19], 8, 9) b = Context([Position(0, 8, 9)], TEST[0:19], 8, 9) self.assertEqual(a, b)
def test_wrong_line_number(self): with self.assertRaises(ValueError): Context.from_file("test.txt", Position(7, 8, 9), 2)
def test_zero_context(self): result = self.se.get_context_windows(self.search_result1, 0) ideal = {'test.txt': [Context([Position(0, 8, 9)], TEST[0:19], 8, 9)]} self.assertEqual(result, ideal)
def test_part_of_line(self): #Я context = Context([Position(0, 0, 1)], TEST3, 0, 50) result = context.cut_and_highlight() ideal = '<b>Я</b> не люблю красные бобы, белые бобы и бобы вообще.' self.assertEqual(result, ideal)
def test_output_type(self): result = Context.from_file("test1.txt", Position(0, 8, 12), 3) self.assertIsInstance(result, Context)
def test_word_in_the_middle(self): result = Context.from_file("test1.txt", Position(0, 16, 20), 2) self.assertEqual(result.positions, [Position(0, 16, 20)]) self.assertEqual(result.start, 8) self.assertEqual(result.end, 31) self.assertEqual(result.line, TEST1)
def test_join_inclusion_sets(self): a = Context([Position(0, 13, 15)], TEST1, 0, 24) b = Context([Position(0, 13, 15)], TEST1, 3, 20) a.join(b) self.assertEqual(a, Context([Position(0, 13, 15)], TEST1, 0, 24))
def test_join_equal_windoows(self): a = Context([Position(0, 13, 15)], TEST1, 0, 24) b = Context([Position(0, 13, 15)], TEST1, 0, 24) a.join(b) self.assertEqual(a, Context([Position(0, 13, 15)], TEST1, 0, 24))
def test_word_in_the_beginning(self): result = Context.from_file("test1.txt", Position(0, 8, 12), 3) self.assertEqual(result.positions, [Position(0, 8, 12)]) self.assertEqual(result.start, 0) self.assertEqual(result.end, 24) self.assertEqual(result.line, TEST1)
def test_isintersected_equal_sets(self): a = Context([Position(0, 13, 15)], TEST1, 0, 24) b = Context([Position(0, 13, 15)], TEST1, 0, 24) self.assertTrue(a.isintersected(b))
def test_wrong_input_error(self): with self.assertRaises(ValueError): Context.from_file(42, 42, 42)