blob: cb4d9ee7dff60609ddd8afd0ffb88ae764349842 [file] [edit]
# Copyright 2026 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
"""Full test of disk_usage module."""
from __future__ import annotations
from collections.abc import Iterator
from recipe_engine import post_process, recipe_api, recipe_test_api
from PB.recipe_engine import result as result_pb
DEPS = [
'pigweed/disk_usage',
'recipe_engine/step',
]
def RunSteps(api: recipe_api.RecipeScriptApi) -> result_pb.RawResult | None:
usage = api.disk_usage()
api.step.empty(
'disk usage summary',
step_text=(
f'Total: {usage.total}, Used: {usage.used}, Free: {usage.free}'
),
)
return None
def GenTests(
api: recipe_test_api.RecipeTestApi,
) -> Iterator[recipe_test_api.TestData]:
yield api.test(
'basic',
api.disk_usage(
total=100 * 1024**3,
used=40 * 1024**3,
free=60 * 1024**3,
),
api.post_check(
post_process.StepSummaryEquals,
'disk usage',
'40.00/100.00 GB used (40.0%)',
),
api.post_check(post_process.MustRun, 'disk usage summary'),
api.post_process(post_process.DropExpectation),
)
yield api.test(
'zero_total',
api.disk_usage(total=0, used=0, free=0),
api.post_check(
post_process.StepSummaryEquals,
'disk usage',
'0.00/0.00 GB used (0.0%)',
),
api.post_check(post_process.MustRun, 'disk usage summary'),
api.post_process(post_process.DropExpectation),
)