Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion python/src/magika/magika.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ def scan_directory(
collected_paths: List[Union[str, os.PathLike]] = []

# Use rglob('*') for recursive scan, glob('*') for single directory
glob_pattern = path_obj.rglob("*") if recursive_scan else path_obj.glob("*")
glob_pattern = (
sorted(path_obj.rglob("*"))
if recursive_scan
else sorted(path_obj.glob("*"))
)

for item in glob_pattern:
# We only want files, not sub-directories themselves
Expand Down
14 changes: 12 additions & 2 deletions python/tests/test_magika_python_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,20 @@ def test_magika_module_with_explicit_model_dir() -> None:


def test_magika_module_with_basic_tests_by_directory() -> None:
tests_paths = utils.get_directory_test_dir()
tests_paths = utils.get_directory_tests_files_dir()

m = Magika()
_ = m.scan_directory(tests_paths)

# Only scan direct children of tests_data/directory.
# Expected output is "directory" content type.
results = m.scan_directory(tests_paths)
direct_children = sorted([p for p in tests_paths.glob("*")])
check_results_vs_expected_results(direct_children, results)

# Scan all files recursively. Expected output is content type of each file.
results = m.scan_directory(tests_paths, recursive_scan=True)
all_files = sorted([p for p in tests_paths.rglob("*") if p.is_file()])
check_results_vs_expected_results(all_files, results)


def test_magika_module_with_basic_tests_by_paths() -> None:
Expand Down
4 changes: 2 additions & 2 deletions python/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def get_basic_tests_files_dir() -> Path:
return tests_files_dir


def get_directory_test_dir() -> Path:
tests_files_dir = get_tests_data_dir() / "scan_directory"
def get_directory_tests_files_dir() -> Path:
tests_files_dir = get_tests_data_dir() / "directory"
assert tests_files_dir.is_dir()
return tests_files_dir

Expand Down
1 change: 1 addition & 0 deletions tests_data/directory/txt/complex-sentence.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is yet another simple test, it includes one simple sentence, but it is not as trivial as other simpler tests.
32 changes: 0 additions & 32 deletions tests_data/scan_directory/code2.py

This file was deleted.

31 changes: 0 additions & 31 deletions tests_data/scan_directory/test.json

This file was deleted.

36 changes: 0 additions & 36 deletions tests_data/scan_directory/test.rs

This file was deleted.

36 changes: 0 additions & 36 deletions tests_data/scan_directory/test.ts

This file was deleted.

Loading