Ejemplo n.º 1
0
 def test_start_line(self):
     position = ((1, 2), (3, 4))
     self.builder.start_line(position)
     self.assertEqual(len(self.builder.lines), 1)
     self.assertListEqual(self.builder.lines,
                          [builders.LineBox([], position)])
     self.builder.start_line(position)
     self.assertEqual(len(self.builder.lines), 1)
     self.assertListEqual(self.builder.lines,
                          [builders.LineBox([], position)])
Ejemplo n.º 2
0
 def setUp(self):
     box1 = builders.Box("word1", ((15, 22), (23, 30)))
     box2 = builders.Box("word2", ((25, 23), (30, 32)))
     box3 = builders.Box("word3", ((32, 25), (40, 32)), 95)
     box4 = builders.Box("word4", ((41, 18), (44, 33)), 98)
     box_unicode = builders.Box("\xe9", ((1, 2), (3, 4)), 98)
     self.line1 = builders.LineBox([box1, box2, box3, box4],
                                   ((14, 15), (45, 33)))
     self.line1_bis = builders.LineBox([box1, box2], ((14, 15), (45, 33)))
     self.line2 = builders.LineBox([box3, box4], ((30, 5), (53, 20)))
     self.line1_dupl = builders.LineBox([box1, box2, box3, box4],
                                        ((14, 15), (45, 33)))
     self.line_unicode = builders.LineBox([box1, box_unicode],
                                          ((1, 2), (3, 4)))
Ejemplo n.º 3
0
 def test_write_file(self):
     output_fh = StringIO()
     lines = []
     for l in range(4):
         boxes = []
         for b in range(4):
             word = "word" + str(4 * l + b)
             position = ((4 * l + b, 4 * l + b + 1), (4 * l + b + 2,
                                                      4 * l + b + 3))
             boxes.append(builders.Box(word, position, randint(0, 100)))
         line_position = ((4 * l, 4 * (l + 1)), (4 * l + 2,
                                                 4 * (l + 1) + 2))
         lines.append(builders.LineBox(boxes, line_position))
     self.builder.write_file(output_fh, lines)
     output_fh.seek(0)
     output = output_fh.read()
     for line in lines:
         for box in line.word_boxes:
             self.assertIn(box.content, output)
             self.assertIn(
                 "{} {} {} {}".format(
                     box.position[0][0],
                     box.position[0][1],
                     box.position[1][0],
                     box.position[1][1],
                 ), output)
             self.assertIn(str(box.confidence), output)
Ejemplo n.º 4
0
    def test_get_output(self):
        lines = []
        for l in range(4):
            boxes = []
            for b in range(4):
                word = "word" + str(4 * l + b)
                position = ((4 * l + b, 0), (0, 0))
                boxes.append(builders.Box(word, position, randint(0, 100)))
            line_position = ((4 * l, 4 * (l + 1)), (4 * l + 2,
                                                    4 * (l + 1) + 2))
            lines.append(builders.LineBox(boxes, line_position))

        for line in lines:
            self.builder.start_line(line.position)
            for word in line.word_boxes:
                self.builder.add_word(word.content, word.position,
                                      word.confidence)
            self.builder.end_line()  # could be useful in future
        output = self.builder.get_output()
        for line, line_expected in zip(output, lines):
            self.assertIsInstance(line, builders.LineBox)
            self.assertEqual(line, line_expected)