Skip to content

Commit f4a16e4

Browse files
committed
Add tests to improve codecov coverage for FlyteFile and FlyteDirectory validators
Signed-off-by: Govert Verkes <govert@cusp.ai>
1 parent 628cf96 commit f4a16e4

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

tests/flytekit/unit/extras/pydantic_transformer/test_pydantic_basemodel_transformer.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,61 @@ class BM(BaseModel):
10411041
bm2.model_dump()
10421042

10431043

1044+
def test_flytefile_pydantic_with_local_file(local_dummy_file):
1045+
class BM(BaseModel):
1046+
ff: FlyteFile
1047+
1048+
bm = BM(ff=FlyteFile(path=local_dummy_file))
1049+
1050+
bm_dict = bm.model_dump()
1051+
bm2 = BM.model_validate(bm_dict)
1052+
1053+
assert isinstance(bm2.ff, FlyteFile)
1054+
assert hasattr(bm2.ff, "_downloader")
1055+
assert hasattr(bm2.ff, "_remote_source")
1056+
1057+
bm2.model_dump()
1058+
1059+
1060+
def test_flytefile_pydantic_with_metadata(local_dummy_file):
1061+
class BM(BaseModel):
1062+
ff: FlyteFile
1063+
1064+
bm = BM(ff=FlyteFile(path=local_dummy_file, metadata={"key": "value"}))
1065+
1066+
bm_dict = bm.model_dump()
1067+
bm2 = BM.model_validate(bm_dict)
1068+
1069+
assert isinstance(bm2.ff, FlyteFile)
1070+
assert hasattr(bm2.ff, "_downloader")
1071+
assert hasattr(bm2.ff, "_remote_source")
1072+
assert bm2.ff.metadata == {"key": "value"}
1073+
1074+
bm2.model_dump()
1075+
1076+
1077+
def test_flytefile_pydantic_direct_dict_validate(local_dummy_file):
1078+
class BM(BaseModel):
1079+
ff: FlyteFile
1080+
1081+
bm = BM.model_validate({"ff": {"path": local_dummy_file}})
1082+
1083+
assert isinstance(bm.ff, FlyteFile)
1084+
assert hasattr(bm.ff, "_downloader")
1085+
assert hasattr(bm.ff, "_remote_source")
1086+
1087+
1088+
def test_flytedirectory_pydantic_direct_dict_validate(local_dummy_directory):
1089+
class BM(BaseModel):
1090+
fd: FlyteDirectory
1091+
1092+
bm = BM.model_validate({"fd": {"path": local_dummy_directory}})
1093+
1094+
assert isinstance(bm.fd, FlyteDirectory)
1095+
assert hasattr(bm.fd, "_downloader")
1096+
assert hasattr(bm.fd, "_remote_source")
1097+
1098+
10441099
def test_flytedirectory_pydantic_model_dump_validate_cycle():
10451100
class BM(BaseModel):
10461101
fd: FlyteDirectory
@@ -1056,3 +1111,19 @@ class BM(BaseModel):
10561111
assert bm2.fd.remote_source == "s3://my-bucket/my-dir"
10571112

10581113
bm2.model_dump()
1114+
1115+
1116+
def test_flytedirectory_pydantic_with_local_directory(local_dummy_directory):
1117+
class BM(BaseModel):
1118+
fd: FlyteDirectory
1119+
1120+
bm = BM(fd=FlyteDirectory(path=local_dummy_directory))
1121+
1122+
bm_dict = bm.model_dump()
1123+
bm2 = BM.model_validate(bm_dict)
1124+
1125+
assert isinstance(bm2.fd, FlyteDirectory)
1126+
assert hasattr(bm2.fd, "_downloader")
1127+
assert hasattr(bm2.fd, "_remote_source")
1128+
1129+
bm2.model_dump()

0 commit comments

Comments
 (0)