|
| 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 |
0 commit comments