|
9 | 9 | from diffsync import Adapter, DiffSyncModel |
10 | 10 | from diffsync.enum import DiffSyncFlags, DiffSyncModelFlags |
11 | 11 | from diffsync.exceptions import DiffClassMismatch, ObjectAlreadyExists, ObjectCrudException, ObjectNotFound |
12 | | -from diffsync.store.local import LocalStore |
13 | 12 |
|
14 | 13 | from .conftest import BackendA, Device, Interface, PersonA, Site, TrackedDiff |
15 | 14 |
|
@@ -1142,129 +1141,3 @@ def test_diffsync_get_initial_value_order(): |
1142 | 1141 | "interface", |
1143 | 1142 | "person", |
1144 | 1143 | ] |
1145 | | - |
1146 | | - |
1147 | | -def test_adapter_new_stores_kwargs(): |
1148 | | - """Test that __new__ stores keyword arguments in _meta_kwargs.""" |
1149 | | - adapter = Adapter(name="test_adapter") |
1150 | | - assert hasattr(adapter, "_meta_kwargs") |
1151 | | - assert adapter._meta_kwargs == {"name": "test_adapter"} # pylint: disable=protected-access |
1152 | | - |
1153 | | - |
1154 | | -def test_adapter_new_with_no_kwargs(): |
1155 | | - """Test that __new__ works with no keyword arguments.""" |
1156 | | - adapter = Adapter() |
1157 | | - assert hasattr(adapter, "_meta_kwargs") |
1158 | | - assert adapter._meta_kwargs == {} # pylint: disable=protected-access |
1159 | | - |
1160 | | - |
1161 | | -def test_adapter_new_with_multiple_kwargs(): |
1162 | | - """Test that __new__ stores multiple keyword arguments.""" |
1163 | | - adapter = Adapter(name="test", internal_storage_engine=LocalStore) |
1164 | | - assert adapter._meta_kwargs == { # pylint: disable=protected-access |
1165 | | - "name": "test", |
1166 | | - "internal_storage_engine": LocalStore, |
1167 | | - } |
1168 | | - |
1169 | | - |
1170 | | -def test_adapter_new_with_subclass(): |
1171 | | - """Test that __new__ works correctly with Adapter subclasses.""" |
1172 | | - adapter = BackendA(name="test_backend") |
1173 | | - assert hasattr(adapter, "_meta_kwargs") # pylint: disable=protected-access |
1174 | | - assert adapter._meta_kwargs == {"name": "test_backend"} # pylint: disable=protected-access |
1175 | | - |
1176 | | - |
1177 | | -def test_adapter_new_independent_instances(): |
1178 | | - """Test that different Adapter instances have independent _meta_kwargs.""" |
1179 | | - adapter1 = Adapter(name="adapter1", internal_storage_engine=LocalStore) |
1180 | | - adapter2 = Adapter(name="adapter2", internal_storage_engine=LocalStore) |
1181 | | - |
1182 | | - assert adapter1._meta_kwargs["name"] == "adapter1" # pylint: disable=protected-access |
1183 | | - assert adapter1._meta_kwargs["internal_storage_engine"] == LocalStore # pylint: disable=protected-access |
1184 | | - assert adapter2._meta_kwargs["name"] == "adapter2" # pylint: disable=protected-access |
1185 | | - assert adapter2._meta_kwargs["internal_storage_engine"] == LocalStore # pylint: disable=protected-access |
1186 | | - |
1187 | | - |
1188 | | -class _AdapterWithExtraKwargs(Adapter): |
1189 | | - """Minimal Adapter subclass that accepts extra kwargs for testing __new__ serialization.""" |
1190 | | - |
1191 | | - def __init__(self, name=None, internal_storage_engine=LocalStore, **kwargs): |
1192 | | - super().__init__(name=name, internal_storage_engine=internal_storage_engine) |
1193 | | - |
1194 | | - |
1195 | | -def test_adapter_new_serializable_objects_are_deep_copied(): |
1196 | | - """Test that serializable objects passed to __new__ are deep-copied into _meta_kwargs.""" |
1197 | | - mutable_config = {"host": "localhost", "port": 5432} |
1198 | | - mutable_list = [1, 2, 3] |
1199 | | - adapter = _AdapterWithExtraKwargs( |
1200 | | - name="test", |
1201 | | - config=mutable_config, |
1202 | | - tags=mutable_list, |
1203 | | - internal_storage_engine=LocalStore, |
1204 | | - ) |
1205 | | - |
1206 | | - # Verify values are stored |
1207 | | - assert adapter._meta_kwargs["config"] == {"host": "localhost", "port": 5432} # pylint: disable=protected-access |
1208 | | - assert adapter._meta_kwargs["tags"] == [1, 2, 3] # pylint: disable=protected-access |
1209 | | - |
1210 | | - # Mutate the original objects - _meta_kwargs should retain the original values (deep copy) |
1211 | | - mutable_config["port"] = 9999 |
1212 | | - mutable_list.append(4) |
1213 | | - |
1214 | | - assert adapter._meta_kwargs["config"] == {"host": "localhost", "port": 5432} # pylint: disable=protected-access |
1215 | | - assert adapter._meta_kwargs["tags"] == [1, 2, 3] # pylint: disable=protected-access |
1216 | | - |
1217 | | - |
1218 | | -def test_adapter_new_non_serializable_type_error_stored_as_is(): |
1219 | | - """Test that objects raising TypeError on deepcopy are stored as-is in _meta_kwargs.""" |
1220 | | - |
1221 | | - class NonCopyableTypeError: |
1222 | | - """Object that raises TypeError when deep-copied (e.g. DB connection, Kafka Consumer).""" |
1223 | | - |
1224 | | - def __deepcopy__(self, memo=None): |
1225 | | - raise TypeError("Cannot deep copy this object") |
1226 | | - |
1227 | | - non_copyable = NonCopyableTypeError() |
1228 | | - adapter = _AdapterWithExtraKwargs(name="test", non_copyable=non_copyable, internal_storage_engine=LocalStore) |
1229 | | - |
1230 | | - assert adapter._meta_kwargs["non_copyable"] is non_copyable # pylint: disable=protected-access |
1231 | | - |
1232 | | - |
1233 | | -def test_adapter_new_non_serializable_attribute_error_stored_as_is(): |
1234 | | - """Test that objects raising AttributeError on deepcopy are stored as-is in _meta_kwargs.""" |
1235 | | - |
1236 | | - class NonCopyableAttributeError: |
1237 | | - """Object that raises AttributeError when deep-copied.""" |
1238 | | - |
1239 | | - def __deepcopy__(self, memo=None): |
1240 | | - raise AttributeError("Cannot deep copy - missing attribute") |
1241 | | - |
1242 | | - non_copyable = NonCopyableAttributeError() |
1243 | | - adapter = _AdapterWithExtraKwargs(name="test", non_copyable=non_copyable, internal_storage_engine=LocalStore) |
1244 | | - |
1245 | | - assert adapter._meta_kwargs["non_copyable"] is non_copyable # pylint: disable=protected-access |
1246 | | - |
1247 | | - |
1248 | | -def test_adapter_new_mixed_serializable_and_non_serializable_kwargs(): |
1249 | | - """Test that __new__ handles mix of serializable and non-serializable kwargs correctly.""" |
1250 | | - |
1251 | | - class NonCopyable: |
1252 | | - def __deepcopy__(self, memo=None): |
1253 | | - raise TypeError("Cannot copy") |
1254 | | - |
1255 | | - serializable_dict = {"key": "value"} |
1256 | | - non_copyable = NonCopyable() |
1257 | | - |
1258 | | - adapter = _AdapterWithExtraKwargs( |
1259 | | - name="test", |
1260 | | - config=serializable_dict, |
1261 | | - connection=non_copyable, |
1262 | | - internal_storage_engine=LocalStore, |
1263 | | - ) |
1264 | | - |
1265 | | - # Serializable: deep-copied (independent copy) |
1266 | | - assert adapter._meta_kwargs["config"] == {"key": "value"} # pylint: disable=protected-access |
1267 | | - assert adapter._meta_kwargs["config"] is not serializable_dict |
1268 | | - |
1269 | | - # Non-serializable: stored by reference |
1270 | | - assert adapter._meta_kwargs["connection"] is non_copyable # pylint: disable=protected-access |
0 commit comments