Skip to content
Snippets Groups Projects

Add initial test framework for utils functions

1 file
+ 105
4
Compare changes
  • Side-by-side
  • Inline
+ 105
4
@@ -3,6 +3,9 @@ from typing import Literal
from pathlib import Path
from rc_gpfs import utils
from polars.testing import assert_series_equal
import polars as pl
@pytest.mark.parametrize("path", ["/data/rc/gpfs-policy", Path("/data/rc/gpfs-policy")])
def test_as_path_valid(path: Path | Literal["/data/rc/gpfs-policy"]):
@@ -34,8 +37,102 @@ def test_convert_si(value,unit,to_unit,use_binary,expected):
def test_as_bytes(val,default,expected):
assert utils.as_bytes(val,default) == expected
class TestSizeDistribution:
inputs = [
class TestSizeGrouping:
input_sizes = pl.Series(
name="size",
values = [
0,
2048,
4096,
1024**2, # 1 MiB
1024**3, # 1 GiB
20*1024**3, # 20 GiB
1024**5 # 1 PiB
],
dtype = pl.Int128()
)
expected_size_groups = [
pl.Series(
name="size",
values=[
"0 B-4 KiB",
"0 B-4 KiB",
"0 B-4 KiB",
"4 KiB-4 MiB",
"4 MiB-1 GiB",
"10 GiB-100 GiB",
">1 TiB",
],
dtype=pl.Enum(
[
"0 B-4 KiB",
"4 KiB-4 MiB",
"4 MiB-1 GiB",
"1 GiB-10 GiB",
"10 GiB-100 GiB",
"100 GiB-1 TiB",
">1 TiB",
]
),
),
pl.Series(
name="size",
values=[
"0 B-4 KiB",
"0 B-4 KiB",
"0 B-4 KiB",
"4 KiB-4 MiB",
"4 MiB-1 GiB",
"10 GiB-100 GiB",
">1 TiB",
],
dtype=pl.Enum(
[
"0 B-4 KiB",
"4 KiB-4 MiB",
"4 MiB-1 GiB",
"1 GiB-10 GiB",
"10 GiB-100 GiB",
"100 GiB-1 TiB",
">1 TiB",
]
),
),
pl.Series(
name="size",
values=[
"0 B-1 KiB",
"1 KiB-4 KiB",
"1 KiB-4 KiB",
"4 KiB-10 GiB",
"4 KiB-10 GiB",
">10 GiB",
">10 GiB",
],
dtype=pl.Enum(["0 B-1 KiB", "1 KiB-4 KiB", "4 KiB-10 GiB", ">10 GiB"]),
),
pl.Series(
name="size",
values=[
"0 B-1 MiB",
"0 B-1 MiB",
"0 B-1 MiB",
"0 B-1 MiB",
">1 MiB",
">1 MiB",
">1 MiB",
],
dtype=pl.Enum(
[
"0 B-1 MiB",
">1 MiB",
]
),
),
]
input_bins = [
["4 KiB", "4 MiB", "1 GiB", "10 GiB", "100 GiB", "1 TiB"],
[4096, 4194304, 1073741824, 10737418240, 107374182400, 1099511627776],
["10 GiB", 1024, 4096, "1 KiB",0],
@@ -60,6 +157,10 @@ class TestSizeDistribution:
def test_create_size_bin_labels(self,bins,expected):
assert utils.create_size_bin_labels(bins) == expected
@pytest.mark.parametrize("bins,expected",list(zip(inputs,list(zip(expected_bins,expected_labels)))))
@pytest.mark.parametrize("bins,expected",list(zip(input_bins,list(zip(expected_bins,expected_labels)))))
def test_prep_size_distribution(self,bins,expected):
assert utils.prep_size_distribution(size_bins=bins) == expected
\ No newline at end of file
assert utils.prep_size_distribution(size_bins=bins) == expected
@pytest.mark.parametrize("bins,expected",list(zip(input_bins,expected_size_groups)),ids=[1,2,3,4])
def test_calculate_size_distribution(self, bins, expected):
assert_series_equal(utils.calculate_size_distribution(self.input_sizes, size_bins=bins),expected)
\ No newline at end of file
Loading