20
20
import re
21
21
import textwrap
22
22
23
- from testlib import Error , MachineCase , wait
23
+ from testlib import Error , MachineCase , MachineProtocol , wait
24
24
25
25
26
- def from_udisks_ascii (codepoints ) :
26
+ def from_udisks_ascii (codepoints : list [ int ]) -> str :
27
27
return '' .join (map (chr , codepoints [:- 1 ]))
28
28
29
29
30
- class StorageHelpers :
30
+ class StorageHelpers ( MachineProtocol ) :
31
31
"""Mix-in class for using in tests that derive from something else than MachineCase or StorageCase"""
32
32
33
- def inode (self , f ) :
33
+ def inode (self , f : str ) -> str :
34
34
return self .machine .execute ("stat -L '%s' -c %%i" % f )
35
35
36
36
def retry (self , setup , check , teardown ):
@@ -45,7 +45,7 @@ def step():
45
45
46
46
self .browser .wait (step )
47
47
48
- def add_ram_disk (self , size = 50 , delay = None ):
48
+ def add_ram_disk (self , size : int = 50 , delay : int | None = None ):
49
49
"""Add per-test RAM disk
50
50
51
51
The disk gets removed automatically when the test ends. This is safe for @nondestructive tests.
@@ -119,7 +119,7 @@ def add_targetd_loopback_disk(self, index, size=50):
119
119
raise Error ("Device not found" )
120
120
return dev
121
121
122
- def force_remove_disk (self , device ) :
122
+ def force_remove_disk (self , device : str ) -> None :
123
123
"""Act like the given device gets physically removed.
124
124
125
125
This circumvents all the normal EBUSY failures, and thus can be used for testing
@@ -140,7 +140,7 @@ def addCleanupMount(self, mount_point):
140
140
141
141
# Dialogs
142
142
143
- def dialog_wait_open (self ):
143
+ def dialog_wait_open (self ) -> None :
144
144
self .browser .wait_visible ('#dialog' )
145
145
146
146
def dialog_wait_alert (self , text1 , text2 = None ):
@@ -149,10 +149,10 @@ def has_alert_title():
149
149
return text1 in t or (text2 is not None and text2 in t )
150
150
self .browser .wait (has_alert_title )
151
151
152
- def dialog_wait_title (self , text ) :
152
+ def dialog_wait_title (self , text : str ) -> None :
153
153
self .browser .wait_in_text ('#dialog .pf-v5-c-modal-box__title' , text )
154
154
155
- def dialog_field (self , field ) :
155
+ def dialog_field (self , field : str ) -> str :
156
156
return f'#dialog [data-field="{ field } "]'
157
157
158
158
def dialog_val (self , field ):
@@ -233,22 +233,22 @@ def dialog_wait_error(self, field, val):
233
233
def dialog_wait_not_present (self , field ):
234
234
self .browser .wait_not_present (self .dialog_field (field ))
235
235
236
- def dialog_wait_apply_enabled (self ):
236
+ def dialog_wait_apply_enabled (self ) -> None :
237
237
self .browser .wait_attr ('#dialog button.apply:nth-of-type(1)' , "disabled" , None )
238
238
239
- def dialog_wait_apply_disabled (self ):
239
+ def dialog_wait_apply_disabled (self ) -> None :
240
240
self .browser .wait_visible ('#dialog button.apply:nth-of-type(1)[disabled]' )
241
241
242
- def dialog_apply (self ):
242
+ def dialog_apply (self ) -> None :
243
243
self .browser .click ('#dialog button.apply:nth-of-type(1)' )
244
244
245
- def dialog_apply_secondary (self ):
245
+ def dialog_apply_secondary (self ) -> None :
246
246
self .browser .click ('#dialog button.apply:nth-of-type(2)' )
247
247
248
- def dialog_cancel (self ):
248
+ def dialog_cancel (self ) -> None :
249
249
self .browser .click ('#dialog button.cancel' )
250
250
251
- def dialog_wait_close (self ):
251
+ def dialog_wait_close (self ) -> None :
252
252
# file system operations often take longer than 10s
253
253
with self .browser .wait_timeout (max (self .browser .timeout , 60 )):
254
254
self .browser .wait_not_present ('#dialog' )
@@ -386,7 +386,7 @@ def udisks_objects(self):
386
386
"org.freedesktop.DBus.ObjectManager",
387
387
"GetManagedObjects", "", [])))""" )]))
388
388
389
- def configuration_field (self , dev , tab , field ) :
389
+ def configuration_field (self , dev : str , tab : str , field : str ) -> str :
390
390
managerObjects = self .udisks_objects ()
391
391
for path in managerObjects :
392
392
if "org.freedesktop.UDisks2.Block" in managerObjects [path ]:
@@ -405,7 +405,7 @@ def assert_in_configuration(self, dev, tab, field, text):
405
405
def assert_not_in_configuration (self , dev , tab , field , text ):
406
406
self .assertNotIn (text , self .configuration_field (dev , tab , field ))
407
407
408
- def child_configuration_field (self , dev , tab , field ) :
408
+ def child_configuration_field (self , dev : str , tab : str , field : str ) -> str :
409
409
udisks_objects = self .udisks_objects ()
410
410
for path in udisks_objects :
411
411
if "org.freedesktop.UDisks2.Encrypted" in udisks_objects [path ]:
@@ -579,13 +579,13 @@ def encrypt_root(self, passphrase):
579
579
580
580
# Cards and tables
581
581
582
- def card (self , title ) :
582
+ def card (self , title : str ) -> str :
583
583
return f"[data-test-card-title='{ title } ']"
584
584
585
- def card_parent_link (self ):
585
+ def card_parent_link (self ) -> str :
586
586
return ".pf-v5-c-breadcrumb__item:nth-last-child(2) > a"
587
587
588
- def card_header (self , title ) :
588
+ def card_header (self , title : str ) -> str :
589
589
return self .card (title ) + " .pf-v5-c-card__header"
590
590
591
591
def card_row (self , title , index = None , name = None , location = None ):
@@ -604,51 +604,51 @@ def click_card_row(self, title, index=None, name=None, location=None):
604
604
def card_row_col (self , title , row_index = None , col_index = None , row_name = None , row_location = None ):
605
605
return self .card_row (title , row_index , row_name , row_location ) + f" td:nth-child({ col_index } )"
606
606
607
- def card_desc (self , card_title , desc_title ) :
607
+ def card_desc (self , card_title : str , desc_title : str ) -> str :
608
608
return self .card (card_title ) + f" [data-test-desc-title='{ desc_title } '] [data-test-value=true]"
609
609
610
- def card_desc_action (self , card_title , desc_title ) :
610
+ def card_desc_action (self , card_title : str , desc_title : str ) -> str :
611
611
return self .card (card_title ) + f" [data-test-desc-title='{ desc_title } '] [data-test-action=true] button"
612
612
613
- def card_button (self , card_title , button_title ) :
613
+ def card_button (self , card_title : str , button_title : str ) -> str :
614
614
return self .card (card_title ) + f" button:contains('{ button_title } ')"
615
615
616
- def dropdown_toggle (self , parent ) :
616
+ def dropdown_toggle (self , parent : str ) -> str :
617
617
return parent + " .pf-v5-c-menu-toggle"
618
618
619
- def dropdown_action (self , parent , title ) :
619
+ def dropdown_action (self , parent : str , title : str ) -> str :
620
620
return parent + f" .pf-v5-c-menu button:contains('{ title } ')"
621
621
622
- def dropdown_description (self , parent , title ) :
622
+ def dropdown_description (self , parent : str , title : str ) -> str :
623
623
return parent + f" .pf-v5-c-menu button:contains('{ title } ') .pf-v5-c-menu__item-description"
624
624
625
- def click_dropdown (self , parent , title ) :
625
+ def click_dropdown (self , parent : str , title : str ) -> None :
626
626
self .browser .click (self .dropdown_toggle (parent ))
627
627
self .browser .click (self .dropdown_action (parent , title ))
628
628
629
- def click_card_dropdown (self , card_title , button_title ) :
629
+ def click_card_dropdown (self , card_title : str , button_title : str ) -> None :
630
630
self .click_dropdown (self .card_header (card_title ), button_title )
631
631
632
- def click_devices_dropdown (self , title ) :
632
+ def click_devices_dropdown (self , title : str ) -> None :
633
633
self .click_card_dropdown ("Storage" , title )
634
634
635
- def check_dropdown_action_disabled (self , parent , title , expected_text ) :
635
+ def check_dropdown_action_disabled (self , parent : str , title : str , expected_text : str ) -> None :
636
636
self .browser .click (self .dropdown_toggle (parent ))
637
637
self .browser .wait_visible (self .dropdown_action (parent , title ) + "[disabled]" )
638
638
self .browser .wait_text (self .dropdown_description (parent , title ), expected_text )
639
639
self .browser .click (self .dropdown_toggle (parent ))
640
640
641
- def wait_mounted (self , card_title ) :
641
+ def wait_mounted (self , card_title : str ) -> None :
642
642
with self .browser .wait_timeout (30 ):
643
643
self .browser .wait_not_in_text (self .card_desc (card_title , "Mount point" ),
644
644
"The filesystem is not mounted." )
645
645
646
- def wait_not_mounted (self , card_title ) :
646
+ def wait_not_mounted (self , card_title : str ) -> None :
647
647
with self .browser .wait_timeout (30 ):
648
648
self .browser .wait_in_text (self .card_desc (card_title , "Mount point" ),
649
649
"The filesystem is not mounted." )
650
650
651
- def wait_card_button_disabled (self , card_title , button_title ) :
651
+ def wait_card_button_disabled (self , card_title : str , button_title : str ) -> None :
652
652
with self .browser .wait_timeout (30 ):
653
653
self .browser .wait_visible (self .card_button (card_title , button_title ) + ":disabled" )
654
654
0 commit comments