|
8 | 8 |
|
9 | 9 | from diffsync import Adapter, DiffSyncModel |
10 | 10 | from diffsync.enum import DiffSyncFlags, DiffSyncModelFlags |
11 | | -from diffsync.exceptions import DiffClassMismatch, ObjectAlreadyExists, ObjectNotFound, ObjectCrudException |
| 11 | +from diffsync.exceptions import DiffClassMismatch, ObjectAlreadyExists, ObjectCrudException, ObjectNotFound |
| 12 | +from diffsync.store.local import LocalStore |
12 | 13 |
|
13 | | -from .conftest import Site, Device, Interface, TrackedDiff, BackendA, PersonA |
| 14 | +from .conftest import BackendA, Device, Interface, PersonA, Site, TrackedDiff |
14 | 15 |
|
15 | 16 |
|
16 | 17 | def test_diffsync_default_name_type(generic_adapter): |
@@ -1141,3 +1142,44 @@ def test_diffsync_get_initial_value_order(): |
1141 | 1142 | "interface", |
1142 | 1143 | "person", |
1143 | 1144 | ] |
| 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"} |
| 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 == {} |
| 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 == { |
| 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") |
| 1174 | + assert adapter._meta_kwargs == {"name": "test_backend"} |
| 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" |
| 1183 | + assert adapter1._meta_kwargs["internal_storage_engine"] == LocalStore |
| 1184 | + assert adapter2._meta_kwargs["name"] == "adapter2" |
| 1185 | + assert adapter2._meta_kwargs["internal_storage_engine"] == LocalStore |
0 commit comments