|
| 1 | +import pytest |
| 2 | + |
| 3 | +from jupyterlab_git.git import Git |
| 4 | + |
| 5 | +from .testutils import FakeContentManager, maybe_future |
| 6 | + |
| 7 | + |
| 8 | +@pytest.mark.parametrize("ignore_content", [None, "dummy", "dummy\n"]) |
| 9 | +@pytest.mark.asyncio |
| 10 | +async def test_ensure_gitignore(tmp_path, ignore_content): |
| 11 | + # Given |
| 12 | + ignore_file = tmp_path / ".gitignore" |
| 13 | + if ignore_content is not None: |
| 14 | + ignore_file.write_text(ignore_content) |
| 15 | + |
| 16 | + # When |
| 17 | + actual_response = await Git(FakeContentManager("/bin")).ensure_gitignore( |
| 18 | + str(tmp_path) |
| 19 | + ) |
| 20 | + |
| 21 | + # Then |
| 22 | + assert {"code": 0} == actual_response |
| 23 | + content = ignore_file.read_text() |
| 24 | + assert len(content) == 0 or content.endswith("\n") |
| 25 | + |
| 26 | + |
| 27 | +@pytest.mark.asyncio |
| 28 | +async def test_ensure_gitignore_failure(tmp_path): |
| 29 | + # Given |
| 30 | + ignore_file = tmp_path / ".gitignore" |
| 31 | + ignore_file.write_text("dummy") |
| 32 | + ignore_file.chmod(200) # Set read only to generate an error |
| 33 | + |
| 34 | + # When |
| 35 | + response = await Git(FakeContentManager("/bin")).ensure_gitignore(str(tmp_path)) |
| 36 | + |
| 37 | + # Then |
| 38 | + assert response["code"] == -1 |
| 39 | + |
| 40 | + |
| 41 | +@pytest.mark.asyncio |
| 42 | +async def test_ignore(tmp_path): |
| 43 | + # Given |
| 44 | + ignore_file = tmp_path / ".gitignore" |
| 45 | + ignore_file.write_text("dummy") |
| 46 | + file_ignore = "to_ignore.txt" |
| 47 | + |
| 48 | + # When |
| 49 | + response = await Git(FakeContentManager("/bin")).ignore(str(tmp_path), file_ignore) |
| 50 | + |
| 51 | + # Then |
| 52 | + assert {"code": 0} == response |
| 53 | + content = ignore_file.read_text() |
| 54 | + content.endswith("{}\n".format(file_ignore)) |
| 55 | + |
| 56 | + |
| 57 | +@pytest.mark.asyncio |
| 58 | +async def test_ignore_failure(tmp_path): |
| 59 | + # Given |
| 60 | + ignore_file = tmp_path / ".gitignore" |
| 61 | + ignore_file.write_text("dummy") |
| 62 | + ignore_file.chmod(200) # Set read only to generate an error |
| 63 | + |
| 64 | + # When |
| 65 | + response = await Git(FakeContentManager("/bin")).ignore( |
| 66 | + str(tmp_path), "to_ignore.txt" |
| 67 | + ) |
| 68 | + |
| 69 | + # Then |
| 70 | + assert response["code"] == -1 |
0 commit comments