mirror of
https://github.com/yusufipk/dikte.git
synced 2026-09-11 10:56:10 +00:00
Count the lines off the font, not off this machine's font
The new test pinned the wrapped height at four lines, which is four lines on a Linux runner and four and a half on a Windows one, where the same sentence in the same 400 pixels needs 54 of the box's 48. What the test is actually about is that the height comes from the width the label has now rather than the eight pixels it had while the window was being built, so it measures that width itself and compares against the answer.
This commit is contained in:
+12
-5
@@ -14,7 +14,7 @@ import unittest
|
|||||||
from typing import ClassVar
|
from typing import ClassVar
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
from PyQt6.QtCore import QPoint, QPointF, Qt
|
from PyQt6.QtCore import QPoint, QPointF, QRect, Qt
|
||||||
from PyQt6.QtGui import QWheelEvent
|
from PyQt6.QtGui import QWheelEvent
|
||||||
from PyQt6.QtWidgets import QApplication, QMessageBox
|
from PyQt6.QtWidgets import QApplication, QMessageBox
|
||||||
|
|
||||||
@@ -263,12 +263,19 @@ class Settings(DikteTest):
|
|||||||
self.assertEqual(label.minimumHeight(), 0)
|
self.assertEqual(label.minimumHeight(), 0)
|
||||||
# Placed and shown, which is the first width worth measuring against.
|
# Placed and shown, which is the first width worth measuring against.
|
||||||
# The room the wrapping needs is claimed then, and it is the lines the
|
# The room the wrapping needs is claimed then, and it is the lines the
|
||||||
# sentence actually takes at this width rather than at the last one.
|
# sentence takes at this width rather than at the last one. Counted
|
||||||
|
# off the font rather than written down here, because how many lines
|
||||||
|
# 400 pixels hold is a different answer on every machine.
|
||||||
label.resize(400, line)
|
label.resize(400, line)
|
||||||
label.show()
|
label.show()
|
||||||
self.assertGreater(label.minimumHeight(), line)
|
wrap = Qt.TextFlag.TextWordWrap | Qt.TextFlag.TextWrapAnywhere
|
||||||
self.assertLessEqual(label.minimumHeight(), 4 * line)
|
needed = label.fontMetrics().boundingRect(
|
||||||
self.assertLessEqual(label.sizeHint().height(), 4 * line)
|
QRect(0, 0, 400, 0), wrap, label.text()).height()
|
||||||
|
self.assertGreater(needed, line) # or the sentence never wrapped
|
||||||
|
self.assertEqual(label.minimumHeight(), needed)
|
||||||
|
# And the label's own hints are the wrapping at this width too, not
|
||||||
|
# the hundred lines the eight pixel one asked for.
|
||||||
|
self.assertLessEqual(label.sizeHint().height(), 3 * needed)
|
||||||
|
|
||||||
def test_saving_without_touching_anything_changes_nothing(self):
|
def test_saving_without_touching_anything_changes_nothing(self):
|
||||||
"""Every widget has to load what is stored, or Save writes its default
|
"""Every widget has to load what is stored, or Save writes its default
|
||||||
|
|||||||
Reference in New Issue
Block a user