diff-cover 10.1.0__tar.gz → 10.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. {diff_cover-10.1.0 → diff_cover-10.2.0}/PKG-INFO +1 -1
  2. {diff_cover-10.1.0 → diff_cover-10.2.0}/diff_cover/git_path.py +4 -0
  3. {diff_cover-10.1.0 → diff_cover-10.2.0}/diff_cover/violationsreporters/base.py +13 -7
  4. {diff_cover-10.1.0 → diff_cover-10.2.0}/pyproject.toml +3 -3
  5. diff_cover-10.2.0/tests/conftest.py +17 -0
  6. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/test_violations_reporter.py +43 -0
  7. {diff_cover-10.1.0 → diff_cover-10.2.0}/LICENSE +0 -0
  8. {diff_cover-10.1.0 → diff_cover-10.2.0}/NOTICE +0 -0
  9. {diff_cover-10.1.0 → diff_cover-10.2.0}/README.rst +0 -0
  10. {diff_cover-10.1.0 → diff_cover-10.2.0}/diff_cover/__init__.py +0 -0
  11. {diff_cover-10.1.0 → diff_cover-10.2.0}/diff_cover/command_runner.py +0 -0
  12. {diff_cover-10.1.0 → diff_cover-10.2.0}/diff_cover/config_parser.py +0 -0
  13. {diff_cover-10.1.0 → diff_cover-10.2.0}/diff_cover/diff_cover_tool.py +0 -0
  14. {diff_cover-10.1.0 → diff_cover-10.2.0}/diff_cover/diff_quality_tool.py +0 -0
  15. {diff_cover-10.1.0 → diff_cover-10.2.0}/diff_cover/diff_reporter.py +0 -0
  16. {diff_cover-10.1.0 → diff_cover-10.2.0}/diff_cover/git_diff.py +0 -0
  17. {diff_cover-10.1.0 → diff_cover-10.2.0}/diff_cover/hook.py +0 -0
  18. {diff_cover-10.1.0 → diff_cover-10.2.0}/diff_cover/hookspecs.py +0 -0
  19. {diff_cover-10.1.0 → diff_cover-10.2.0}/diff_cover/report_generator.py +0 -0
  20. {diff_cover-10.1.0 → diff_cover-10.2.0}/diff_cover/snippets.py +0 -0
  21. {diff_cover-10.1.0 → diff_cover-10.2.0}/diff_cover/templates/console_coverage_report.txt +0 -0
  22. {diff_cover-10.1.0 → diff_cover-10.2.0}/diff_cover/templates/console_quality_report.txt +0 -0
  23. {diff_cover-10.1.0 → diff_cover-10.2.0}/diff_cover/templates/external_style.css +0 -0
  24. {diff_cover-10.1.0 → diff_cover-10.2.0}/diff_cover/templates/github_coverage_annotations.txt +0 -0
  25. {diff_cover-10.1.0 → diff_cover-10.2.0}/diff_cover/templates/html_coverage_report.html +0 -0
  26. {diff_cover-10.1.0 → diff_cover-10.2.0}/diff_cover/templates/html_quality_report.html +0 -0
  27. {diff_cover-10.1.0 → diff_cover-10.2.0}/diff_cover/templates/markdown_coverage_report.md +0 -0
  28. {diff_cover-10.1.0 → diff_cover-10.2.0}/diff_cover/templates/markdown_quality_report.md +0 -0
  29. {diff_cover-10.1.0 → diff_cover-10.2.0}/diff_cover/templates/snippet_content.html +0 -0
  30. {diff_cover-10.1.0 → diff_cover-10.2.0}/diff_cover/templates/snippet_content.md +0 -0
  31. {diff_cover-10.1.0 → diff_cover-10.2.0}/diff_cover/templates/snippet_content.txt +0 -0
  32. {diff_cover-10.1.0 → diff_cover-10.2.0}/diff_cover/templates/snippet_style.html +0 -0
  33. {diff_cover-10.1.0 → diff_cover-10.2.0}/diff_cover/util.py +0 -0
  34. {diff_cover-10.1.0 → diff_cover-10.2.0}/diff_cover/violationsreporters/__init__.py +0 -0
  35. {diff_cover-10.1.0 → diff_cover-10.2.0}/diff_cover/violationsreporters/java_violations_reporter.py +0 -0
  36. {diff_cover-10.1.0 → diff_cover-10.2.0}/diff_cover/violationsreporters/violations_reporter.py +0 -0
  37. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/__init__.py +0 -0
  38. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/add_console_report.txt +0 -0
  39. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/add_html_report.html +0 -0
  40. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/add_json_report.json +0 -0
  41. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/add_json_report_float.json +0 -0
  42. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/add_markdown_report.md +0 -0
  43. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/changed_console_report.txt +0 -0
  44. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/changed_html_report.html +0 -0
  45. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/coverage.xml +0 -0
  46. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/coverage1.xml +0 -0
  47. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/coverage2.xml +0 -0
  48. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/coverage_missing_lines.xml +0 -0
  49. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/cpp_functions_console_report.txt +0 -0
  50. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/cpp_functions_coverage.lcov +0 -0
  51. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/delete_console_report.txt +0 -0
  52. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/delete_html_report.html +0 -0
  53. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/dotnet_coverage.xml +0 -0
  54. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/empty.txt +0 -0
  55. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/empty_pycodestyle_violations.txt +0 -0
  56. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/expand_console_report.txt +0 -0
  57. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/external_css_html_report.html +0 -0
  58. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/external_style.css +0 -0
  59. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/git_diff_add.txt +0 -0
  60. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/git_diff_changed.txt +0 -0
  61. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/git_diff_code_dupe.txt +0 -0
  62. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/git_diff_cpp.txt +0 -0
  63. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/git_diff_cpp_functions.txt +0 -0
  64. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/git_diff_delete.txt +0 -0
  65. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/git_diff_dotnet.txt +0 -0
  66. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/git_diff_external_css.txt +0 -0
  67. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/git_diff_lua.txt +0 -0
  68. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/git_diff_moved.txt +0 -0
  69. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/git_diff_mult.txt +0 -0
  70. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/git_diff_python.txt +0 -0
  71. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/git_diff_subdir.txt +0 -0
  72. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/git_diff_typescript.txt +0 -0
  73. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/git_diff_typescript_branches.txt +0 -0
  74. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/git_diff_unicode.txt +0 -0
  75. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/git_diff_violations.txt +0 -0
  76. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/git_diff_violations_two_files.txt +0 -0
  77. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/hello.py +0 -0
  78. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/hi.py +0 -0
  79. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/html_report.html +0 -0
  80. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/html_report_empty.html +0 -0
  81. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/html_report_one_snippet.html +0 -0
  82. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/html_report_two_snippets.html +0 -0
  83. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/lcov.info +0 -0
  84. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/lua_console_report.txt +0 -0
  85. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/luacoverage.xml +0 -0
  86. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/markdown_report_one_snippet.md +0 -0
  87. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/markdown_report_two_snippets.md +0 -0
  88. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/moved_console_report.txt +0 -0
  89. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/moved_coverage.xml +0 -0
  90. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/moved_html_report.html +0 -0
  91. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/mult_inputs_console_report.txt +0 -0
  92. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/mult_inputs_html_report.html +0 -0
  93. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/pycodestyle_report.txt +0 -0
  94. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/pycodestyle_violations_report.html +0 -0
  95. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/pycodestyle_violations_report.json +0 -0
  96. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/pycodestyle_violations_report.md +0 -0
  97. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/pycodestyle_violations_report.txt +0 -0
  98. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/pycodestyle_violations_report_external_css.html +0 -0
  99. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/pycodestyle_violations_report_float.json +0 -0
  100. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/pyflakes_two_files.txt +0 -0
  101. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/pyflakes_violations_report.html +0 -0
  102. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/pyflakes_violations_report.txt +0 -0
  103. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/pylint_dupe.txt +0 -0
  104. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/pylint_dupe_violations_report.txt +0 -0
  105. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/pylint_report.txt +0 -0
  106. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/pylint_violations_console_report.txt +0 -0
  107. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/pylint_violations_report.html +0 -0
  108. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/pylint_violations_report.txt +0 -0
  109. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/pylintrc +0 -0
  110. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/real_cpp_console_report.txt +0 -0
  111. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/real_cpp_coverage.lcov +0 -0
  112. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/real_python_console_report.txt +0 -0
  113. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/real_python_coverage.lcov +0 -0
  114. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/real_typescript_console_report.txt +0 -0
  115. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/real_typescript_coverage.lcov +0 -0
  116. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/show_uncovered_lines_console.txt +0 -0
  117. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/snippet.css +0 -0
  118. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/snippet_8859.py +0 -0
  119. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/snippet_arabic_output.html +0 -0
  120. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/snippet_default.html +0 -0
  121. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/snippet_invalid_violations.html +0 -0
  122. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/snippet_list.html +0 -0
  123. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/snippet_list.md +0 -0
  124. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/snippet_list2.md +0 -0
  125. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/snippet_list3.md +0 -0
  126. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/snippet_no_filename_ext.html +0 -0
  127. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/snippet_src.py +0 -0
  128. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/snippet_src2.cpp +0 -0
  129. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/snippet_src3.cpp +0 -0
  130. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/snippet_unicode.html +0 -0
  131. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/snippet_unicode.py +0 -0
  132. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/snippet_unicode_html_output.html +0 -0
  133. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/subdir_coverage_console_report.txt +0 -0
  134. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/subdir_coverage_html_report.html +0 -0
  135. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/test_src.txt +0 -0
  136. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/typescript_branches_console_report.txt +0 -0
  137. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/typescript_branches_coverage.lcov +0 -0
  138. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/unicode_console_report.txt +0 -0
  139. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/unicode_coverage.xml +0 -0
  140. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/unicode_html_report.html +0 -0
  141. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/unicode_test_src.txt +0 -0
  142. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/fixtures/violations_test_file.py +0 -0
  143. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/helpers.py +0 -0
  144. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/snippet_list_unicode.html +0 -0
  145. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/test_clover_violations_reporter/test.xml +0 -0
  146. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/test_clover_violations_reporter.py +0 -0
  147. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/test_config_parser.py +0 -0
  148. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/test_diff_cover_main.py +0 -0
  149. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/test_diff_cover_tool.py +0 -0
  150. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/test_diff_quality_main.py +0 -0
  151. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/test_diff_reporter.py +0 -0
  152. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/test_git_diff.py +0 -0
  153. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/test_git_diff_file.py +0 -0
  154. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/test_git_path.py +0 -0
  155. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/test_integration.py +0 -0
  156. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/test_java_violations_reporter.py +0 -0
  157. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/test_report_generator.py +0 -0
  158. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/test_snippets.py +0 -0
  159. {diff_cover-10.1.0 → diff_cover-10.2.0}/tests/test_util.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: diff_cover
3
- Version: 10.1.0
3
+ Version: 10.2.0
4
4
  Summary: Run coverage and linting reports on diffs
5
5
  License: Apache-2.0
6
6
  Author: See Contributors
@@ -36,6 +36,10 @@ class GitPathTool:
36
36
  """
37
37
  Returns git_diff_path relative to cwd.
38
38
  """
39
+ # If GitPathTool hasn't been initialized, return the path unchanged
40
+ if cls._cwd is None or cls._root is None:
41
+ return git_diff_path
42
+
39
43
  # Remove git_root from src_path for searching the correct filename
40
44
  # If cwd is `/home/user/work/diff-cover/diff_cover`
41
45
  # and src_path is `diff_cover/violations_reporter.py`
@@ -6,6 +6,7 @@ from abc import ABC, abstractmethod
6
6
  from collections import defaultdict, namedtuple
7
7
 
8
8
  from diff_cover.command_runner import execute, run_command_for_code
9
+ from diff_cover.git_path import GitPathTool
9
10
  from diff_cover.util import to_unix_path
10
11
 
11
12
  Violation = namedtuple("Violation", "line, message")
@@ -152,14 +153,19 @@ class QualityReporter(BaseViolationReporter):
152
153
  if not any(src_path.endswith(ext) for ext in self.driver.supported_extensions):
153
154
  return []
154
155
 
155
- if src_path not in self.violations_dict:
156
+ # `src_path` is relative to the git root. We convert it to be relative to
157
+ # the current working directory, since quality tools report paths relative
158
+ # to the current working directory.
159
+ relative_src_path = to_unix_path(GitPathTool.relative_path(src_path))
160
+
161
+ if relative_src_path not in self.violations_dict:
156
162
  if self.reports:
157
163
  self.violations_dict = self.driver.parse_reports(self.reports)
158
- return self.violations_dict[src_path]
164
+ return self.violations_dict[relative_src_path]
159
165
 
160
- if not os.path.exists(src_path):
161
- self.violations_dict[src_path] = []
162
- return self.violations_dict[src_path]
166
+ if not os.path.exists(relative_src_path):
167
+ self.violations_dict[relative_src_path] = []
168
+ return self.violations_dict[relative_src_path]
163
169
 
164
170
  if self.driver_tool_installed is None:
165
171
  self.driver_tool_installed = self.driver.installed()
@@ -170,13 +176,13 @@ class QualityReporter(BaseViolationReporter):
170
176
  if self.options:
171
177
  for arg in self.options.split():
172
178
  command.append(arg)
173
- command.append(src_path.encode(sys.getfilesystemencoding()))
179
+ command.append(relative_src_path.encode(sys.getfilesystemencoding()))
174
180
 
175
181
  stdout, stderr = execute(command, self.driver.exit_codes)
176
182
  output = stderr if self.driver.output_stderr else stdout
177
183
  self.violations_dict.update(self.driver.parse_reports([output]))
178
184
 
179
- return self.violations_dict[src_path]
185
+ return self.violations_dict[relative_src_path]
180
186
 
181
187
  def measured_lines(self, src_path):
182
188
  """
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "diff_cover"
3
- version = "10.1.0"
3
+ version = "10.2.0"
4
4
  description = "Run coverage and linting reports on diffs"
5
5
  authors = ["See Contributors"]
6
6
  homepage = "https://github.com/Bachmann1234/diff-cover"
@@ -55,12 +55,12 @@ pytest-xdist = "^3.6.1"
55
55
  pycodestyle = ">=2.9.1"
56
56
  flake8-pyproject = "^1.2.3"
57
57
  pyflakes = "^3.3.2"
58
- pylint = "^3.3.4"
58
+ pylint = ">=3.3.4,<5.0.0"
59
59
  pylint-pytest = "^1.1.8"
60
60
  pydocstyle = "^6.1.1"
61
61
  black = "^25.1.0"
62
62
  isort = "^6.0.1"
63
- doc8 = "1.1.2"
63
+ doc8 = "2.0.0"
64
64
  ruff = ">=0.11.10,<0.15.0"
65
65
 
66
66
  [tool.poetry.extras]
@@ -0,0 +1,17 @@
1
+ import pytest
2
+
3
+ from diff_cover.git_path import GitPathTool
4
+
5
+
6
+ @pytest.fixture(autouse=True)
7
+ def reset_git_path_tool():
8
+ """Reset GitPathTool before each test to ensure test isolation.
9
+
10
+ GitPathTool uses class variables (_cwd and _root) that persist across tests.
11
+ This fixture ensures each test starts with a clean state.
12
+ """
13
+ GitPathTool._cwd = None
14
+ GitPathTool._root = None
15
+ yield
16
+ GitPathTool._cwd = None
17
+ GitPathTool._root = None
@@ -2312,3 +2312,46 @@ class TestClangFormatcheckQualityDriverTest:
2312
2312
  driver = ClangFormatDriver()
2313
2313
  actual_violations = driver.parse_reports([report])
2314
2314
  assert actual_violations == expected_violations
2315
+
2316
+
2317
+ class TestQualityReporterSubdirectory:
2318
+ """
2319
+ Test that QualityReporter works correctly when running from a subdirectory.
2320
+
2321
+ When running diff-quality from a subdirectory:
2322
+ - Git reports paths relative to the git root (e.g., "subdir/file.py")
2323
+ - Quality tools report paths relative to the current working directory (e.g., "file.py")
2324
+ """
2325
+
2326
+ def test_violations_from_subdirectory(self, mocker, process_patcher):
2327
+ """
2328
+ Test that violations are found when running from a subdirectory.
2329
+
2330
+ Simulates running diff-quality from "subdir/" where:
2331
+ - Git reports the file as "subdir/file.py" (relative to git root)
2332
+ - The quality tool reports violations on "file.py" (relative to cwd)
2333
+ """
2334
+ from diff_cover.git_path import GitPathTool
2335
+
2336
+ # Simulate running from a subdirectory by mocking relative_path
2337
+ # to strip the "subdir/" prefix (as it would when cwd is inside subdir/)
2338
+ mocker.patch.object(
2339
+ GitPathTool, "relative_path", side_effect=lambda x: x.replace("subdir/", "")
2340
+ )
2341
+
2342
+ # Quality tool outputs violations with paths relative to cwd
2343
+ # (without the "subdir/" prefix)
2344
+ tool_output = "file.py:10: error: Something is wrong [error-code]"
2345
+ process_patcher((tool_output.encode("utf-8"), b""))
2346
+
2347
+ quality = QualityReporter(mypy_driver)
2348
+
2349
+ # Request violations using the git-relative path (with "subdir/" prefix)
2350
+ # This is what diff-quality would pass based on git diff output
2351
+ violations = quality.violations("subdir/file.py")
2352
+
2353
+ # Verify violations are found (the fix makes this work)
2354
+ expected = [
2355
+ Violation(line=10, message="error: Something is wrong [error-code]")
2356
+ ]
2357
+ assert violations == expected
File without changes
File without changes
File without changes