Skip to content
Snippets Groups Projects

Add initial test framework for utils functions

1 file
+ 65
0
Compare changes
  • Side-by-side
  • Inline
+ 65
0
import pytest
from typing import Literal
from pathlib import Path
from rc_gpfs import utils
@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"]):
p_path = utils.as_path(path)
assert isinstance(p_path, Path)
@pytest.mark.parametrize(
"value,unit,to_unit,use_binary,expected",
[
(1,"G","K",False,1000000),
(4,'K','base',True,4096),
('100','base','T',False,1e-10)
]
)
def test_convert_si(value,unit,to_unit,use_binary,expected):
assert utils.convert_si(value,unit,to_unit,use_binary) == expected
@pytest.mark.parametrize(
"val,default,expected",
[
('1 kiB',None,1024),
('1 kiB',(1024**4),1024),
('10 TiB',None,10*(1024**4)),
(None,1024,1024),
(None,None,None),
('1.5 MiB',None,1572864)
]
)
def test_as_bytes(val,default,expected):
assert utils.as_bytes(val,default) == expected
class TestSizeDistribution:
inputs = [
["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],
"1 MiB"
]
expected_bins = [
[4096, 4194304, 1073741824, 10737418240, 107374182400, 1099511627776],
[4096, 4194304, 1073741824, 10737418240, 107374182400, 1099511627776],
[1024, 4096, 10737418240],
[1048576]
]
expected_labels = [
["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"],
["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"],
["0 B-1 KiB","1 KiB-4 KiB","4 KiB-10 GiB",">10 GiB"],
["0 B-1 MiB",">1 MiB"]
]
@pytest.mark.parametrize("bins,expected",list(zip(expected_bins,expected_labels)))
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)))))
def test_prep_size_distribution(self,bins,expected):
assert utils.prep_size_distribution(size_bins=bins) == expected
\ No newline at end of file
Loading