aboutsummaryrefslogtreecommitdiff
path: root/benchmark/agbenchmark/challenges/verticals/code/3_file_organizer
diff options
context:
space:
mode:
Diffstat (limited to 'benchmark/agbenchmark/challenges/verticals/code/3_file_organizer')
-rw-r--r--benchmark/agbenchmark/challenges/verticals/code/3_file_organizer/artifacts_out/__init__.py0
-rw-r--r--benchmark/agbenchmark/challenges/verticals/code/3_file_organizer/artifacts_out/organize_files.py48
-rw-r--r--benchmark/agbenchmark/challenges/verticals/code/3_file_organizer/custom_python/test.py45
-rw-r--r--benchmark/agbenchmark/challenges/verticals/code/3_file_organizer/data.json29
4 files changed, 122 insertions, 0 deletions
diff --git a/benchmark/agbenchmark/challenges/verticals/code/3_file_organizer/artifacts_out/__init__.py b/benchmark/agbenchmark/challenges/verticals/code/3_file_organizer/artifacts_out/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/benchmark/agbenchmark/challenges/verticals/code/3_file_organizer/artifacts_out/__init__.py
diff --git a/benchmark/agbenchmark/challenges/verticals/code/3_file_organizer/artifacts_out/organize_files.py b/benchmark/agbenchmark/challenges/verticals/code/3_file_organizer/artifacts_out/organize_files.py
new file mode 100644
index 000000000..dcbc77573
--- /dev/null
+++ b/benchmark/agbenchmark/challenges/verticals/code/3_file_organizer/artifacts_out/organize_files.py
@@ -0,0 +1,48 @@
+import argparse
+import os
+import shutil
+
+
+def organize_files(directory_path):
+ # Define file type groups
+ file_types = {
+ "images": [".png", ".jpg", ".jpeg"],
+ "documents": [".pdf", ".docx", ".txt"],
+ "audio": [".mp3", ".wav", ".flac"],
+ }
+
+ # Create the folders if they don't exist
+ for folder_name in file_types.keys():
+ folder_path = os.path.join(directory_path, folder_name)
+ if not os.path.exists(folder_path):
+ os.makedirs(folder_path)
+
+ # Traverse through all files and folders in the specified directory
+ for foldername, subfolders, filenames in os.walk(directory_path):
+ for filename in filenames:
+ # Get file extension
+ _, file_extension = os.path.splitext(filename)
+
+ # Move files to corresponding folders
+ for folder_name, extensions in file_types.items():
+ if file_extension in extensions:
+ old_path = os.path.join(foldername, filename)
+ new_path = os.path.join(directory_path, folder_name, filename)
+ if old_path != new_path:
+ shutil.move(old_path, new_path)
+
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser(
+ description="Organize files in a directory based on their file types"
+ )
+ parser.add_argument(
+ "--directory_path",
+ type=str,
+ required=True,
+ help="The path of the directory to be organized",
+ )
+
+ args = parser.parse_args()
+
+ organize_files(args.directory_path)
diff --git a/benchmark/agbenchmark/challenges/verticals/code/3_file_organizer/custom_python/test.py b/benchmark/agbenchmark/challenges/verticals/code/3_file_organizer/custom_python/test.py
new file mode 100644
index 000000000..224a73427
--- /dev/null
+++ b/benchmark/agbenchmark/challenges/verticals/code/3_file_organizer/custom_python/test.py
@@ -0,0 +1,45 @@
+import os
+import subprocess
+import tempfile
+import unittest
+
+
+class TestOrganizeFiles(unittest.TestCase):
+ def setUp(self):
+ # Create temporary directory
+ self.test_dir = tempfile.mkdtemp()
+
+ # File types and their corresponding directory
+ self.file_types = {
+ "test_image.png": "images",
+ "test_doc.txt": "documents",
+ "test_audio.mp3": "audio",
+ }
+
+ # Create test files
+ for file_name in self.file_types.keys():
+ open(os.path.join(self.test_dir, file_name), "a").close()
+
+ def test_organize_files(self):
+ # Call the organize_files.py script using subprocess
+ subprocess.call(
+ ["python", "organize_files.py", "--directory_path=" + self.test_dir]
+ )
+
+ # Check if the files have been moved to the correct directories
+ for file_name, directory in self.file_types.items():
+ self.assertTrue(
+ os.path.isfile(os.path.join(self.test_dir, directory, file_name))
+ )
+
+ def tearDown(self):
+ # Delete test directory and its contents
+ for file_name, directory in self.file_types.items():
+ os.remove(os.path.join(self.test_dir, directory, file_name))
+ for directory in set(self.file_types.values()):
+ os.rmdir(os.path.join(self.test_dir, directory))
+ os.rmdir(self.test_dir)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/benchmark/agbenchmark/challenges/verticals/code/3_file_organizer/data.json b/benchmark/agbenchmark/challenges/verticals/code/3_file_organizer/data.json
new file mode 100644
index 000000000..c732990ec
--- /dev/null
+++ b/benchmark/agbenchmark/challenges/verticals/code/3_file_organizer/data.json
@@ -0,0 +1,29 @@
+{
+ "category": [
+ "coding",
+ "general"
+ ],
+ "cutoff": 90,
+ "dependencies": [
+ "TestPasswordGenerator"
+ ],
+ "eval_id": "029c1e6f-2b36-451e-bca6-60063b827d2e",
+ "ground": {
+ "answer": "The correct python file is written and organizes the files accordingly",
+ "eval": {
+ "type": "python"
+ },
+ "files": [
+ "test.py"
+ ],
+ "should_contain": [],
+ "should_not_contain": []
+ },
+ "info": {
+ "description": "Tests if the agent can create a file organizer.",
+ "difficulty": "basic",
+ "side_effects": []
+ },
+ "name": "FileOrganizer",
+ "task": "Create a file organizer CLI tool in Python that sorts files in a directory based on their file types (e.g., images, documents, audio) and moves them into these corresponding folders: 'images', 'documents', 'audio'. The entry point will be a python file that can be run this way: python organize_files.py --directory_path=YOUR_DIRECTORY_PATH"
+}