예제 #1
0
 def test_line_exceeds_width_and_height_multiple(self):
     """Should return an errors indicating which lines are too big."""
     base_image = Images._create_blank_image(50, 100, 'white')
     text = ['This text is too big', 'and so is this']
     settings = {'text_label_font_name': 'arialbd.ttf',
                 'text_label_font_size': 64,
                 'text_label_font_color': 'red'}
     font_kwargs = ImageSettings._get_font_kwargs(
         settings=settings, label_or_hint='label')
     image_log = logging.getLogger('odk_tools.question_images.images')
     with self.assertLogs(logger=image_log, level="WARN") as logs:
         Images._draw_text(
             base_image=base_image, pixels_from_top=0, pixels_before=10,
             pixels_between=5, **font_kwargs, text=text, image_name="img")
     expected = 3
     self.assertEqual(expected, len(logs.output))
예제 #2
0
 def test_line_exceeds_height(self):
     """Should return an error indicating the line that was too tall."""
     base_image = Images._create_blank_image(200, 100, 'white')
     text = ['Big', 'Text']
     settings = {'text_label_font_name': 'arialbd.ttf',
                 'text_label_font_size': 64,
                 'text_label_font_color': 'red'}
     font_kwargs = ImageSettings._get_font_kwargs(
         settings=settings, label_or_hint='label')
     image_log = logging.getLogger('odk_tools.question_images.images')
     with self.assertLogs(logger=image_log, level="WARN") as logs:
         Images._draw_text(
             base_image=base_image, pixels_from_top=0, pixels_before=10,
             pixels_between=5, **font_kwargs, text=text, image_name="img")
     expected = "WARNING:odk_tools.question_images.images:" \
                "Text outside image margins. image name (img)," \
                " dim (height), pos (59), text ({0})".format(text[1])
     self.assertEqual(expected, logs.output[0])
예제 #3
0
 def test_line_exceeds_width_and_height(self):
     """Should return an errors indicating the line is too wide and tall."""
     base_image = Images._create_blank_image(50, 50, 'white')
     text = ['This is too big']
     settings = {'text_label_font_name': 'arialbd.ttf',
                 'text_label_font_size': 64,
                 'text_label_font_color': 'red'}
     font_kwargs = ImageSettings._get_font_kwargs(
         settings=settings, label_or_hint='label')
     image_log = logging.getLogger('odk_tools.question_images.images')
     with self.assertLogs(logger=image_log, level="WARN") as logs:
         Images._draw_text(
             base_image=base_image, pixels_from_top=0, pixels_before=10,
             pixels_between=5, **font_kwargs, text=text, image_name="img")
     self.assertEqual(2, len(logs.output))
     expected_width = "dim (width), pos (436), text ({0})".format(text[0])
     self.assertTrue(logs.output[0].endswith(expected_width))
     expected_height = "dim (height), pos (72), text ({0})".format(text[0])
     self.assertTrue(logs.output[1].endswith(expected_height))
예제 #4
0
 def test_ideal_input(self):
     """Should return a modified image with expected offset and no errors."""
     settings = ImageSettings.read(xlsform_workbook=self.xlsform1_workbook)
     settings = settings[2]
     base_image = Images._create_blank_image(
         settings['image_width'], settings['image_height'],
         settings['image_color'])
     original_image = base_image.copy()
     text = ['This is some text', 'that is for a question']
     font_kwargs = ImageSettings._get_font_kwargs(
         settings=settings, label_or_hint='label')
     with patch('logging.Logger.warn', MagicMock()) as log_warn:
         drawn_image, vertical = Images._draw_text(
             base_image=base_image, pixels_from_top=0, pixels_before=10,
             pixels_between=5, **font_kwargs, text=text, image_name='img')
     self.assertFalse(log_warn.called)
     self.assertNotEqual(list(original_image.getdata()),
                         list(drawn_image.getdata()))
     self.assertEqual(79, vertical)