summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2020-11-24 14:06:03 +0100
committerFlorian Bruhin <me@the-compiler.org>2020-11-24 16:49:05 +0100
commit6e4d9301c0b421f9fcecd7f74674e49f2af6cce3 (patch)
tree5b82d80633aab519edebfb4e69a6cb06e70541b6
parent029ba192b6168e2bbe1b445c39ff126412177eb2 (diff)
downloadqutebrowser-6e4d9301c0b421f9fcecd7f74674e49f2af6cce3.tar.gz
qutebrowser-6e4d9301c0b421f9fcecd7f74674e49f2af6cce3.zip
Add a test for the system monospace font
See #5663
-rw-r--r--qutebrowser/config/configutils.py3
-rw-r--r--tests/unit/config/test_configutils.py43
2 files changed, 46 insertions, 0 deletions
diff --git a/qutebrowser/config/configutils.py b/qutebrowser/config/configutils.py
index b4eb004c2..e7a60a7eb 100644
--- a/qutebrowser/config/configutils.py
+++ b/qutebrowser/config/configutils.py
@@ -282,6 +282,9 @@ class FontFamilies:
def __iter__(self) -> Iterator[str]:
yield from self._families
+ def __len__(self) -> int:
+ return len(self._families)
+
def __repr__(self) -> str:
return utils.get_repr(self, families=self._families, constructor=True)
diff --git a/tests/unit/config/test_configutils.py b/tests/unit/config/test_configutils.py
index 7e1a7c744..f76d55f52 100644
--- a/tests/unit/config/test_configutils.py
+++ b/tests/unit/config/test_configutils.py
@@ -21,6 +21,7 @@ import hypothesis
from hypothesis import strategies
import pytest
from PyQt5.QtCore import QUrl
+from PyQt5.QtWidgets import QLabel
from qutebrowser.config import configutils, configdata, configtypes, configexc
from qutebrowser.utils import urlmatch, usertypes, qtutils
@@ -364,3 +365,45 @@ class TestFontFamilies:
assert family
str(families)
+
+ def test_system_default_basics(self, qapp):
+ families = configutils.FontFamilies.from_system_default()
+ assert len(families) == 1
+ assert str(families)
+
+ def test_system_default_rendering(self, qtbot):
+ families = configutils.FontFamilies.from_system_default()
+
+ label = QLabel()
+ qtbot.add_widget(label)
+ label.setText("Hello World")
+
+ stylesheet = f'font-family: {families.to_str(quote=True)}'
+ print(stylesheet)
+ label.setStyleSheet(stylesheet)
+
+ with qtbot.waitExposed(label):
+ # Needed so the font gets calculated
+ label.show()
+ info = label.fontInfo()
+
+ # Check the requested font to make sure CSS parsing worked
+ assert label.font().family() == families.family
+
+ # Try to find out whether the monospace font did a fallback on a non-monospace
+ # font...
+ fallback_label = QLabel()
+ qtbot.add_widget(label)
+ fallback_label.setText("fallback")
+
+ with qtbot.waitExposed(fallback_label):
+ # Needed so the font gets calculated
+ fallback_label.show()
+
+ fallback_family = fallback_label.fontInfo().family()
+ print(f'fallback: fallback_family')
+ if info.family() == fallback_family:
+ return
+
+ # If we didn't fall back, we should've gotten a fixed-pitch font.
+ assert info.fixedPitch(), info.family()