|
| 1 | +import pkginfo |
| 2 | +import pytest |
| 3 | + |
| 4 | +from ..fetch_description import _enhance_author_maintainer_info |
| 5 | + |
| 6 | + |
| 7 | +@pytest.mark.parametrize( |
| 8 | + [ |
| 9 | + "author", |
| 10 | + "author_email", |
| 11 | + "maintainer", |
| 12 | + "maintainer_email", |
| 13 | + "expected_author", |
| 14 | + "expected_maintainer", |
| 15 | + ], |
| 16 | + [ |
| 17 | + # Test extracting author from email when no author |
| 18 | + (None, "John Doe <[email protected]>", None, None, "John Doe", None), |
| 19 | + # Test extracting maintainer from email when no maintainer |
| 20 | + (None, None, None, "Jane Smith <[email protected]>", None, "Jane Smith"), |
| 21 | + # Test extracting both author and maintainer |
| 22 | + ( |
| 23 | + None, |
| 24 | + |
| 25 | + None, |
| 26 | + |
| 27 | + "John Doe", |
| 28 | + "Jane Smith", |
| 29 | + ), |
| 30 | + # Test preserving existing author name |
| 31 | + ( |
| 32 | + "Existing Author", |
| 33 | + |
| 34 | + None, |
| 35 | + None, |
| 36 | + "Existing Author", |
| 37 | + None, |
| 38 | + ), |
| 39 | + # Test preserving existing maintainer name |
| 40 | + ( |
| 41 | + None, |
| 42 | + None, |
| 43 | + "Existing Maintainer", |
| 44 | + |
| 45 | + None, |
| 46 | + "Existing Maintainer", |
| 47 | + ), |
| 48 | + # Test handling empty author email |
| 49 | + (None, "", None, None, None, None), |
| 50 | + # Test handling None author email |
| 51 | + (None, None, None, None, None, None), |
| 52 | + # Test handling multiple emails |
| 53 | + ( |
| 54 | + None, |
| 55 | + |
| 56 | + None, |
| 57 | + None, |
| 58 | + "John Doe, Jane Smith", |
| 59 | + None, |
| 60 | + ), |
| 61 | + # Test handling email without display name |
| 62 | + (None, "[email protected]", None, None, "", None), |
| 63 | + # Test handling mixed email formats |
| 64 | + ( |
| 65 | + None, |
| 66 | + |
| 67 | + None, |
| 68 | + None, |
| 69 | + "John Doe, ", |
| 70 | + None, |
| 71 | + ), |
| 72 | + # Test handling empty string author (should be treated as missing) |
| 73 | + ("", "John Doe <[email protected]>", None, None, "John Doe", None), |
| 74 | + # Test handling empty string maintainer (should be treated as missing) |
| 75 | + (None, None, "", "Jane Smith <[email protected]>", None, "Jane Smith"), |
| 76 | + # Test complex real-world scenario |
| 77 | + ( |
| 78 | + "", |
| 79 | + |
| 80 | + "", |
| 81 | + |
| 82 | + "John Doe, Support Team", |
| 83 | + "Jane Smith", |
| 84 | + ), |
| 85 | + # Test whitespace in emails |
| 86 | + (None, " John Doe <[email protected]> ", None, None, "John Doe", None), |
| 87 | + # Test no changes needed |
| 88 | + ( |
| 89 | + "John Doe", |
| 90 | + |
| 91 | + "Jane Smith", |
| 92 | + |
| 93 | + "John Doe", |
| 94 | + "Jane Smith", |
| 95 | + ), |
| 96 | + ], |
| 97 | +) |
| 98 | +def test_enhance_author_maintainer_info( |
| 99 | + author, |
| 100 | + author_email, |
| 101 | + maintainer, |
| 102 | + maintainer_email, |
| 103 | + expected_author, |
| 104 | + expected_maintainer, |
| 105 | +): |
| 106 | + """Test _enhance_author_maintainer_info with various email and name combinations.""" |
| 107 | + # Create a real pkginfo.Distribution instance |
| 108 | + info = pkginfo.Distribution() |
| 109 | + info.name = "test-package" |
| 110 | + info.author = author |
| 111 | + info.author_email = author_email |
| 112 | + info.maintainer = maintainer |
| 113 | + info.maintainer_email = maintainer_email |
| 114 | + |
| 115 | + _enhance_author_maintainer_info(info) |
| 116 | + |
| 117 | + assert info.author == expected_author |
| 118 | + assert info.maintainer == expected_maintainer |
0 commit comments