|
| 1 | +import os, subprocess |
| 2 | + |
| 3 | +expected_authors_list = "test <[email protected]>\ntestagain <[email protected]>\n" |
| 4 | +expected_authors_list_without_email = "test\ntestagain\n" |
| 5 | +authors_file = "AUTHORS" |
| 6 | + |
| 7 | +class TestGitAuthors: |
| 8 | + def test_init(self, temp_repo): |
| 9 | + git = temp_repo.get_repo_git() |
| 10 | + tmp_file = temp_repo.get_file(0) |
| 11 | + temp_repo.writefile(tmp_file, "A") |
| 12 | + git.add(".") |
| 13 | + git.commit("-m", "test: add data A") |
| 14 | + git.config("--local", "user.name", "testagain") |
| 15 | + git. config( "--local", "user.email", "[email protected]") |
| 16 | + temp_repo.writefile(tmp_file, "B") |
| 17 | + git.add(".") |
| 18 | + git.commit("-m", "test: add data B") |
| 19 | + |
| 20 | + def test_output_authors_has_email_without_any_parameter(self, temp_repo): |
| 21 | + git = temp_repo.get_repo_git() |
| 22 | + rs = temp_repo.invoke_extras_command("authors") |
| 23 | + with open(authors_file) as f: |
| 24 | + content = f.read() |
| 25 | + print(content) |
| 26 | + print(expected_authors_list) |
| 27 | + assert content == expected_authors_list |
| 28 | + |
| 29 | + def test_list_authors_has_email_defaultly(self, temp_repo): |
| 30 | + git = temp_repo.get_repo_git() |
| 31 | + actual = temp_repo.invoke_extras_command("authors", "--list") |
| 32 | + actual = actual.stdout.decode() |
| 33 | + assert actual == expected_authors_list |
| 34 | + actual = temp_repo.invoke_extras_command("authors", "-l") |
| 35 | + actual = actual.stdout.decode() |
| 36 | + assert actual == expected_authors_list |
| 37 | + |
| 38 | + def test_list_authors_has_not_email(self, temp_repo): |
| 39 | + git = temp_repo.get_repo_git() |
| 40 | + actual = temp_repo.invoke_extras_command("authors", "--list", "--no-email") |
| 41 | + actual = actual.stdout.decode() |
| 42 | + assert actual == expected_authors_list_without_email |
| 43 | + actual = temp_repo.invoke_extras_command("authors", "-l", "--no-email") |
| 44 | + actual = actual.stdout.decode() |
| 45 | + assert actual == expected_authors_list_without_email |
| 46 | + |
| 47 | + def test_output_authors_has_email_into_AUTHORS(self, temp_repo): |
| 48 | + git = temp_repo.get_repo_git() |
| 49 | + temp_repo.invoke_extras_command("authors", "--output") |
| 50 | + with open(authors_file) as f: |
| 51 | + content = f.read() |
| 52 | + assert content == expected_authors_list |
| 53 | + |
| 54 | + def test_output_authors_has_email_into_target_file(self, temp_repo): |
| 55 | + git = temp_repo.get_repo_git() |
| 56 | + temp_repo.invoke_extras_command("authors", "--output", "AUTHORS_TARGET_FILE_A") |
| 57 | + with open("AUTHORS_TARGET_FILE_A") as f: |
| 58 | + content = f.read() |
| 59 | + assert content == expected_authors_list |
| 60 | + |
| 61 | + def test_output_authors_has_not_email_into_target_file(self, temp_repo): |
| 62 | + git = temp_repo.get_repo_git() |
| 63 | + rs = temp_repo.invoke_extras_command("authors", "--output", "AUTHORS_TARGET_FILE_B", "--no-email") |
| 64 | + with open("AUTHORS_TARGET_FILE_B") as f: |
| 65 | + content = f.read() |
| 66 | + assert content == expected_authors_list_without_email |
| 67 | + |
| 68 | + def test_fail_to_output_authors_when_an_option_like_follow_output_parameter(self, temp_repo): |
| 69 | + git = temp_repo.get_repo_git() |
| 70 | + actual = temp_repo.invoke_extras_command("authors", "--output", "--no-email") |
| 71 | + actual = actual.stderr.decode() |
| 72 | + assert actual == "option --output requires a value\n" |
| 73 | + |
| 74 | + def test_fail_to_output_authors_when_only_no_email_option(self, temp_repo): |
| 75 | + git = temp_repo.get_repo_git() |
| 76 | + actual = temp_repo.invoke_extras_command("authors", "--no-email") |
| 77 | + actual = actual.stderr.decode() |
| 78 | + assert actual == "--no-email option only can be used with --list | -l | --output\n" |
0 commit comments