chaokunyang commented on code in PR #3384:
URL: https://github.com/apache/fory/pull/3384#discussion_r2867250647


##########
python/pyfory/tests/test_duplicate_field_names.py:
##########
@@ -0,0 +1,277 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+Tests for inheritance in TypeDef implementation.
+"""
+
+from dataclasses import dataclass
+from pyfory.buffer import Buffer
+from pyfory.meta.typedef_encoder import encode_typedef
+from pyfory.meta.typedef_decoder import decode_typedef
+from pyfory import Fory
+
+
+@dataclass
+class ParentClass:
+    """Parent class with some fields."""
+
+    name: str
+    value: int
+
+
+@dataclass
+class ChildClass(ParentClass):
+    """Child class that inherits from ParentClass."""
+
+    description: str
+    count: int
+
+
+@dataclass
+class ChildWithShadowedField(ParentClass):
+    """Child class that shadows a parent field name."""
+
+    name: str  # Shadows ParentClass.name
+    extra: float
+
+
+@dataclass
+class GrandchildClass(ChildClass):
+    """Grandchild class for multi-level inheritance."""
+
+    level: int
+
+
+@dataclass
+class GrandchildWithShadowedFields(ChildClass):
+    """Grandchild that shadows fields from multiple levels."""
+
+    name: str  # Shadows ParentClass.name
+    value: int  # Shadows ParentClass.value
+    description: str  # Shadows ChildClass.description
+
+
+def test_inheritance_basic():
+    """Test TypeDef encoding/decoding with basic inheritance."""
+    fory = Fory(xlang=True)
+    fory.register(ParentClass, namespace="example", typename="ParentClass")
+    fory.register(ChildClass, namespace="example", typename="ChildClass")
+
+    resolver = fory.type_resolver
+
+    # Test parent class
+    parent_typedef = encode_typedef(resolver, ParentClass)
+    assert len(parent_typedef.fields) == 2
+    field_names = [f.name for f in parent_typedef.fields]
+    assert "name" in field_names
+    assert "value" in field_names
+
+    # Test child class - should have all fields from parent plus its own
+    child_typedef = encode_typedef(resolver, ChildClass)
+    assert len(child_typedef.fields) == 4
+    field_names = [f.name for f in child_typedef.fields]
+    assert "name" in field_names
+    assert "value" in field_names
+    assert "description" in field_names
+    assert "count" in field_names
+
+    # Verify round-trip encoding/decoding
+    buffer = Buffer(child_typedef.encoded)
+    decoded_typedef = decode_typedef(buffer, resolver)
+    assert len(decoded_typedef.fields) == 4
+
+
+def test_inheritance_shadowed_fields():
+    """Test TypeDef encoding/decoding when child shadows parent fields."""
+    fory = Fory(xlang=True)
+    fory.register(ParentClass, namespace="example", typename="ParentClass")
+    fory.register(ChildWithShadowedField, namespace="example", 
typename="ChildWithShadowedField")
+
+    resolver = fory.type_resolver
+
+    # Encode the child class with shadowed field
+    typedef = encode_typedef(resolver, ChildWithShadowedField)
+
+    # Should have: name (from parent), value (from parent), name (shadowed), 
extra
+    # But with deduplication, we should only have unique field entries
+    field_names = [f.name for f in typedef.fields]
+
+    # Verify 'name' appears only once (deduplicated)
+    assert field_names.count("name") == 1, f"Expected 'name' to appear once, 
but found {field_names.count('name')} times"
+    assert "value" in field_names
+    assert "extra" in field_names
+
+    # Verify round-trip
+    buffer = Buffer(typedef.encoded)
+    decoded_typedef = decode_typedef(buffer, resolver)
+
+    decoded_field_names = [f.name for f in decoded_typedef.fields]
+    assert decoded_field_names.count("name") == 1
+
+
+def test_multilevel_inheritance():

Review Comment:
   I'm not sure whether such tests are meaningful. The shadow ones shuld 
already cover it.More code means more maintainance overhead. 
   
   Please refactor all tests to to make it consise and remove redundancy



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to