From e9aa7d99094de5a3f8be80365ff308e9b81f2da2 Mon Sep 17 00:00:00 2001 From: Lucky Sivagurunathan <25218389+luckyvs1@users.noreply.github.com> Date: Fri, 10 Jul 2020 12:54:44 -0700 Subject: [PATCH] Add tests for the repository.get_commits function (#1674) Fixes #383 --- tests/fixtures/commits.json | 5 +++ tests/test_repository.py | 76 +++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/tests/fixtures/commits.json b/tests/fixtures/commits.json index 56393bdd..4cd34b4e 100644 --- a/tests/fixtures/commits.json +++ b/tests/fixtures/commits.json @@ -3,3 +3,8 @@ {"author": "Kearwood \"Kip\" Gilbert ", "desc": "Bug 1389220 - Prevent navigator.activeVRDisplays from activating VR hardware and runtimes r=daoshengmu\n\nMozReview-Commit-ID: JYMiGyT0iVY", "date": "2017-09-20 22:39:35", "pushdate": "2017-09-21 13:14:27", "bug_id": 1389220, "backedoutby": "", "added": 8, "test_added": 0, "deleted": 3, "test_deleted": 0, "files_modified_num": 1, "types": ["C/C++"], "components": ["Core::DOM: Core & HTML"], "author_experience": 7, "author_experience_90_days": 7, "author_email": "kgilbert@mozilla.com", "node": "b37909c3b506a2196d9e7c41c8f72e23b15eb3c9", "ignored": false, "backsout": []} {"author": "Mike Hommey ", "desc": "Bug 1488307 - Build the LLVM gold plugin. r=mshal\n\nAs much as it's tempting to use LLD for LTO, it still causes some\nsubtle problems with the build, and it's still better to keep using\nBFD ld for the time being. Doing so requires the gold plugin, which\nonly requires to pass cmake the directory where the binutils headers\nare, and they are part of the gcc toolchain headers.\n\nDifferential Revision: https://phabricator.services.mozilla.com/D4896", "date": "2018-08-30 01:55:49", "pushdate": "2018-09-05 09:45:59", "bug_id": 1488307, "backedoutby": "", "added": 2, "test_added": 0, "deleted": 0, "test_deleted": 0, "files_modified_num": 1, "types": ["Python"], "components": ["Firefox Build System::General"], "author_experience": 1147, "author_experience_90_days": 125, "author_email": "mh+mozilla@glandium.org", "node": "e2a02b08089b0bd0c18ceac0b2eb1e3888d56dc2", "ignored": false, "backsout": []} {"author": "Mike Hommey ", "desc": "Bug 1488307 - Build the LLVM gold plugin. r=mshal\n\nAs much as it's tempting to use LLD for LTO, it still causes some\nsubtle problems with the build, and it's still better to keep using\nBFD ld for the time being. Doing so requires the gold plugin, which\nonly requires to pass cmake the directory where the binutils headers\nare, and they are part of the gcc toolchain headers.\n\nDifferential Revision: https://phabricator.services.mozilla.com/D4896", "date": "2018-08-30 01:55:49", "pushdate": "2018-09-05 09:45:59", "bug_id": 1488307, "backedoutby": "faba20592c04ce934cabf0284168733eb48baac0", "added": 2, "test_added": 0, "deleted": 0, "test_deleted": 0, "files_modified_num": 1, "types": ["Python"], "components": ["Firefox Build System::General"], "author_experience": 1148, "author_experience_90_days": 126, "author_email": "mh+mozilla@glandium.org", "node": "c2b5cf7bde83db072fc206c24d1cab72354be727", "ignored": false, "backsout": []} +{"author": "Csoregi Natalia ", "desc": "Bug 1631018", "date": "2020-06-04 21:34:51", "pushdate": "2020-06-04 21:34:51", "bug_id": 1631018, "backedoutby": "", "added": 2, "test_added": 0, "deleted": 0, "test_deleted": 0, "files_modified_num": 1, "types": ["Python"], "components": ["Firefox Build System::General"], "author_experience": 1148, "author_experience_90_days": 126, "author_email": "ncsoregi@mozilla.com", "node": "ec01c146f756b74d18e4892b4fd3aecba00da93e", "ignored": false, "backsout": ["7f27080ffee35521c42fe9d4025caabef7b6258c","11f135d60922e74b71819223f1b1321ccca015a6"]} +{"author": "Rob Wu ", "desc": "Bug 1631018", "date": "2020-06-04 21:34:51", "pushdate": "2020-06-04 21:34:51", "bug_id": 1631018, "backedoutby": "", "added": 2, "test_added": 0, "deleted": 0, "test_deleted": 0, "files_modified_num": 1, "types": ["Python"], "components": ["Firefox Build System::General"], "author_experience": 1148, "author_experience_90_days": 126, "author_email": "rob@robwu.nl", "node": "7f27080ffee35521c42fe9d4025caabef7b6258c", "ignored": true, "backsout": []} +{"author": "Hiroyuki Ikezoe ", "desc": "", "date": "2020-06-05 09:53:51", "pushdate": "2020-06-05 09:53:51", "bug_id": null, "backedoutby": "", "added": 2, "test_added": 0, "deleted": 0, "test_deleted": 0, "files_modified_num": 1, "types": ["Python"], "components": ["Firefox Build System::General"], "author_experience": 1148, "author_experience_90_days": 126, "author_email": "hikezoe.birchill@mozilla.com", "node": "75966ee1fe658b1767d7459256175c0662d14c25", "ignored": false, "backsout": []} +{"author": "Johann Hofmann ", "desc": "", "date": "2020-06-05 10:53:51", "pushdate": "2020-06-05 10:53:51", "bug_id": null, "backedoutby": "", "added": 2, "test_added": 0, "deleted": 0, "test_deleted": 0, "files_modified_num": 1, "types": ["Python"], "components": ["Firefox Build System::General"], "author_experience": 1148, "author_experience_90_days": 126, "author_email": "jhofmann@mozilla.com", "node": "75276e64701bfde7cf2dd1f851adfea6a92d5747", "ignored": true, "backsout": []} +{"author": "Razvan Maries ", "desc": "", "date": "2020-06-04 09:53:51", "pushdate": "2020-06-04 09:53:51", "bug_id": null, "backedoutby": "", "added": 2, "test_added": 0, "deleted": 0, "test_deleted": 0, "files_modified_num": 1, "types": ["Python"], "components": ["Firefox Build System::General"], "author_experience": 1148, "author_experience_90_days": 126, "author_email": "rmaries@mozilla.com", "node": "46c1c161cbe189a59d8274e011085d76163db7f4", "ignored": true, "backsout": ["10c9e57fb4f8c70d4772a7809ba3d652536b984d"]} \ No newline at end of file diff --git a/tests/test_repository.py b/tests/test_repository.py index b8f1f6db..732c4b09 100644 --- a/tests/test_repository.py +++ b/tests/test_repository.py @@ -1770,3 +1770,79 @@ function inner_func() { touched_functions = repository.get_touched_functions(metrics["spaces"], [], [4],) assert touched_functions == {("outer_func", 1, 6), ("inner_func", 3, 5)} + + +def test_get_commits(): + # By default get_commits utilizes the following parameters: + # include_no_bug: bool = False + # include_backouts: bool = False + # include_ignored: bool = False + + BACKOUT_COMMIT = "ec01c146f756b74d18e4892b4fd3aecba00da93e" + IGNORED_COMMIT = "7f27080ffee35521c42fe9d4025caabef7b6258c" + NOBUG_COMMIT = "75966ee1fe658b1767d7459256175c0662d14c25" + NOBUG_IGNORED_COMMIT = "75276e64701bfde7cf2dd1f851adfea6a92d5747" + NOBUG_IGNORED_BACKOUT_COMMIT = "46c1c161cbe189a59d8274e011085d76163db7f4" + + retrieved_commits = list(repository.get_commits()) + excluded_commits = [ + IGNORED_COMMIT, + BACKOUT_COMMIT, + NOBUG_COMMIT, + NOBUG_IGNORED_COMMIT, + NOBUG_IGNORED_BACKOUT_COMMIT, + ] + # 10 mock commits, 1 ignored, 1 backouts, 1 no_bug, 1 no_bug and ignored, 1 no_bug, ignored, and backouts + assert len(retrieved_commits) == 5 + assert not any( + excluded_commit in {c["node"] for c in retrieved_commits} + for excluded_commit in excluded_commits + ) + + retrieved_commits = list(repository.get_commits(include_backouts=True)) + assert len(retrieved_commits) == 6 + assert BACKOUT_COMMIT in (c["node"] for c in retrieved_commits) + + retrieved_commits = list(repository.get_commits(include_ignored=True)) + assert len(retrieved_commits) == 6 + assert IGNORED_COMMIT in (c["node"] for c in retrieved_commits) + + retrieved_commits = list(repository.get_commits(include_no_bug=True)) + assert len(retrieved_commits) == 6 + assert NOBUG_COMMIT in (c["node"] for c in retrieved_commits) + + retrieved_commits = list( + repository.get_commits(include_ignored=True, include_backouts=True) + ) + included_commits = {IGNORED_COMMIT, BACKOUT_COMMIT} + assert len(retrieved_commits) == 7 + assert included_commits.issubset({c["node"] for c in retrieved_commits}) + + retrieved_commits = list( + repository.get_commits(include_ignored=True, include_no_bug=True) + ) + included_commits = {IGNORED_COMMIT, NOBUG_COMMIT} + assert len(retrieved_commits) == 8 + assert included_commits.issubset({c["node"] for c in retrieved_commits}) + + retrieved_commits = list( + repository.get_commits(include_no_bug=True, include_backouts=True) + ) + included_commits = {BACKOUT_COMMIT, NOBUG_COMMIT} + assert len(retrieved_commits) == 7 + assert included_commits.issubset({c["node"] for c in retrieved_commits}) + + retrieved_commits = list( + repository.get_commits( + include_ignored=True, include_backouts=True, include_no_bug=True + ) + ) + included_commits = { + IGNORED_COMMIT, + BACKOUT_COMMIT, + NOBUG_COMMIT, + NOBUG_IGNORED_COMMIT, + NOBUG_IGNORED_BACKOUT_COMMIT, + } + assert len(retrieved_commits) == 10 + assert included_commits.issubset({c["node"] for c in retrieved_commits})