Repository: jorisroovers/gitlint (language: python)

Issue:
Unit-tests fail on Windows
`./run_tests` doesn't work on windows since it's a bash script, but you can still run the unit tests directly using pytest:
```
pytest -rw -s gitlint
```

At the time of writing, 35 unit tests are failing, 94 are passing. Some failures seem related to unicode issues.


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml
index ccba4a01..326a3d48 100644
--- a/.github/workflows/checks.yml
+++ b/.github/workflows/checks.yml
@@ -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


Test patch:
diff --git a/gitlint-core/gitlint/tests/cli/test_cli.py b/gitlint-core/gitlint/tests/cli/test_cli.py
index d18efe93..45093dd6 100644
--- a/gitlint-core/gitlint/tests/cli/test_cli.py
+++ b/gitlint-core/gitlint/tests/cli/test_cli.py
@@ -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)
 
@@ -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)
 
@@ -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)
@@ -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)
 
@@ -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)
 
@@ -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")
diff --git a/gitlint-core/gitlint/tests/cli/test_cli_hooks.py b/gitlint-core/gitlint/tests/cli/test_cli_hooks.py
index d4311c65..6564a64f 100644
--- a/gitlint-core/gitlint/tests/cli/test_cli_hooks.py
+++ b/gitlint-core/gitlint/tests/cli/test_cli_hooks.py
@@ -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)
 
diff --git a/gitlint-core/gitlint/tests/expected/cli/test_cli/test_debug_1 b/gitlint-core/gitlint/tests/expected/cli/test_cli/test_debug_1
index 4bd3b7db..319a2594 100644
--- a/gitlint-core/gitlint/tests/expected/cli/test_cli/test_debug_1
+++ b/gitlint-core/gitlint/tests/expected/cli/test_cli/test_debug_1
@@ -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
@@ -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
@@ -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
\ No newline at end of file
diff --git a/gitlint-core/gitlint/tests/expected/cli/test_cli/test_lint_staged_msg_filename_2 b/gitlint-core/gitlint/tests/expected/cli/test_cli/test_lint_staged_msg_filename_2
index 59b24142..fe470db2 100644
--- a/gitlint-core/gitlint/tests/expected/cli/test_cli/test_lint_staged_msg_filename_2
+++ b/gitlint-core/gitlint/tests/expected/cli/test_cli/test_lint_staged_msg_filename_2
@@ -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
\ No newline at end of file
diff --git a/gitlint-core/gitlint/tests/expected/cli/test_cli/test_lint_staged_stdin_2 b/gitlint-core/gitlint/tests/expected/cli/test_cli/test_lint_staged_stdin_2
index 23df7b21..e5ba7c6c 100644
--- a/gitlint-core/gitlint/tests/expected/cli/test_cli/test_lint_staged_stdin_2
+++ b/gitlint-core/gitlint/tests/expected/cli/test_cli/test_lint_staged_stdin_2
@@ -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
\ No newline at end of file