Fix copyright detection for bracket notation [C] and [c] #4612
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.
Fixes #3659
This PR fixes the issue where copyright signs using bracket notation
[C]and[c]weren't being detected.Implementation Steps
Corc)prepare_text_line()to convert[C]and[c]to(c)before brackets get removedTasks
Run tests locally to check for errors.
Testing
Before Fix (Failed Tests)
(myenv) PS D:\scancode-dev\scancode-toolkit> python -m pytest tests\cluecode\test_copyrights_basic.py::TestTextPreparation::test_prepare_text_line_normalizes_bracket_C_uppercase tests\cluecode\test_copyrights_basic.py::TestTextPreparation::test_prepare_text_line_normalizes_bracket_c_lowercase -vs ========================================================================================= test session starts ========================================================================================= platform win32 -- Python 3.10.1, pytest-7.4.4, pluggy-1.6.0 -- D:\scancode-dev\scancode-toolkit\myenv\Scripts\python.exe cachedir: .pytest_cache rootdir: D:\scancode-dev\scancode-toolkit configfile: pyproject.toml collecting 2 items 2 tests selected, 0 tests skipped. collected 2 itemstests/cluecode/test_copyrights_basic.py::TestTextPreparation::test_prepare_text_line_normalizes_bracket_C_uppercase FAILED
tests/cluecode/test_copyrights_basic.py::TestTextPreparation::test_prepare_text_line_normalizes_bracket_c_lowercase FAILED
============================================================================================== FAILURES ===============================================================================================
______________________________________________________________ TestTextPreparation.test_prepare_text_line_normalizes_bracket_C_uppercase ______________________________________________________________
self = <test_copyrights_basic.TestTextPreparation testMethod=test_prepare_text_line_normalizes_bracket_C_uppercase>
E AssertionError: assert 'C The Regent...ghts Reserved' == '(c) The Rege...ghts Reserved'
E - (c) The Regents of the University of Michigan and Merit Network, Inc. 1992, 1993, 1994, 1995 All Rights Reserved
E ? ^^^
E + C The Regents of the University of Michigan and Merit Network, Inc. 1992, 1993, 1994, 1995 All Rights Reserved
E ? ^
tests\cluecode\test_copyrights_basic.py:75: AssertionError
______________________________________________________________ TestTextPreparation.test_prepare_text_line_normalizes_bracket_c_lowercase ______________________________________________________________
self = <test_copyrights_basic.TestTextPreparation testMethod=test_prepare_text_line_normalizes_bracket_c_lowercase>
E AssertionError: assert 'Copyright c ...ample Company' == 'Copyright (c...ample Company'
E - Copyright (c) 2023 Example Company
E ? - -
E + Copyright c 2023 Example Company
tests\cluecode\test_copyrights_basic.py:81: AssertionError
========================================================================================== warnings summary ===========================================================================================
conftest.py:94
D:\scancode-dev\scancode-toolkit\conftest.py:94: PytestDeprecationWarning: The hookimpl pytest_collection_modifyitems uses old-style configuration options (marks or attributes).
Please use the pytest.hookimpl(trylast=True) decorator instead
to configure the hooks.
See https://docs.pytest.org/en/latest/deprecations.html#configuring-hook-specs-impls-using-markers
@pytest.mark.trylast
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
======================================================================================= short test summary info =======================================================================================
FAILED tests/cluecode/test_copyrights_basic.py::TestTextPreparation::test_prepare_text_line_normalizes_bracket_C_uppercase - AssertionError: assert 'C The Regent...ghts Reserved' == '(c) The Rege...ghts Reserved'
FAILED tests/cluecode/test_copyrights_basic.py::TestTextPreparation::test_prepare_text_line_normalizes_bracket_c_lowercase - AssertionError: assert 'Copyright c ...ample Company' == 'Copyright (c...ample Company'
==================================================================================== 2 failed, 1 warning in 1.29s =====================================================================================
After Fix (Passing Tests)
(myenv) PS D:\scancode-dev\scancode-toolkit> python -m pytest tests\cluecode\test_copyrights_basic.py::TestTextPreparation::test_prepare_text_line_normalizes_bracket_C_uppercase tests\cluecode\test_copyrights_basic.py::TestTextPreparation::test_prepare_text_line_normalizes_bracket_c_lowercase -vs =================================================== test session starts =================================================== platform win32 -- Python 3.10.1, pytest-7.4.4, pluggy-1.6.0 -- D:\scancode-dev\scancode-toolkit\myenv\Scripts\python.exe cachedir: .pytest_cache rootdir: D:\scancode-dev\scancode-toolkit configfile: pyproject.toml collecting 2 items 2 tests selected, 0 tests skipped. collected 2 itemstests/cluecode/test_copyrights_basic.py::TestTextPreparation::test_prepare_text_line_normalizes_bracket_C_uppercase PASSED
tests/cluecode/test_copyrights_basic.py::TestTextPreparation::test_prepare_text_line_normalizes_bracket_c_lowercase PASSED
==================================================== warnings summary =====================================================
conftest.py:94
D:\scancode-dev\scancode-toolkit\conftest.py:94: PytestDeprecationWarning: The hookimpl pytest_collection_modifyitems uses old-style configuration options (marks or attributes).
Please use the pytest.hookimpl(trylast=True) decorator instead
to configure the hooks.
See https://docs.pytest.org/en/latest/deprecations.html#configuring-hook-specs-impls-using-markers
@pytest.mark.trylast
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
============================================== 2 passed, 1 warning in 1.28s ===============================================
Signed-off-by: Shekhar Suman levi42x@gmail.com