-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes author merging and adds tests for author merging (#802)
Fix the merging of authors when a new entry provides a link between existing authors. And add tests for this. Also change author map generation to take a project name instead of a path, to conform with commit_map generation.
- Loading branch information
Showing
2 changed files
with
96 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,33 @@ | ||
import unittest | ||
import unittest.mock as mock | ||
from pathlib import Path | ||
from tempfile import NamedTemporaryFile | ||
|
||
from varats.mapping.author_map import generate_author_map, Author | ||
from varats.project.project_util import get_local_project_git_path | ||
from varats.mapping.author_map import generate_author_map, Author, AuthorMap | ||
from varats.projects.discover_projects import initialize_projects | ||
|
||
|
||
class TestAuthor(unittest.TestCase): | ||
|
||
def test_merge(self) -> None: | ||
author_one = Author(1, "Jon Doe", "jon_doe@jon_doe.com") | ||
author_two = Author(4, "J. Doe", "jon_doe@jon_doe.com") | ||
author_three = Author(2, "Jon Doe", "[email protected]") | ||
merge_one = author_one.merge(author_two) | ||
self.assertEqual(merge_one.author_id, 1) | ||
self.assertEqual(merge_one.names, {"Jon Doe", "J. Doe"}) | ||
self.assertEqual(merge_one.mail_addresses, {"jon_doe@jon_doe.com"}) | ||
merge_two = author_three.merge(author_one) | ||
self.assertEqual(merge_two.author_id, 1) | ||
self.assertEqual(merge_two.names, {"Jon Doe", "J. Doe"}) | ||
self.assertEqual( | ||
merge_two.mail_addresses, | ||
{"jon_doe@jon_doe.com", "[email protected]"} | ||
) | ||
|
||
|
||
class TestAuthorMap(unittest.TestCase): | ||
|
||
def test_get_author_by_email(self) -> None: | ||
initialize_projects() | ||
git_path = get_local_project_git_path("xz") | ||
amap = generate_author_map(git_path) | ||
amap = generate_author_map("xz") | ||
test_author = amap.get_author_by_email("[email protected]") | ||
self.assertEqual( | ||
test_author.mail_addresses, | ||
|
@@ -23,8 +37,7 @@ def test_get_author_by_email(self) -> None: | |
|
||
def test_get_author_by_name(self) -> None: | ||
initialize_projects() | ||
git_path = get_local_project_git_path("xz") | ||
amap = generate_author_map(git_path) | ||
amap = generate_author_map("xz") | ||
test_author = amap.get_author_by_name("Jia Cheong Tan") | ||
self.assertEqual( | ||
test_author.names, {"Jia Cheong Tan", "Jia Tan", "jiat75"} | ||
|
@@ -36,8 +49,7 @@ def test_get_author_by_name(self) -> None: | |
|
||
def test_get_author(self) -> None: | ||
initialize_projects() | ||
git_path = get_local_project_git_path("xz") | ||
amap = generate_author_map(git_path) | ||
amap = generate_author_map("xz") | ||
test_author = amap.get_author("Jia Cheong Tan", "[email protected]") | ||
self.assertEqual( | ||
test_author.names, {"Jia Cheong Tan", "Jia Tan", "jiat75"} | ||
|
@@ -49,26 +61,52 @@ def test_get_author(self) -> None: | |
|
||
def test_get_author_ambiguous(self) -> None: | ||
initialize_projects() | ||
git_path = get_local_project_git_path("xz") | ||
amap = generate_author_map(git_path) | ||
amap = generate_author_map("xz") | ||
self.assertIsNone(amap.get_author("Jia Cheong Tan", "[email protected]")) | ||
|
||
def test_get_author_missing_mail(self) -> None: | ||
initialize_projects() | ||
git_path = get_local_project_git_path("xz") | ||
amap = generate_author_map(git_path) | ||
amap = generate_author_map("xz") | ||
self.assertIsNone( | ||
amap.get_author("Jia Cheong Tan", "[email protected]") | ||
) | ||
|
||
def test_get_author_missing_name(self) -> None: | ||
initialize_projects() | ||
git_path = get_local_project_git_path("xz") | ||
amap = generate_author_map(git_path) | ||
amap = generate_author_map("xz") | ||
self.assertIsNone(amap.get_author("Not Present", "[email protected]")) | ||
|
||
def test_get_author_missing(self) -> None: | ||
initialize_projects() | ||
git_path = get_local_project_git_path("xz") | ||
amap = generate_author_map(git_path) | ||
amap = generate_author_map("xz") | ||
self.assertIsNone(amap.get_author("Not Present", "[email protected]")) | ||
|
||
def test_author_merging(self) -> None: | ||
amap = AuthorMap() | ||
amap.add_entry("Jon Doe", "jon_doe@jon_doe.com") | ||
amap.add_entry("JD", "[email protected]") | ||
amap.add_entry("Jon Doe", "[email protected]") | ||
disambiguated_author = amap.get_author("JD", "jon_doe@jon_doe.com") | ||
self.assertEqual(disambiguated_author.author_id, 0) | ||
self.assertEqual(disambiguated_author.names, {"Jon Doe", "JD"}) | ||
self.assertEqual( | ||
disambiguated_author.mail_addresses, | ||
{"jon_doe@jon_doe.com", "[email protected]"} | ||
) | ||
|
||
def test_author_merging_generate(self) -> None: | ||
initialize_projects() | ||
amap = generate_author_map("brotli") | ||
test_author = amap.get_author("eustas", "[email protected]") | ||
self.assertEqual( | ||
test_author.names, { | ||
"eustas", "Eugene Kliuchnikov", "Eugene Klyuchnikov", | ||
"Evgenii Kliuchnikov" | ||
} | ||
) | ||
self.assertEqual( | ||
test_author.mail_addresses, { | ||
"[email protected]", "[email protected]", | ||
"[email protected]" | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters