From 1bcd4f519dd3d4a356c49594b5fe8c56c2230dd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Collonval?= Date: Sat, 8 Aug 2020 17:53:44 +0200 Subject: [PATCH] Merge pull request #717 from fcollonval/unittest-ignore Add unit tests for ignore feature --- jupyterlab_git/tests/test_ignore.py | 70 +++++++++++++++++++++++++++++ src/model.ts | 3 +- 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 jupyterlab_git/tests/test_ignore.py diff --git a/jupyterlab_git/tests/test_ignore.py b/jupyterlab_git/tests/test_ignore.py new file mode 100644 index 000000000..15ef387c9 --- /dev/null +++ b/jupyterlab_git/tests/test_ignore.py @@ -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 diff --git a/src/model.ts b/src/model.ts index 4e2da4bfc..47a296f2c 100644 --- a/src/model.ts +++ b/src/model.ts @@ -1201,7 +1201,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 { await this.ready;