test_file_info.py
1 from mlflow.entities import FileInfo 2 3 from tests.helper_functions import random_int, random_str 4 5 6 def _check(fi, path, is_dir, size_in_bytes): 7 assert isinstance(fi, FileInfo) 8 assert fi.path == path 9 assert fi.is_dir == is_dir 10 assert fi.file_size == size_in_bytes 11 12 13 def test_creation_and_hydration(): 14 path = random_str(random_int(10, 50)) 15 is_dir = random_int(10, 2500) % 2 == 0 16 size_in_bytes = random_int(1, 10000) 17 fi1 = FileInfo(path, is_dir, size_in_bytes) 18 _check(fi1, path, is_dir, size_in_bytes) 19 20 as_dict = {"path": path, "is_dir": is_dir, "file_size": size_in_bytes} 21 assert dict(fi1) == as_dict 22 23 proto = fi1.to_proto() 24 fi2 = FileInfo.from_proto(proto) 25 _check(fi2, path, is_dir, size_in_bytes) 26 27 fi3 = FileInfo.from_dictionary(as_dict) 28 _check(fi3, path, is_dir, size_in_bytes)