@@ -132,13 +132,12 @@ def test_diffsync_remove_with_generic_model(generic_diffsync, generic_diffsync_m
132132 generic_diffsync .get_by_uids (["" ], DiffSyncModel )
133133
134134
135- def test_diffsync_subclass_validation ():
136- """Test the declaration-time checks on a DiffSync subclass."""
135+ def test_diffsync_subclass_validation_name_mismatch ():
137136 # pylint: disable=unused-variable
138137 with pytest .raises (AttributeError ) as excinfo :
139138
140139 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."""
142141
143142 dev_class = Device # should be device = Device
144143
@@ -147,6 +146,33 @@ class BadElementName(DiffSync):
147146 assert "dev_class" in str (excinfo .value )
148147
149148
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+
150176def test_diffsync_dict_with_data (backend_a ):
151177 assert backend_a .dict () == {
152178 "device" : {
@@ -250,7 +276,9 @@ def test_diffsync_str_with_data(backend_a):
250276 interface: rdu-spine2__eth0: {'interface_type': 'ethernet', 'description': 'Interface 0'}
251277 interface: rdu-spine2__eth1: {'interface_type': 'ethernet', 'description': 'Interface 1'}
252278 people
253- person: Glenn Matthews: {}"""
279+ person: Glenn Matthews: {}
280+ unused: []\
281+ """
254282 )
255283
256284
0 commit comments