Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests for ignore feature #717

Merged
merged 1 commit into from
Aug 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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