def test_wrap_text_empty(self): font = create_traitsfont("Courier") font_metrics = QtGui.QFontMetrics(font) average_char_width = font_metrics.averageCharWidth() line_spacing = font_metrics.lineSpacing() width = 500 * average_char_width height = 100 * line_spacing lines = wrap_text_with_elision("", font, width, height) self.assertEqual(lines, [])
def test_wrap_text_basic(self): font = create_traitsfont("Courier") font_metrics = QtGui.QFontMetrics(font) average_char_width = font_metrics.averageCharWidth() line_spacing = font_metrics.lineSpacing() width = 500 * average_char_width height = 100 * line_spacing lines = wrap_text_with_elision(lorem_ipsum, font, width, height) self.assertEqual(lines, [line.rstrip() for line in lorem_ipsum.splitlines()])
def test_wrap_text_narrow(self): font = create_traitsfont("Courier") font_metrics = QtGui.QFontMetrics(font) average_char_width = font_metrics.averageCharWidth() line_spacing = font_metrics.lineSpacing() width = 20 * average_char_width height = 100 * line_spacing lines = wrap_text_with_elision(lorem_ipsum, font, width, height) # add one char slack as depends on OS, exact font, etc. self.assertTrue(all(len(line) <= 21 for line in lines))
def test_wrap_text_short(self): font = create_traitsfont("Courier") font_metrics = QtGui.QFontMetrics(font) average_char_width = font_metrics.averageCharWidth() line_spacing = font_metrics.lineSpacing() width = 500 * average_char_width height = 3 * line_spacing lines = wrap_text_with_elision(lorem_ipsum, font, width, height) expected_lines = get_expected_lines(lorem_ipsum, 500)[:3] self.assertEqual(lines, expected_lines)
def test_wrap_text_narrow_short(self): font = create_traitsfont("Courier") font_metrics = QtGui.QFontMetrics(font) average_char_width = font_metrics.averageCharWidth() line_spacing = font_metrics.lineSpacing() width = 20 * average_char_width height = 20 * line_spacing lines = wrap_text_with_elision(lorem_ipsum, font, width, height) # add one char slack as depends on OS, exact font, etc. self.assertTrue(all(len(line) <= 21 for line in lines)) # different os elide the last line slightly differently, # just check last character shows elision. self.assertEqual(lines[19][-1], '\u2026')
def test_wrap_text_narrow_short(self): font = create_traitsfont("Courier") font_metrics = QtGui.QFontMetrics(font) average_char_width = font_metrics.averageCharWidth() line_spacing = font_metrics.lineSpacing() width = 20 * average_char_width height = 20 * line_spacing lines = wrap_text_with_elision(lorem_ipsum, font, width, height) # add one char slack as depends on OS, exact font, etc. self.assertTrue(all(len(line) <= 21 for line in lines)) # different os elide the last line slightly differently, # just check end of last line shows elision. # In most systems elision is marked with ellipsis # but it has been reported as "..." on NetBSD. if lines[19][-1] == ".": self.assertEqual(lines[19][-3:], "...") else: self.assertEqual(lines[19][-1], "\u2026")