99
1010def test_constructor_only_text_no_size (window ):
1111 """Should fit text"""
12- label = UILabel (text = "Example" )
12+ label = UILabel (text = "Example" , font_name = "Kenney Pixel" )
1313
14- assert label .rect .width == pytest .approx (
15- 63 , abs = 10
16- ) # on windows the width differs about 6 pixel
17- assert label .rect .height == pytest .approx (19 , abs = 1 )
14+ assert label .rect .width == 43
15+ assert label .rect .height == 12
1816
1917
2018def test_constructor_text_and_size (window ):
@@ -28,11 +26,11 @@ def test_constructor_size_smaller_then_text(window):
2826
2927
3028def test_constructor_fix_width_and_multiline (window ):
31- label = UILabel (text = "E x a m p l e" , width = 10 , multiline = True )
32- assert label .rect .left == pytest . approx ( 0 , abs = 2 )
33- assert label .rect .bottom == pytest . approx ( 0 , abs = 2 )
34- assert label .rect .width == pytest . approx ( 10 , abs = 2 )
35- assert label .rect .height == pytest . approx ( 133 , abs = 7 )
29+ label = UILabel (text = "E x a m p l e" , width = 10 , multiline = True , font_name = "Kenney Pixel" )
30+ assert label .rect .left == 0
31+ assert label .rect .bottom == 0
32+ assert label .rect .width == 10
33+ assert label .rect .height == 84
3634
3735
3836def test_constructor_adaptive_width_support_for_multiline_text (window ):
@@ -47,23 +45,23 @@ def test_constructor_adaptive_width_support_for_multiline_text(window):
4745
4846
4947def test_with_border_keeps_previous_size (window ):
50- label = UILabel (text = "Example" )
51- assert label .rect .width == pytest . approx ( 63 , abs = 10 )
52- assert label .rect .height == pytest . approx ( 19 , abs = 6 )
48+ label = UILabel (text = "Example" , font_name = "Kenney Pixel" )
49+ assert label .rect .width == 43
50+ assert label .rect .height == 12
5351
5452 label .with_border ()
55- assert label .rect .width == pytest . approx ( 63 , abs = 10 )
56- assert label .rect .height == pytest . approx ( 19 , abs = 6 )
53+ assert label .rect .width == 43
54+ assert label .rect .height == 12
5755
5856
5957def test_with_padding_keeps_previous_size (window ):
60- label = UILabel (text = "Example" )
61- assert label .rect .width == pytest . approx ( 63 , abs = 10 )
62- assert label .rect .height == pytest . approx ( 19 , abs = 6 )
58+ label = UILabel (text = "Example" , font_name = "Kenney Pixel" )
59+ assert label .rect .width == 43
60+ assert label .rect .height == 12
6361
6462 label .with_padding (all = 2 )
65- assert label .rect .width == pytest . approx ( 63 , abs = 10 )
66- assert label .rect .height == pytest . approx ( 19 , abs = 6 )
63+ assert label .rect .width == 43
64+ assert label .rect .height == 12
6765
6866
6967def test_internals_text_placed_at_0_0 (window ):
@@ -187,21 +185,22 @@ def test_integration_with_layout_fit_to_content(ui):
187185 label = UILabel (
188186 text = "Example" ,
189187 size_hint = (0 , 0 ), # default, enables auto size
188+ font_name = "Kenney Pixel" ,
190189 )
191190
192191 ui .add (label )
193192 ui .execute_layout ()
194193
195194 # auto size should fit the text
196- assert label .rect .width == pytest . approx ( 63 , abs = 10 )
197- assert label .rect .height == pytest . approx ( 19 , abs = 6 )
195+ assert label .rect .width == 44
196+ assert label .rect .height == 12
198197
199198 # even when text changed
200199 label .text = "Example, which is way longer"
201200 ui .execute_layout ()
202201
203202 assert label .rect .width > 63
204- assert label .rect .height == pytest . approx ( 19 , abs = 6 )
203+ assert label .rect .height == 12
205204
206205 # or font
207206 label .text = "Example"
@@ -217,12 +216,13 @@ def test_fit_content_overrides_width(ui):
217216 text = "Example" ,
218217 width = 100 ,
219218 height = 50 ,
219+ font_name = "Kenney Pixel" ,
220220 )
221221
222222 label .fit_content ()
223223
224- assert label .rect .width == pytest . approx ( 63 , abs = 10 )
225- assert label .rect .height == pytest . approx ( 19 , abs = 6 )
224+ assert label .rect .width == 44
225+ assert label .rect .height == 12
226226
227227
228228def test_fit_content_uses_adaptive_multiline_width (ui ):
0 commit comments