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

Fix Windows unit tests #383

Merged
merged 2 commits into from
Nov 30, 2022
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
15 changes: 2 additions & 13 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,8 @@ jobs:
- name: gitlint --version
run: gitlint --version

- name: Tests (sanity)
run: tools\windows\run_tests.bat "gitlint-core\gitlint\tests\cli\test_cli.py::CLITests::test_lint"

- name: Tests (ignore cli\*)
run: pytest --ignore gitlint-core\gitlint\tests\cli -rw -s gitlint-core

- name: Tests (test_cli.py only - continue-on-error:true)
run: tools\windows\run_tests.bat "gitlint-core\gitlint\tests\cli\test_cli.py"
continue-on-error: true # Known to fail at this point

- name: Tests (all - continue-on-error:true)
run: tools\windows\run_tests.bat
continue-on-error: true # Known to fail at this point
- name: Unit Tests
run: pytest gitlint-core

- name: Integration tests (continue-on-error:true)
run: pytest -rw -s qa
Expand Down
35 changes: 32 additions & 3 deletions gitlint-core/gitlint/tests/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ def test_lint_staged_stdin(self, sh, _, __):
self.assertEqual(result.output, "")

expected_kwargs = self.get_system_info_dict()
changed_files_stats = (
f" {os.path.join('commit-1', 'file-1')}: 1 additions, 5 deletions\n"
f" {os.path.join('commit-1', 'file-2')}: 8 additions, 9 deletions"
)
expected_kwargs.update({"changed_files_stats": changed_files_stats})
expected_logs = self.get_expected("cli/test_cli/test_lint_staged_stdin_2", expected_kwargs)
self.assert_logged(expected_logs)

Expand Down Expand Up @@ -328,6 +333,11 @@ def test_lint_staged_msg_filename(self, sh, _):
self.assertEqual(result.output, "")

expected_kwargs = self.get_system_info_dict()
changed_files_stats = (
f" {os.path.join('commit-1', 'file-1')}: 3 additions, 4 deletions\n"
f" {os.path.join('commit-1', 'file-2')}: 4 additions, 7 deletions"
)
expected_kwargs.update({"changed_files_stats": changed_files_stats})
expected_logs = self.get_expected("cli/test_cli/test_lint_staged_msg_filename_2", expected_kwargs)
self.assert_logged(expected_logs)

Expand Down Expand Up @@ -458,6 +468,25 @@ def test_debug(self, sh, _):
self.assertEqual(result.exit_code, 6)

expected_kwargs = self.get_system_info_dict()
changed_files_stats1 = (
f" {os.path.join('commit-1', 'file-1')}: 5 additions, 8 deletions\n"
f" {os.path.join('commit-1', 'file-2')}: 2 additions, 9 deletions"
)
changed_files_stats2 = (
f" {os.path.join('commit-2', 'file-1')}: 5 additions, 8 deletions\n"
f" {os.path.join('commit-2', 'file-2')}: 7 additions, 9 deletions"
)
changed_files_stats3 = (
f" {os.path.join('commit-3', 'file-1')}: 1 additions, 4 deletions\n"
f" {os.path.join('commit-3', 'file-2')}: 3 additions, 4 deletions"
)
expected_kwargs.update(
{
"changed_files_stats1": changed_files_stats1,
"changed_files_stats2": changed_files_stats2,
"changed_files_stats3": changed_files_stats3,
}
)
expected_kwargs.update({"config_path": config_path})
expected_logs = self.get_expected("cli/test_cli/test_debug_1", expected_kwargs)
self.assert_logged(expected_logs)
Expand Down Expand Up @@ -548,7 +577,7 @@ def test_config_file_negative(self):
# Non existing file
config_path = self.get_sample_path("föo")
result = self.cli.invoke(cli.cli, ["--config", config_path])
expected_string = f"Error: Invalid value for '-C' / '--config': File '{config_path}' does not exist."
expected_string = f"Error: Invalid value for '-C' / '--config': File {config_path!r} does not exist."
self.assertEqual(result.output.split("\n")[3], expected_string)
self.assertEqual(result.exit_code, self.USAGE_ERROR_CODE)

Expand All @@ -569,7 +598,7 @@ def test_config_file_negative_environment(self):
# Non existing file
config_path = self.get_sample_path("föo")
result = self.cli.invoke(cli.cli, env={"GITLINT_CONFIG": config_path})
expected_string = f"Error: Invalid value for '-C' / '--config': File '{config_path}' does not exist."
expected_string = f"Error: Invalid value for '-C' / '--config': File {config_path!r} does not exist."
self.assertEqual(result.output.split("\n")[3], expected_string)
self.assertEqual(result.exit_code, self.USAGE_ERROR_CODE)

Expand Down Expand Up @@ -602,7 +631,7 @@ def test_target_negative(self):
target_path = self.get_sample_path(os.path.join("config", "gitlintconfig"))
result = self.cli.invoke(cli.cli, ["--target", target_path])
self.assertEqual(result.exit_code, self.USAGE_ERROR_CODE)
expected_msg = f"Error: Invalid value for '--target': Directory '{target_path}' is a file."
expected_msg = f"Error: Invalid value for '--target': Directory {target_path!r} is a file."
self.assertEqual(result.output.split("\n")[3], expected_msg)

@patch("gitlint.config.LintConfigGenerator.generate_config")
Expand Down
3 changes: 2 additions & 1 deletion gitlint-core/gitlint/tests/cli/test_cli_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ def test_run_hook_negative(self, sh, _):
error_msg = b"fatal: not a git repository (or any of the parent directories): .git"
sh.git.side_effect = ErrorReturnCode("full command", b"stdout", error_msg)
result = self.cli.invoke(cli.cli, ["run-hook"])
expected = self.get_expected("cli/test_cli_hooks/test_run_hook_negative_1", {"git_repo": os.getcwd()})
expected_kwargs = {"git_repo": os.path.realpath(os.getcwd())}
expected = self.get_expected("cli/test_cli_hooks/test_run_hook_negative_1", expected_kwargs)
self.assertEqual(result.output, expected)
self.assertEqual(result.exit_code, self.GIT_CONTEXT_ERROR_CODE)

Expand Down
9 changes: 3 additions & 6 deletions gitlint-core/gitlint/tests/expected/cli/test_cli/test_debug_1
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ Parents: ['a123']
Branches: ['commit-1-branch-1', 'commit-1-branch-2']
Changed Files: ['commit-1/file-1', 'commit-1/file-2']
Changed Files Stats:
commit-1/file-1: 5 additions, 8 deletions
commit-1/file-2: 2 additions, 9 deletions
{changed_files_stats1}
-----------------------
DEBUG: gitlint.git ('log', '25053ccec5e28e1bb8f7551fdbb5ab213ada2401', '-1', '--pretty=%aN%x00%aE%x00%ai%x00%P%n%B')
DEBUG: gitlint.lint Linting commit 25053ccec5e28e1bb8f7551fdbb5ab213ada2401
Expand All @@ -112,8 +111,7 @@ Parents: ['b123']
Branches: ['commit-2-branch-1', 'commit-2-branch-2']
Changed Files: ['commit-2/file-1', 'commit-2/file-2']
Changed Files Stats:
commit-2/file-1: 5 additions, 8 deletions
commit-2/file-2: 7 additions, 9 deletions
{changed_files_stats2}
-----------------------
DEBUG: gitlint.git ('log', '4da2656b0dadc76c7ee3fd0243a96cb64007f125', '-1', '--pretty=%aN%x00%aE%x00%ai%x00%P%n%B')
DEBUG: gitlint.lint Linting commit 4da2656b0dadc76c7ee3fd0243a96cb64007f125
Expand All @@ -135,7 +133,6 @@ Parents: ['c123']
Branches: ['commit-3-branch-1', 'commit-3-branch-2']
Changed Files: ['commit-3/file-1', 'commit-3/file-2']
Changed Files Stats:
commit-3/file-1: 1 additions, 4 deletions
commit-3/file-2: 3 additions, 4 deletions
{changed_files_stats3}
-----------------------
DEBUG: gitlint.cli Exit Code = 6
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ Parents: []
Branches: ['my-branch']
Changed Files: ['commit-1/file-1', 'commit-1/file-2']
Changed Files Stats:
commit-1/file-1: 3 additions, 4 deletions
commit-1/file-2: 4 additions, 7 deletions
{changed_files_stats}
-----------------------
DEBUG: gitlint.cli Exit Code = 2
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ Parents: []
Branches: ['my-branch']
Changed Files: ['commit-1/file-1', 'commit-1/file-2']
Changed Files Stats:
commit-1/file-1: 1 additions, 5 deletions
commit-1/file-2: 8 additions, 9 deletions
{changed_files_stats}
-----------------------
DEBUG: gitlint.cli Exit Code = 3