Skip to content

Commit

Permalink
fix: rename function
Browse files Browse the repository at this point in the history
  • Loading branch information
agusmakmun committed Apr 8, 2024
1 parent 8d162f0 commit b3327e3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/scanreq/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,16 @@ def search_string_in_file(file_path: str, search_string: str) -> Optional[str]:
return None


def search_string_in_python_files(directory: str, search_string: str) -> List[str]:
def search_string_in_files(directory: str, search_string: str) -> List[str]:
"""
A function that searches for a specific string in all Python files within a given directory.
Search for a specific string within files in a given directory using multiprocessing.
Parameters:
- directory: A string representing the path to the directory to search in.
- search_string: A string representing the specific string to search for in the files.
Args:
directory (str): The directory path to search for files.
search_string (str): The string to search for within the files.
Returns:
- A list of strings containing the paths to the files where the search_string was found.
List[str]: A list of file paths where the search_string was found.
"""
found_files: List[Any] = []
pool = multiprocessing.Pool()
Expand Down Expand Up @@ -217,7 +217,7 @@ def scan(
package_name in main_package_names
and package_name not in ignored_packages
):
results: list = search_string_in_python_files(project_path, module_name)
results: list = search_string_in_files(project_path, module_name)
if not results and (module_name not in unused_packages):
unused_packages.append(package_name)
number_str: str = f"{number}."
Expand Down
7 changes: 4 additions & 3 deletions tests/test_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
get_main_packages,
read_requirements,
search_string_in_file,
search_string_in_python_files,
search_string_in_files,
)


Expand Down Expand Up @@ -79,12 +79,12 @@ def create_test_files(tmp_path):
return sub_dir


def test_search_string_in_python_files(create_test_files):
def test_search_string_in_files(create_test_files):
directory = str(create_test_files)
search_string = "foo"
expected_file = os.path.join(directory, "test2.py")

found_files = search_string_in_python_files(directory, search_string)
found_files = search_string_in_files(directory, search_string)
assert expected_file in found_files
assert len(found_files) == 1

Expand All @@ -99,6 +99,7 @@ def test_search_string_in_python_files(create_test_files):
(" NumPy ", "numpy"),
("django-cookie-cutter>2.0", "django-cookie-cutter"),
("django-cookie-cutter<2.0", "django-cookie-cutter"),
("Django-Allauth>5.0", "django-allauth"),
],
)
def test_clean_package_name(package_name, expected):
Expand Down

0 comments on commit b3327e3

Please sign in to comment.