Skip to content

Commit

Permalink
add tests for utils function
Browse files Browse the repository at this point in the history
  • Loading branch information
diitaz93 committed Jul 26, 2024
1 parent f73d6b8 commit 7e4302b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/utils/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from cg.utils.files import (
get_directories_in_path,
get_file_in_directory,
get_file_with_pattern_from_list,
get_files_in_directory_with_pattern,
get_files_matching_pattern,
get_source_creation_time_stamp,
Expand All @@ -25,6 +26,30 @@ def test_get_file_in_directory(nested_directory_with_file: Path, some_file: str)
assert file_path.exists()


def test_get_file_with_pattern_from_list():
"""Test that a file is extracted from a list by pattern."""
# GIVEN a list of files and a pattern found in one of the files
files = [Path("file1.txt"), Path("file2.txt"), Path("file3.txt")]

# WHEN getting a file by the pattern
file = get_file_with_pattern_from_list(files, "file2")

# THEN assert that the file is returned
assert file == Path("file2.txt")


def test_get_file_with_pattern_from_list_no_file():
"""Test that a file is extracted from a list by pattern."""
# GIVEN a list of files and a pattern not found in any of the files
files = [Path("file1.txt"), Path("file2.txt"), Path("file3.txt")]

# WHEN getting a file by the pattern

# THEN a FileNotFoundError should be raised
with pytest.raises(FileNotFoundError):
get_file_with_pattern_from_list(files, "file4")


def test_get_files_in_directory_by_pattern(nested_directory_with_file: Path, some_file: str):
"""Test function to get files with a pattern in a directory and subdirectories."""
# GIVEN a directory with subdirectories with a file
Expand Down

0 comments on commit 7e4302b

Please sign in to comment.