-
-
Notifications
You must be signed in to change notification settings - Fork 656
Support directory paths in referenced_filenames rule attribute #4647
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
adityashirsatrao007
wants to merge
1
commit into
aboutcode-org:develop
Choose a base branch
from
adityashirsatrao007:allow-directories-in-referenced-filenames
base: develop
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.
+161
−40
Open
Changes from all commits
Commits
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
Some comments aren't visible on the classic Files Changed page.
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
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,78 @@ | ||
|
|
||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # Copyright (c) nexB Inc. and others. All rights reserved. | ||
| # ScanCode is a trademark of nexB Inc. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # See http://www.apache.org/licenses/LICENSE-2.0 for the license text. | ||
| # See https://github.com/nexB/scancode-toolkit for support or download. | ||
| # See https://aboutcode.org for more information about nexB OSS projects. | ||
| # | ||
|
|
||
| import os | ||
| from commoncode.testcase import FileDrivenTesting | ||
| from commoncode.resource import Codebase | ||
| from licensedcode.detection import find_referenced_resource | ||
|
|
||
| class TestIssue4276(FileDrivenTesting): | ||
|
|
||
| def test_find_referenced_resource_with_glob(self): | ||
| test_dir = self.get_temp_dir() | ||
| os.makedirs(os.path.join(test_dir, 'licenses')) | ||
| with open(os.path.join(test_dir, 'README.txt'), 'w') as f: | ||
| f.write('See licenses/*.txt') | ||
| with open(os.path.join(test_dir, 'licenses', 'MIT.txt'), 'w') as f: | ||
| f.write('MIT License') | ||
|
|
||
| codebase = Codebase(test_dir) | ||
| readme = None | ||
| for res in codebase.walk(): | ||
| if res.name == 'README.txt': | ||
| readme = res | ||
| break | ||
| assert readme is not None, "README.txt resource not found in codebase" | ||
|
|
||
| # Test finding with glob | ||
| # This currently expects a single return, but we want it to handle globs | ||
| # For this test, we accept either a list or a single resource if we stick to single-return for now | ||
| # But realistically we need a list. | ||
|
|
||
| print(f"DEBUG: Root path: {codebase.root.path if codebase.root else 'None'}") | ||
| print(f"DEBUG: Readme path: {readme.path}") | ||
| print(f"DEBUG: Readme parent: {readme.parent_path()}") | ||
| print(f"DEBUG: All resources: {[r.path for r in codebase.walk()]}") | ||
|
|
||
| result = find_referenced_resource('licenses/*.txt', readme, codebase) | ||
| print(f"DEBUG: Result: {result}") | ||
|
|
||
| assert result is not None | ||
| if isinstance(result, list): | ||
| assert len(result) > 0 | ||
| assert result[0].path.endswith('licenses/MIT.txt') | ||
| else: | ||
| assert result.path.endswith('licenses/MIT.txt') | ||
|
|
||
adityashirsatrao007 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def test_find_referenced_resource_with_directory(self): | ||
| test_dir = self.get_temp_dir() | ||
| os.makedirs(os.path.join(test_dir, 'licenses')) | ||
| with open(os.path.join(test_dir, 'README.txt'), 'w') as f: | ||
| f.write('See licenses/') | ||
| with open(os.path.join(test_dir, 'licenses', 'MIT.txt'), 'w') as f: | ||
| f.write('MIT License') | ||
|
|
||
| codebase = Codebase(test_dir) | ||
| readme = None | ||
| for res in codebase.walk(): | ||
| if res.name == 'README.txt': | ||
| readme = res | ||
| break | ||
| assert readme is not None | ||
|
|
||
| # referencing a directory should return all files in it | ||
| result = find_referenced_resource('licenses/', readme, codebase) | ||
|
|
||
| assert result is not None | ||
| assert isinstance(result, list) | ||
| # We expect it to find the file inside the directory | ||
| found_paths = [r.path for r in result] | ||
| assert any(p.endswith('licenses/MIT.txt') for p in found_paths) | ||
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
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.