@@ -132,13 +132,12 @@ def test_diffsync_remove_with_generic_model(generic_diffsync, generic_diffsync_m
132
132
generic_diffsync .get_by_uids (["" ], DiffSyncModel )
133
133
134
134
135
- def test_diffsync_subclass_validation ():
136
- """Test the declaration-time checks on a DiffSync subclass."""
135
+ def test_diffsync_subclass_validation_name_mismatch ():
137
136
# pylint: disable=unused-variable
138
137
with pytest .raises (AttributeError ) as excinfo :
139
138
140
139
class BadElementName (DiffSync ):
141
- """Model with a DiffSyncModel attribute whose name does not match the modelname."""
140
+ """DiffSync with a DiffSyncModel attribute whose name does not match the modelname."""
142
141
143
142
dev_class = Device # should be device = Device
144
143
@@ -147,6 +146,33 @@ class BadElementName(DiffSync):
147
146
assert "dev_class" in str (excinfo .value )
148
147
149
148
149
+ def test_diffsync_subclass_validation_missing_top_level ():
150
+ with pytest .raises (AttributeError ) as excinfo :
151
+
152
+ class MissingTopLevel (DiffSync ):
153
+ """DiffSync whose top_level references an attribute that does not exist on the class."""
154
+
155
+ top_level = ["missing" ]
156
+
157
+ assert "top_level" in str (excinfo .value )
158
+ assert "missing" in str (excinfo .value )
159
+ assert "is not a class attribute" in str (excinfo .value )
160
+
161
+
162
+ def test_diffsync_subclass_validation_top_level_not_diffsyncmodel ():
163
+ with pytest .raises (AttributeError ) as excinfo :
164
+
165
+ class TopLevelNotDiffSyncModel (DiffSync ):
166
+ """DiffSync whose top_level references an attribute that is not a DiffSyncModel subclass."""
167
+
168
+ age = 0
169
+ top_level = ["age" ]
170
+
171
+ assert "top_level" in str (excinfo .value )
172
+ assert "age" in str (excinfo .value )
173
+ assert "is not a DiffSyncModel" in str (excinfo .value )
174
+
175
+
150
176
def test_diffsync_dict_with_data (backend_a ):
151
177
assert backend_a .dict () == {
152
178
"device" : {
@@ -250,7 +276,9 @@ def test_diffsync_str_with_data(backend_a):
250
276
interface: rdu-spine2__eth0: {'interface_type': 'ethernet', 'description': 'Interface 0'}
251
277
interface: rdu-spine2__eth1: {'interface_type': 'ethernet', 'description': 'Interface 1'}
252
278
people
253
- person: Glenn Matthews: {}"""
279
+ person: Glenn Matthews: {}
280
+ unused: []\
281
+ """
254
282
)
255
283
256
284
0 commit comments