Untitled
unknown
plain_text
9 days ago
2.8 kB
2
Indexable
Never
from pro_filer.actions.main_actions import show_preview # NOQA def test_show_preview(capsys): file_context = { "all_files": ["project/__init__.py", "project/main.py", "project/helpers/__init__.py", "examples/bar/bar.py", "examples/foo/foo.py"], "all_dirs": ["project", "project/helpers", "examples", "examples/bar", "examples/foo"] } show_preview(file_context) assert file_context["all_files"] == ["project/__init__.py", "project/main.py", "project/helpers/__init__.py", "examples/bar/bar.py", "examples/foo/foo.py"] assert file_context["all_dirs"] == ["project", "project/helpers", "examples", "examples/bar", "examples/foo"] assert len(file_context["all_files"]) == 5 assert len(file_context["all_dirs"]) == 5 expected_message = ( f"Found 5 files and 5 directories\n" f"First 5 files: ['project/__init__.py', 'project/main.py', 'project/helpers/__init__.py', 'examples/bar/bar.py', 'examples/foo/foo.py']\n" f"First 5 directories: ['project', 'project/helpers', 'examples', 'examples/bar', 'examples/foo']\n" ) captured_output = capsys.readouterr() assert captured_output.out == expected_message def test_show_preview_with_empty_context(capsys): empty_context = { "all_files": [], "all_dirs": [] } show_preview(empty_context) assert empty_context["all_files"] == [] assert empty_context["all_dirs"] == [] assert len(empty_context["all_files"]) == 0 assert len(empty_context["all_dirs"]) == 0 expected_message = f'Found 0 files and 0 directories\n' captured_output = capsys.readouterr() assert captured_output.out == expected_message def test_show_preview_with_more_than_5_files_and_dirs(capsys): extended_context = { "all_files": ["project/__init__.py", "project/main.py", "project/helpers/__init__.py", "project/helpers/util.py", "project/helpers/util2.py", "project/helpers/util3.py"], "all_dirs": ["project", "project/helpers"] } show_preview(extended_context) assert extended_context["all_files"] == ["project/__init__.py", "project/main.py", "project/helpers/__init__.py", "project/helpers/util.py", "project/helpers/util2.py", "project/helpers/util3.py"] assert extended_context["all_dirs"] == ["project", "project/helpers"] assert len(extended_context["all_files"]) == 6 assert len(extended_context["all_dirs"]) == 2 expected_message = ( f"Found 6 files and 2 directories\n" f"First 5 files: ['project/__init__.py', 'project/main.py', 'project/helpers/__init__.py', 'project/helpers/util.py', 'project/helpers/util2.py']\n" f"First 5 directories: ['project', 'project/helpers']\n" ) captured_output = capsys.readouterr() assert captured_output.out == expected_message
Leave a Comment