def test_string_image_tries_provided_font_path(self, m_truetype): some_string = 'asdf' some_font = 'somefont' try: _polygrid_module._string_image(some_string, font_path=some_font) except Exception: pass # ignore fallout m_truetype_args = m_truetype.call_args[0] self.assertIn(some_font, m_truetype_args)
def test_string_image_uses_bundled_font_when_none_provided(self, m_tt): some_string = 'asdf' bundled_font_name = 'NotoSansCJK-Bold.ttc' try: _polygrid_module._string_image(some_string) except Exception: pass # ignore fallout due to mock object blowing up later m_truetype_args = m_tt.call_args[0] m_truetype_arg = m_truetype_args[0] self.assertIn(bundled_font_name, m_truetype_arg)
def test_string_image_is_about_double_height_with_newline(self): # get a string image without newline char = 'a' image_without_newline = _polygrid_module._string_image(char) # get a string image with 1 literal newline char_with_newline = char + '\\n' + char image_with_newline = _polygrid_module._string_image(char_with_newline) # confirm height is about double h_single_line = image_without_newline.size[1] h_min_spec = 2 * h_single_line h_max_spec = 3.5 * h_single_line # since cropped, generous upper bound h_double = image_with_newline.size[1] self.assertTrue(h_min_spec <= h_double <= h_max_spec, 'Height of text with newline was unexpectedly not about' ' double the height of a single line.\nExpected' ' between {} and {} but got {}' ''.format(h_min_spec, h_max_spec, h_double))
def test_string_image_is_about_double_height_with_newline(self): # get a string image without newline char = 'a' image_without_newline = _polygrid_module._string_image(char) # get a string image with 1 literal newline char_with_newline = char + '\\n' + char image_with_newline = _polygrid_module._string_image(char_with_newline) # confirm height is about double h_single_line = image_without_newline.size[1] h_min_spec = 2 * h_single_line h_max_spec = 3.5 * h_single_line # since cropped, generous upper bound h_double = image_with_newline.size[1] self.assertTrue( h_min_spec <= h_double <= h_max_spec, 'Height of text with newline was unexpectedly not about' ' double the height of a single line.\nExpected' ' between {} and {} but got {}' ''.format(h_min_spec, h_max_spec, h_double))
def test_string_image_returns_a_PIL_image(self): some_string = 'asdf' image = _polygrid_module._string_image(some_string) self.assertTrue(hasattr(image, 'resize'))