Skip to content

Commit 2551571

Browse files
[bct] Add specific messages for enums in the changelog (Azure#37216)
* add enum specific messages for changelog * add test * nit remove comment --------- Co-authored-by: Catalina Peralta <[email protected]>
1 parent 6b5ce2d commit 2551571

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

scripts/breaking_changes_checker/changelog_tracker.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class ChangeType(str, Enum):
1818
ADDED_CLASS_METHOD = "AddedClassMethod"
1919
ADDED_CLASS_METHOD_PARAMETER = "AddedClassMethodParameter"
2020
ADDED_CLASS_PROPERTY = "AddedClassProperty"
21+
ADDED_ENUM = "AddedEnum"
22+
ADDED_ENUM_MEMBER = "AddedEnumMember"
2123
ADDED_FUNCTION_PARAMETER = "AddedFunctionParameter"
2224
ADDED_OPERATION_GROUP = "AddedOperationGroup"
2325

@@ -36,6 +38,10 @@ class ChangelogTracker(BreakingChangesTracker):
3638
"Function `{}` added parameter `{}`"
3739
ADDED_CLASS_PROPERTY_MSG = \
3840
"Model `{}` added property `{}`"
41+
ADDED_ENUM_MSG = \
42+
"Added enum `{}`"
43+
ADDED_ENUM_MEMBER_MSG = \
44+
"Enum `{}` added member `{}`"
3945
ADDED_OPERATION_GROUP_MSG = \
4046
"Client `{}` added operation group `{}`"
4147

@@ -71,6 +77,14 @@ def run_non_breaking_class_level_diff_checks(self, module: Dict) -> None:
7177
self.module_name, class_name
7278
)
7379
self.features_added.append(fa)
80+
elif class_components.get("type", None) == "Enum":
81+
# This is a new enum
82+
fa = (
83+
self.ADDED_ENUM_MSG,
84+
ChangeType.ADDED_ENUM,
85+
self.module_name, class_name
86+
)
87+
self.features_added.append(fa)
7488
else:
7589
# This is a new class
7690
fa = (
@@ -135,6 +149,12 @@ def run_non_breaking_class_level_diff_checks(self, module: Dict) -> None:
135149
ChangeType.ADDED_OPERATION_GROUP,
136150
self.module_name, self.class_name, property_name
137151
)
152+
if stable_class_nodes[self.class_name]["type"] == "Enum":
153+
fa = (
154+
self.ADDED_ENUM_MEMBER_MSG,
155+
ChangeType.ADDED_ENUM_MEMBER,
156+
self.module_name, class_name, property_name
157+
)
138158
self.features_added.append(fa)
139159

140160

scripts/breaking_changes_checker/tests/test_changelog.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def test_new_class_property_added():
3232
"azure.ai.contentsafety": {
3333
"class_nodes": {
3434
"AnalyzeTextResult": {
35+
"type": None,
3536
"methods": {},
3637
"properties": {
3738
"blocklists_match": "Optional",
@@ -47,6 +48,7 @@ def test_new_class_property_added():
4748
"azure.ai.contentsafety": {
4849
"class_nodes": {
4950
"AnalyzeTextResult": {
51+
"type": None,
5052
"methods": {},
5153
"properties": {
5254
"blocklists_match": "Optional",
@@ -144,6 +146,7 @@ def test_new_class_property_added_init():
144146
"azure.ai.contentsafety": {
145147
"class_nodes": {
146148
"AnalyzeTextResult": {
149+
"type": None,
147150
"methods": {
148151
"__init__": {
149152
"parameters": {
@@ -177,6 +180,7 @@ def test_new_class_property_added_init():
177180
"azure.ai.contentsafety": {
178181
"class_nodes": {
179182
"AnalyzeTextResult": {
183+
"type": None,
180184
"methods": {
181185
"__init__": {
182186
"parameters": {
@@ -390,6 +394,7 @@ def test_added_operation_group():
390394
"azure.contoso": {
391395
"class_nodes": {
392396
"ContosoClient": {
397+
"type": None,
393398
"methods": {},
394399
"properties": {
395400
"bar": {
@@ -405,6 +410,7 @@ def test_added_operation_group():
405410
"azure.contoso": {
406411
"class_nodes": {
407412
"ContosoClient": {
413+
"type": None,
408414
"methods": {},
409415
"properties": {
410416
"bar": {
@@ -438,6 +444,7 @@ def test_ignore_changes():
438444
"azure.contoso": {
439445
"class_nodes": {
440446
"ContosoClient": {
447+
"type": None,
441448
"methods": {},
442449
"properties": {
443450
"bar": {
@@ -453,6 +460,7 @@ def test_ignore_changes():
453460
"azure.contoso": {
454461
"class_nodes": {
455462
"ContosoClient": {
463+
"type": None,
456464
"methods": {},
457465
"properties": {
458466
"bar": {
@@ -497,3 +505,53 @@ def test_async_features_added_cleanup():
497505
assert len(ct.features_added) == 2
498506
assert ct.features_added[0] == ("Message", "AddedClient", "azure.contoso", "FooClient", "foo")
499507
assert ct.features_added[1] == ("Message", "AddedClassMethod", "azure.contoso", "FooClient", "from_connection_string")
508+
509+
510+
def test_new_enum_added():
511+
current = {
512+
"azure.contoso.widgetmanager": {
513+
"class_nodes": {
514+
"WidgetEnum": {
515+
"type": "Enum",
516+
"methods": {},
517+
"properties": {
518+
"a": "a",
519+
"b": "b",
520+
}
521+
},
522+
"ManagerEnum": {
523+
"type": "Enum",
524+
"methods": {},
525+
"properties": {
526+
"foo": "foo",
527+
"bar": "bar",
528+
}
529+
},
530+
}
531+
}
532+
}
533+
534+
stable = {
535+
"azure.contoso.widgetmanager": {
536+
"class_nodes": {
537+
"ManagerEnum": {
538+
"type": "Enum",
539+
"methods": {},
540+
"properties": {
541+
"foo": "foo",
542+
}
543+
},
544+
}
545+
}
546+
}
547+
548+
bc = ChangelogTracker(stable, current, "azure-contoso-widgetmanager")
549+
bc.run_checks()
550+
551+
assert len(bc.features_added) == 2
552+
msg, _, *args = bc.features_added[0]
553+
assert msg == ChangelogTracker.ADDED_ENUM_MEMBER_MSG
554+
assert args == ['azure.contoso.widgetmanager', 'ManagerEnum', 'bar']
555+
msg, _, *args = bc.features_added[1]
556+
assert msg == ChangelogTracker.ADDED_ENUM_MSG
557+
assert args == ['azure.contoso.widgetmanager', 'WidgetEnum']

0 commit comments

Comments
 (0)