added pytest, moved dependencies
parent
4b6bd55df4
commit
ee45b46638
|
|
@ -1,18 +1,34 @@
|
||||||
from PyQt6 import QtGui
|
import pytest
|
||||||
from piker.ui._style import DpiAwareFont
|
from piker.ui._style import DpiAwareFont
|
||||||
|
|
||||||
class MockScreen:
|
class MockScreen:
|
||||||
|
def __init__(self, pdpi, ldpi, name="MockScreen"):
|
||||||
|
self._pdpi = pdpi
|
||||||
|
self._ldpi = ldpi
|
||||||
|
self._name = name
|
||||||
|
|
||||||
def physicalDotsPerInch(self):
|
def physicalDotsPerInch(self):
|
||||||
return 169 # example HiDPI
|
return self._pdpi
|
||||||
|
|
||||||
def logicalDotsPerInch(self):
|
def logicalDotsPerInch(self):
|
||||||
return 96
|
return self._ldpi
|
||||||
|
|
||||||
def name(self):
|
def name(self):
|
||||||
return "MockScreen"
|
return self._name
|
||||||
|
|
||||||
# create font instance
|
@pytest.mark.parametrize(
|
||||||
|
"pdpi, ldpi",
|
||||||
|
[
|
||||||
|
(96, 96), # normal DPI
|
||||||
|
(169, 96), # HiDPI
|
||||||
|
(120, 96), # mid-DPI
|
||||||
|
]
|
||||||
|
)
|
||||||
|
def test_font_px_size(pdpi, ldpi):
|
||||||
font = DpiAwareFont()
|
font = DpiAwareFont()
|
||||||
|
font.configure_to_dpi(screen=MockScreen(pdpi, ldpi))
|
||||||
|
|
||||||
# pass the mock screen to configure_to_dpi
|
px = font.px_size
|
||||||
font.configure_to_dpi(screen=MockScreen())
|
print(f"{pdpi}x{ldpi} DPI -> Computed pixel size: {px}")
|
||||||
|
|
||||||
print("Computed pixel size:", font.px_size)
|
assert 12 <= px <= 24
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue