class ObjectMapperTest(unittest.TestCase):
"""
Unit tests for the `ObjectMapper` module.
"""
@dataclass
class FromTestDataClass:
a: int
b: str
@dataclass
class ToTestDataClass:
a: int
b: str
def test_mapping_creation_without_mappings_correct_using_dataclass(self):
""" Test mapping creation without mappings with dataclass"""
# Arrange
from_class = FromTestClass()
mapper = ObjectMapper()
mapper.create_map(FromTestDataClass, ToTestDataClass)
# Act
result = mapper.map(FromTestDataClass(a=1, b='2'))
# Assert
self.assertTrue(isinstance(result, ToTestDataClass), "Target types must be same")
self.assertEqual(result.name, from_class.name, "Name mapping must be equal")
self.assertEqual(result, ToTestDataClass(a=1, b='2'), "Class instance must be equal")
@dataclass
is a pretty good feature and unfortunatelly is not supported.https://github.com/marazt/object-mapper/blob/9d62e9bf00cd78afdaccd6e950a6bb4a1dd1cc06/mapper/object_mapper.py#L171
Example