Skip to content

Commit 8f836be

Browse files
committed
Hoist calculation of side triple into parent class
Signed-off-by: mulhern <amulhern@redhat.com>
1 parent 386aa7d commit 8f836be

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

src/stratis_cli/_actions/_list_filesystem.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ def display(self):
121121
List filesystems.
122122
"""
123123

124+
@staticmethod
125+
def size_triple(mofs: Any) -> SizeTriple:
126+
"""
127+
Calculate size triple
128+
"""
129+
return SizeTriple(Range(mofs.Size()), get_property(mofs.Used(), Range, None))
130+
124131

125132
class Table(ListFilesystem): # pylint: disable=too-few-public-methods
126133
"""
@@ -133,15 +140,14 @@ def display(self):
133140
"""
134141

135142
def filesystem_size_quartet(
136-
total: Range, used: Optional[Range], limit: Optional[Range]
143+
size_triple: SizeTriple, limit: Optional[Range]
137144
) -> str:
138145
"""
139146
Calculate the triple to display for filesystem size.
140147
141148
:returns: a string a formatted string showing all three values
142149
:rtype: str
143150
"""
144-
size_triple = SizeTriple(total, used)
145151
triple_str = " / ".join(
146152
(
147153
TABLE_FAILURE_STRING if x is None else str(x)
@@ -165,8 +171,7 @@ def filesystem_size_quartet(
165171
)
166172
size_func = catch_missing_property(
167173
lambda mofs: filesystem_size_quartet(
168-
Range(mofs.Size()),
169-
get_property(mofs.Used(), Range, None),
174+
ListFilesystem.size_triple(mofs),
170175
get_property(mofs.SizeLimit(), Range, None),
171176
),
172177
TABLE_UNKNOWN_STRING,
@@ -215,7 +220,7 @@ def display(self):
215220

216221
fs = self.filesystems_with_props[0]
217222

218-
size_triple = SizeTriple(Range(fs.Size()), get_property(fs.Used(), Range, None))
223+
size_triple = ListFilesystem.size_triple(fs)
219224
limit = get_property(fs.SizeLimit(), Range, None)
220225
created = (
221226
date_parser.isoparse(fs.Created()).astimezone().strftime("%b %d %Y %H:%M")

tests/integration/pool/test_list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def test_list_no_size(self):
331331
stratis_cli._actions._list_pool.Default, # pyright: ignore
332332
"size_triple",
333333
autospec=True,
334-
raises=DbusClientMissingPropertyError(
334+
side_effect=DbusClientMissingPropertyError(
335335
"oops",
336336
stratis_cli._actions._constants.POOL_INTERFACE, # pyright: ignore
337337
"TotalPhysicalUsed",

0 commit comments

Comments
 (0)