Skip to content

Commit

Permalink
Merge pull request #717 from fcollonval/unittest-ignore
Browse files Browse the repository at this point in the history
Add unit tests for ignore feature
  • Loading branch information
fcollonval authored Aug 8, 2020
2 parents e3682d6 + 4ec179e commit 7558e29
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
70 changes: 70 additions & 0 deletions jupyterlab_git/tests/test_ignore.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import pytest

from jupyterlab_git.git import Git

from .testutils import FakeContentManager, maybe_future


@pytest.mark.parametrize("ignore_content", [None, "dummy", "dummy\n"])
@pytest.mark.asyncio
async def test_ensure_gitignore(tmp_path, ignore_content):
# Given
ignore_file = tmp_path / ".gitignore"
if ignore_content is not None:
ignore_file.write_text(ignore_content)

# When
actual_response = await Git(FakeContentManager("/bin")).ensure_gitignore(
str(tmp_path)
)

# Then
assert {"code": 0} == actual_response
content = ignore_file.read_text()
assert len(content) == 0 or content.endswith("\n")


@pytest.mark.asyncio
async def test_ensure_gitignore_failure(tmp_path):
# Given
ignore_file = tmp_path / ".gitignore"
ignore_file.write_text("dummy")
ignore_file.chmod(200) # Set read only to generate an error

# When
response = await Git(FakeContentManager("/bin")).ensure_gitignore(str(tmp_path))

# Then
assert response["code"] == -1


@pytest.mark.asyncio
async def test_ignore(tmp_path):
# Given
ignore_file = tmp_path / ".gitignore"
ignore_file.write_text("dummy")
file_ignore = "to_ignore.txt"

# When
response = await Git(FakeContentManager("/bin")).ignore(str(tmp_path), file_ignore)

# Then
assert {"code": 0} == response
content = ignore_file.read_text()
content.endswith("{}\n".format(file_ignore))


@pytest.mark.asyncio
async def test_ignore_failure(tmp_path):
# Given
ignore_file = tmp_path / ".gitignore"
ignore_file.write_text("dummy")
ignore_file.chmod(200) # Set read only to generate an error

# When
response = await Git(FakeContentManager("/bin")).ignore(
str(tmp_path), "to_ignore.txt"
)

# Then
assert response["code"] == -1
3 changes: 2 additions & 1 deletion src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,8 @@ export class GitExtension implements IGitExtension {
/**
* Make request to ignore one file.
*
* @param filename Optional name of the files to add
* @param filePath File to ignore
* @param useExtension Whether to ignore the file or its extension
*/
async ignore(filePath: string, useExtension: boolean): Promise<Response> {
await this.ready;
Expand Down

0 comments on commit 7558e29

Please sign in to comment.