Skip to content

Commit ad953cd

Browse files
[bct] Internal tracker clean up (Azure#37063)
* move diff call to init * underscore for properties that shouldnt be used on the tracker * more clean up * fix tests and changelogtracker * fix tests --------- Co-authored-by: Catalina Peralta <[email protected]>
1 parent 4487087 commit ad953cd

File tree

6 files changed

+126
-142
lines changed

6 files changed

+126
-142
lines changed

scripts/breaking_changes_checker/breaking_changes_tracker.py

Lines changed: 90 additions & 90 deletions
Large diffs are not rendered by default.

scripts/breaking_changes_checker/changelog_tracker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ class ChangelogTracker(BreakingChangesTracker):
4040
"Client '{}' added operation group '{}'"
4141

4242

43-
def __init__(self, stable: Dict, current: Dict, diff: Dict, package_name: str, **kwargs: Any) -> None:
44-
super().__init__(stable, current, diff, package_name, **kwargs)
43+
def __init__(self, stable: Dict, current: Dict, package_name: str, **kwargs: Any) -> None:
44+
super().__init__(stable, current, package_name, **kwargs)
4545
self.features_added = []
4646

4747
def run_checks(self) -> None:

scripts/breaking_changes_checker/detect_breaking_changes.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from breaking_changes_tracker import BreakingChangesTracker
2626
from changelog_tracker import ChangelogTracker
2727
from pathlib import Path
28-
from checkers.method_overloads_checker import MethodOverloadsChecker
28+
from supported_checkers import CHECKERS
2929

3030
root_dir = os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "..", ".."))
3131
_LOGGER = logging.getLogger(__name__)
@@ -445,18 +445,9 @@ def test_compare_reports(pkg_dir: str, changelog: bool, source_report: str = "st
445445
stable = report_azure_mgmt_versioned_module(stable)
446446
current = report_azure_mgmt_versioned_module(current)
447447

448-
diff = jsondiff.diff(stable, current)
449-
checker = BreakingChangesTracker(
450-
stable,
451-
current,
452-
diff, # TODO in preparation for generic trackers, the diff can be created during init
453-
package_name,
454-
checkers = [
455-
MethodOverloadsChecker(),
456-
]
457-
)
448+
checker = BreakingChangesTracker(stable, current, package_name, checkers = CHECKERS)
458449
if changelog:
459-
checker = ChangelogTracker(stable, current, diff, package_name)
450+
checker = ChangelogTracker(stable, current, package_name, checkers = CHECKERS)
460451
checker.run_checks()
461452

462453
remove_json_files(pkg_dir)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env python
2+
3+
# --------------------------------------------------------------------------------------------
4+
# Copyright (c) Microsoft Corporation. All rights reserved.
5+
# Licensed under the MIT License. See License.txt in the project root for license information.
6+
# --------------------------------------------------------------------------------------------
7+
8+
from checkers.method_overloads_checker import MethodOverloadsChecker
9+
10+
CHECKERS = [
11+
MethodOverloadsChecker(),
12+
]

scripts/breaking_changes_checker/tests/test_breaking_changes.py

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import os
99
import json
10-
import jsondiff
1110
import pytest
1211
from breaking_changes_checker.breaking_changes_tracker import BreakingChangesTracker
1312
from breaking_changes_checker.detect_breaking_changes import main
@@ -51,9 +50,8 @@ def test_multiple_checkers():
5150
stable = json.load(fd)
5251
with open(os.path.join(os.path.dirname(__file__), "test_current.json"), "r") as fd:
5352
current = json.load(fd)
54-
diff = jsondiff.diff(stable, current)
5553

56-
bc = BreakingChangesTracker(stable, current, diff, "azure-storage-queue")
54+
bc = BreakingChangesTracker(stable, current, "azure-storage-queue")
5755
bc.run_checks()
5856

5957
changes = bc.report_changes()
@@ -68,15 +66,14 @@ def test_ignore_checks():
6866
stable = json.load(fd)
6967
with open(os.path.join(os.path.dirname(__file__), "test_current.json"), "r") as fd:
7068
current = json.load(fd)
71-
diff = jsondiff.diff(stable, current)
7269

7370
ignore = {
7471
"azure-storage-queue": [
7572
("ChangedParameterOrdering", "*", "QueueClient", "from_connection_string"),
7673
]
7774
}
7875

79-
bc = BreakingChangesTracker(stable, current, diff, "azure-storage-queue", ignore=ignore)
76+
bc = BreakingChangesTracker(stable, current, "azure-storage-queue", ignore=ignore)
8077
bc.run_checks()
8178

8279
changes = bc.report_changes()
@@ -91,7 +88,6 @@ def test_ignore_with_wildcard_checks():
9188
stable = json.load(fd)
9289
with open(os.path.join(os.path.dirname(__file__), "test_current.json"), "r") as fd:
9390
current = json.load(fd)
94-
diff = jsondiff.diff(stable, current)
9591

9692
ignore = {
9793
"azure-storage-queue": [
@@ -100,7 +96,7 @@ def test_ignore_with_wildcard_checks():
10096
]
10197
}
10298

103-
bc = BreakingChangesTracker(stable, current, diff, "azure-storage-queue", ignore=ignore)
99+
bc = BreakingChangesTracker(stable, current, "azure-storage-queue", ignore=ignore)
104100
bc.run_checks()
105101

106102
changes = bc.report_changes()
@@ -187,8 +183,7 @@ def test_replace_all_params():
187183
"(RemovedOrRenamedPositionalParam): 'my_function_name' function deleted or renamed its parameter 'testing2' of kind 'positional_or_keyword'"
188184
]
189185

190-
diff = jsondiff.diff(stable, current)
191-
bc = BreakingChangesTracker(stable, current, diff, "azure-storage-queue")
186+
bc = BreakingChangesTracker(stable, current, "azure-storage-queue")
192187
bc.run_checks()
193188

194189
changes = bc.report_changes()
@@ -275,8 +270,7 @@ def test_replace_all_functions():
275270
"(RemovedOrRenamedModuleLevelFunction): Deleted or renamed function 'my_function_name2'"
276271
]
277272

278-
diff = jsondiff.diff(stable, current)
279-
bc = BreakingChangesTracker(stable, current, diff, "azure-storage-queue")
273+
bc = BreakingChangesTracker(stable, current, "azure-storage-queue")
280274
bc.run_checks()
281275

282276
changes = bc.report_changes()
@@ -349,8 +343,7 @@ def test_replace_all_classes():
349343
"(RemovedOrRenamedClass): Deleted or renamed model 'class_name2'"
350344
]
351345

352-
diff = jsondiff.diff(stable, current)
353-
bc = BreakingChangesTracker(stable, current, diff, "azure-storage-queue")
346+
bc = BreakingChangesTracker(stable, current, "azure-storage-queue")
354347
bc.run_checks()
355348

356349
changes = bc.report_changes()
@@ -376,8 +369,7 @@ def test_replace_all_modules():
376369
"(RemovedOrRenamedModule): Deleted or renamed module 'azure.ai.formrecognizer'",
377370
]
378371

379-
diff = jsondiff.diff(stable, current)
380-
bc = BreakingChangesTracker(stable, current, diff, "azure-storage-queue")
372+
bc = BreakingChangesTracker(stable, current, "azure-storage-queue")
381373
bc.run_checks()
382374

383375
changes = bc.report_changes()
@@ -433,8 +425,7 @@ def test_removed_operation_group():
433425
"(RemovedOrRenamedOperationGroup): Deleted or renamed client operation group 'ContosoClient.foo'"
434426
]
435427

436-
diff = jsondiff.diff(stable, current)
437-
bc = BreakingChangesTracker(stable, current, diff, "azure-storage-queue")
428+
bc = BreakingChangesTracker(stable, current, "azure-storage-queue")
438429
bc.run_checks()
439430

440431
changes = bc.report_changes()
@@ -452,7 +443,7 @@ def test_async_breaking_changes_cleanup():
452443
]
453444

454445
# create dummy BreakingChangesTracker instance
455-
bct = BreakingChangesTracker({}, {}, {}, "azure-contoso")
446+
bct = BreakingChangesTracker({}, {}, "azure-contoso")
456447
bct.breaking_changes = breaking_changes
457448

458449
bct.run_async_cleanup(bct.breaking_changes)
@@ -577,8 +568,7 @@ def test_removed_overload():
577568
"(RemovedMethodOverload): class_name.two had all overloads removed"
578569
]
579570

580-
diff = jsondiff.diff(stable, current)
581-
bc = BreakingChangesTracker(stable, current, diff, "azure-contoso", checkers=[MethodOverloadsChecker()])
571+
bc = BreakingChangesTracker(stable, current, "azure-contoso", checkers=[MethodOverloadsChecker()])
582572
bc.run_checks()
583573

584574
changes = bc.report_changes()

scripts/breaking_changes_checker/tests/test_changelog.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import os
99
import json
10-
import jsondiff
1110
import pytest
1211
from breaking_changes_checker.changelog_tracker import ChangelogTracker, BreakingChangesTracker
1312
from breaking_changes_checker.detect_breaking_changes import main
@@ -18,9 +17,8 @@ def test_changelog_flag():
1817
stable = json.load(fd)
1918
with open(os.path.join(os.path.dirname(__file__), "examples", "code-reports", "content-safety", "current.json"), "r") as fd:
2019
current = json.load(fd)
21-
diff = jsondiff.diff(stable, current)
2220

23-
bc = ChangelogTracker(stable, current, diff, "azure-ai-contentsafety")
21+
bc = ChangelogTracker(stable, current, "azure-ai-contentsafety")
2422
bc.run_checks()
2523

2624
assert len(bc.features_added) > 0
@@ -59,8 +57,7 @@ def test_new_class_property_added():
5957
}
6058
}
6159

62-
diff = jsondiff.diff(stable, current)
63-
bc = ChangelogTracker(stable, current, diff, "azure-ai-contentsafety")
60+
bc = ChangelogTracker(stable, current, "azure-ai-contentsafety")
6461
bc.run_checks()
6562

6663
assert len(bc.features_added) == 1
@@ -128,8 +125,7 @@ def test_async_cleanup_check():
128125
}
129126
}
130127

131-
diff = jsondiff.diff(stable, current)
132-
bc = ChangelogTracker(stable, current, diff, "azure-mgmt-contentsafety")
128+
bc = ChangelogTracker(stable, current, "azure-mgmt-contentsafety")
133129
bc.run_checks()
134130

135131
# Should only have 1 breaking change reported instead of 2
@@ -209,8 +205,7 @@ def test_new_class_property_added_init():
209205
}
210206
}
211207

212-
diff = jsondiff.diff(stable, current)
213-
bc = ChangelogTracker(stable, current, diff, "azure-ai-contentsafety")
208+
bc = ChangelogTracker(stable, current, "azure-ai-contentsafety")
214209
bc.run_checks()
215210

216211
assert len(bc.features_added) == 1
@@ -281,8 +276,7 @@ def test_new_class_property_added_init_only():
281276
}
282277
}
283278

284-
diff = jsondiff.diff(stable, current)
285-
bc = ChangelogTracker(stable, current, diff, "azure-ai-contentsafety")
279+
bc = ChangelogTracker(stable, current, "azure-ai-contentsafety")
286280
bc.run_checks()
287281

288282
assert len(bc.features_added) == 1
@@ -370,8 +364,7 @@ def test_new_class_method_parameter_added():
370364
}
371365
}
372366

373-
diff = jsondiff.diff(stable, current)
374-
bc = ChangelogTracker(stable, current, diff, "azure-ai-contentsafety")
367+
bc = ChangelogTracker(stable, current, "azure-ai-contentsafety")
375368
bc.run_checks()
376369

377370
assert len(bc.features_added) == 1
@@ -429,8 +422,7 @@ def test_added_operation_group():
429422
}
430423
}
431424

432-
diff = jsondiff.diff(stable, current)
433-
bc = ChangelogTracker(stable, current, diff, "azure-contoso")
425+
bc = ChangelogTracker(stable, current, "azure-contoso")
434426
bc.run_checks()
435427

436428
assert len(bc.features_added) == 2
@@ -481,8 +473,7 @@ def test_ignore_changes():
481473
IGNORE = {
482474
"azure-contoso": [("AddedOperationGroup", "*", "ContosoClient", "foo")]
483475
}
484-
diff = jsondiff.diff(stable, current)
485-
bc = ChangelogTracker(stable, current, diff, "azure-contoso", ignore=IGNORE)
476+
bc = ChangelogTracker(stable, current, "azure-contoso", ignore=IGNORE)
486477
bc.run_checks()
487478
bc.report_changes()
488479
assert len(bc.features_added) == 1
@@ -498,7 +489,7 @@ def test_async_features_added_cleanup():
498489
]
499490

500491
# create dummy BreakingChangesTracker instance
501-
ct = ChangelogTracker({}, {}, {}, "azure-contoso")
492+
ct = ChangelogTracker({}, {}, "azure-contoso")
502493
ct.features_added = features_added
503494

504495
ct.run_async_cleanup(ct.features_added)

0 commit comments

Comments
 (0)