@@ -945,6 +945,33 @@ def test_schema_object_field_access(self):
945945 assert schema [0 ]["name" ] == "name" # Access fields using indexing
946946 assert schema [1 ]["type" ] == "INTEGER"
947947
948+ def test_schema_object_data_access (self ):
949+ """Schema class is superclassed by UserList, which requires the
950+ use of a '.data' attribute. The decision was made to have both of these attributes point to
951+ the same key "fields" in the '_properties' dictionary. Thus '.data' is an alias
952+ for '_fields'.
953+
954+ This test assures that .data functions as an alias to the underlying data.
955+ """
956+
957+ schema = Schema (
958+ fields = [
959+ SchemaField ("name" , "STRING" ),
960+ SchemaField ("age" , "INTEGER" ),
961+ ]
962+ )
963+
964+ assert len (schema .data ) == 2
965+ assert schema .data [0 ]["name" ] == "name" # Access fields using indexing
966+ assert schema .data [1 ]["type" ] == "INTEGER"
967+
968+ new_fields = [
969+ SchemaField ("new_name" , "STRING" ),
970+ SchemaField ("new_age" , "INTEGER" ),
971+ ]
972+ schema .data = new_fields
973+ assert schema .data [0 ]["name" ] == "new_name"
974+
948975 def test_schema_object_foreign_type_info (self ):
949976 schema = Schema (foreign_type_info = "External" )
950977 assert schema .foreign_type_info == "External"
@@ -1046,6 +1073,14 @@ def test_schema_extend(self):
10461073 },
10471074 id = "repr without foreign type info" ,
10481075 ),
1076+ pytest .param (
1077+ Schema (fields = None ),
1078+ {
1079+ "fields" : [],
1080+ "foreignTypeInfo" : None ,
1081+ },
1082+ id = "repr with no fields" ,
1083+ ),
10491084 ],
10501085 )
10511086 def test_to_api_repr (self , schema , expected_api_repr ):
0 commit comments