Skip to content

Commit 9fd8854

Browse files
authored
feat: adds two from_api_tests: StorageDesc & SerDeInfo (#2074)
* Adds two from_api_tests: StorageDesc & SerDeInfo * Update tests/unit/test_schema.py
1 parent 236455c commit 9fd8854

File tree

1 file changed

+68
-2
lines changed

1 file changed

+68
-2
lines changed

tests/unit/test_schema.py

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,23 @@ def test_to_api_repr(self, type_system, expected):
11611161
assert result.to_api_repr() == expected
11621162

11631163

1164+
@pytest.fixture
1165+
def _make_storage_descriptor():
1166+
serdeinfo = SerDeInfo(
1167+
serialization_library="testpath.to.LazySimpleSerDe",
1168+
name="serde_lib_name",
1169+
parameters={"key": "value"},
1170+
)
1171+
1172+
obj = StorageDescriptor(
1173+
input_format="testpath.to.OrcInputFormat",
1174+
location_uri="gs://test/path/",
1175+
output_format="testpath.to.OrcOutputFormat",
1176+
serde_info=serdeinfo,
1177+
)
1178+
return obj
1179+
1180+
11641181
class TestStorageDescriptor:
11651182
"""Tests for the StorageDescriptor class."""
11661183

@@ -1251,7 +1268,34 @@ def test_to_api_repr(self):
12511268

12521269
assert storage_descriptor.to_api_repr() == expected_repr
12531270

1254-
# TODO: needs a from_api_repr() test.
1271+
SERDEINFO = SerDeInfo(
1272+
serialization_library="testpath.to.LazySimpleSerDe",
1273+
name="serde_lib_name",
1274+
parameters={"key": "value"},
1275+
)
1276+
1277+
API_REPR = {
1278+
"inputFormat": "testpath.to.OrcInputFormat",
1279+
"locationUri": "gs://test/path/",
1280+
"outputFormat": "testpath.to.OrcOutputFormat",
1281+
"serDeInfo": SERDEINFO.to_api_repr(),
1282+
}
1283+
1284+
def test_from_api_repr(self, _make_storage_descriptor):
1285+
"""GIVEN an api representation of a StorageDescriptor (i.e. API_REPR)
1286+
WHEN converted into a StorageDescriptor using from_api_repr() and
1287+
displayed as a dict
1288+
THEN it will have the same representation a StorageDescriptor created
1289+
directly (via the fixture) and displayed as a dict.
1290+
"""
1291+
# generate via fixture
1292+
expected = _make_storage_descriptor
1293+
resource = self.API_REPR
1294+
klass = self._get_target_class()
1295+
# generate via API_REPR
1296+
result = klass.from_api_repr(resource)
1297+
1298+
assert result.to_api_repr() == expected.to_api_repr()
12551299

12561300

12571301
class TestSerDeInfo:
@@ -1315,4 +1359,26 @@ def test_to_api_repr(self):
13151359
}
13161360
assert serde_info.to_api_repr() == expected_repr
13171361

1318-
# TODO: needs a from_api_repr() test.
1362+
def test_from_api_repr(self, _make_storage_descriptor):
1363+
"""GIVEN an api representation of a SerDeInfo object (i.e. resource)
1364+
WHEN converted into a SerDeInfo using from_api_repr() and
1365+
displayed as a dict
1366+
THEN it will have the same representation a SerDeInfo object created
1367+
directly (via _make_one()) and displayed as a dict.
1368+
"""
1369+
resource = {
1370+
"serializationLibrary": "testpath.to.LazySimpleSerDe",
1371+
"name": "serde_name",
1372+
"parameters": {"key": "value"},
1373+
}
1374+
1375+
expected = self._make_one(
1376+
serialization_library="testpath.to.LazySimpleSerDe",
1377+
name="serde_name",
1378+
parameters={"key": "value"},
1379+
)
1380+
1381+
klass = self._get_target_class()
1382+
result = klass.from_api_repr(resource)
1383+
1384+
assert result.to_api_repr() == expected.to_api_repr()

0 commit comments

Comments
 (0)