From 7e4302b9ca2b3753c2890cff7ead354cda243181 Mon Sep 17 00:00:00 2001 From: Sebastian Diaz Date: Fri, 26 Jul 2024 12:57:58 +0200 Subject: [PATCH] add tests for utils function --- tests/utils/test_files.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/utils/test_files.py b/tests/utils/test_files.py index 0efc86441f..2707c1a0e4 100644 --- a/tests/utils/test_files.py +++ b/tests/utils/test_files.py @@ -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, @@ -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