-
Notifications
You must be signed in to change notification settings - Fork 52
Extract NPath report parser #1231
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
Open
somepatt
wants to merge
4
commits into
cqfn:master
Choose a base branch
from
somepatt:fix-796-extract-npath-report-parser
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2019-2026 Aibolit | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
| import pytest | ||
|
|
||
| from aibolit.metrics.npath import main as npath_main | ||
| from aibolit.metrics.npath.main import NPathMetric | ||
|
|
||
|
|
||
| def test_parse_report_reads_complexity_from_xml(): | ||
| """PMD XML content should be parsed without touching the filesystem.""" | ||
| result = NPathMetric.parse_report( | ||
| ''' | ||
| <pmd> | ||
| <file name="/tmp/npath/src/main/java/test/metrics/npath/Foo.java"> | ||
| <violation>NPath complexity of 200</violation> | ||
| </file> | ||
| </pmd> | ||
| ''', | ||
| '/tmp/npath', | ||
| ) | ||
|
|
||
| assert result == { | ||
| 'data': [{'file': 'test/metrics/npath/Foo.java', 'complexity': 200}], | ||
| 'errors': [], | ||
| } | ||
|
|
||
|
|
||
| def test_parse_report_raises_pmd_error(): | ||
| """PMD error entries should surface with source-relative filenames.""" | ||
| with pytest.raises(Exception, match='test/metrics/npath/ooo.java: PMDException'): | ||
| NPathMetric.parse_report( | ||
| ''' | ||
| <pmd> | ||
| <error filename="/tmp/npath/src/main/java/test/metrics/npath/ooo.java" | ||
| msg="PMDException" /> | ||
| </pmd> | ||
| ''', | ||
| '/tmp/npath', | ||
| ) | ||
|
|
||
|
|
||
| def test_parse_report_raises_on_malformed_violation(): | ||
| """Unexpected violation text should fail with a descriptive parser error.""" | ||
| with pytest.raises(ValueError, match='Unexpected PMD violation format'): | ||
| NPathMetric.parse_report( | ||
| ''' | ||
| <pmd> | ||
| <file name="/tmp/npath/src/main/java/test/metrics/npath/Foo.java"> | ||
| <violation>unexpected</violation> | ||
| </file> | ||
| </pmd> | ||
| ''', | ||
| '/tmp/npath', | ||
| ) | ||
|
|
||
|
|
||
| def test_parse_report_normalizes_windows_source_paths(): | ||
| """Windows-style PMD paths should still be trimmed to source-relative names.""" | ||
| result = NPathMetric.parse_report( | ||
| ''' | ||
| <pmd> | ||
| <file name="C:\\tmp\\npath\\src\\main\\java\\test\\metrics\\npath\\Foo.java"> | ||
| <violation>NPath complexity of 200</violation> | ||
| </file> | ||
| </pmd> | ||
| ''', | ||
| 'C:\\tmp\\npath', | ||
| ) | ||
|
|
||
| assert result == { | ||
| 'data': [{'file': 'test/metrics/npath/Foo.java', 'complexity': 200}], | ||
| 'errors': [], | ||
| } | ||
|
|
||
|
|
||
| def test_value_preserves_root_initialization_error(monkeypatch): | ||
| """Temporary-root setup errors should not be masked by cleanup.""" | ||
| metric = NPathMetric('Foo.java') | ||
|
|
||
| def fail_gettempdir(): | ||
| raise RuntimeError('temp root failed') | ||
|
|
||
| monkeypatch.setattr(npath_main.tempfile, 'gettempdir', fail_gettempdir) | ||
|
|
||
| with pytest.raises(RuntimeError, match='temp root failed'): | ||
| metric.value() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.