Skip to content

Commit cfed368

Browse files
committed
test: let StorageHelpers inherit from TestCase
We don't want to re-define addCleanup ourself so we simply inherit unittest.TestCase and type everything which uses addCleanup.
1 parent 6c4e137 commit cfed368

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

test/common/storagelib.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import os.path
2020
import re
2121
import textwrap
22+
import unittest
2223
from typing import Any
2324

2425
from machine import testvm
@@ -29,7 +30,7 @@ def from_udisks_ascii(codepoints: list[int]) -> str:
2930
return ''.join(map(chr, codepoints[:-1]))
3031

3132

32-
class StorageHelpers:
33+
class StorageHelpers(unittest.TestCase):
3334
"""Mix-in class for using in tests that derive from something else than MachineCase or StorageCase"""
3435
machine: testvm.Machine
3536
browser: Browser
@@ -70,7 +71,7 @@ def add_ram_disk(self, size: int = 50, delay: int | None = None):
7071

7172
return dev
7273

73-
def add_loopback_disk(self, size=50, name=None):
74+
def add_loopback_disk(self, size: int = 50, name: str | None = None) -> str:
7475
"""Add per-test loopback disk
7576
7677
The disk gets removed automatically when the test ends. This is safe for @nondestructive tests.
@@ -103,7 +104,7 @@ def add_loopback_disk(self, size=50, name=None):
103104

104105
return dev
105106

106-
def add_targetd_loopback_disk(self, index, size=50):
107+
def add_targetd_loopback_disk(self, index: str, size: int = 50) -> str:
107108
"""Add per-test loopback device that can be forcefully removed.
108109
"""
109110

@@ -135,12 +136,12 @@ def force_remove_disk(self, device: str) -> None:
135136
# the removal trips up PCP and our usage graphs
136137
self.allow_browser_errors("direct: instance name lookup failed.*")
137138

138-
def addCleanupVG(self, vgname):
139+
def addCleanupVG(self, vgname: str) -> None:
139140
"""Ensure the given VG is removed after the test"""
140141

141142
self.addCleanup(self.machine.execute, f"if [ -d /dev/{vgname} ]; then vgremove --force {vgname}; fi")
142143

143-
def addCleanupMount(self, mount_point):
144+
def addCleanupMount(self, mount_point: str) -> None:
144145
self.addCleanup(self.machine.execute,
145146
f"if mountpoint -q {mount_point}; then umount {mount_point}; fi")
146147

0 commit comments

Comments
 (0)