Skip to content

Commit

Permalink
Added Scripts to execute copying task
Browse files Browse the repository at this point in the history
  • Loading branch information
az108 committed Sep 8, 2024
1 parent be08064 commit 413557f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 5 deletions.
16 changes: 11 additions & 5 deletions supporting_scripts/course-scripts/quick-course-setup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,21 @@ The script will automatically perform all the necessary steps:

If you want to generate different results for all the students created by the script:

1. Navigate to the [testFiles](../../../src/main/resources/templates/java/test/testFiles) folder and copy the [RandomizedTestCases](./testFiles-template/randomized/RandomizedTestCases.java) file into it.
If you want, you can delete the existing folders (behavior and structural) from the programming exercise’s test case template. The new test cases will randomly pass or fail, causing different results for each student.
2. Rebuild Artemis to apply the changes.
1. Run the following Script which will navigate to the [testFiles](../../../src/main/resources/templates/java/test/testFiles) folder and copy the [RandomizedTestCases](./testFiles-template/randomized/RandomizedTestCases.java) file into it.
It will delete the existing folders (behavior and structural) from the programming exercise’s test case template. The new test cases will randomly pass or fail, causing different results for each student.
```shell
python3 randomize_results_before.py
```
2. Rebuild Artemis to apply the changes.
3. Run the main method in large_course_main.py. Now, all created students should have varying results in the programming exercise.
```shell
python3 large_course_main.py
```
4. Make sure to revert these changes after running the script. You can copy the original test case files from the [default](./testFiles-template/default) folder back into the [testFiles](../../../src/main/resources/templates/java/test/testFiles) folder and delete the [RandomizedTestCases](./testFiles-template/randomized/RandomizedTestCases.java) file that was copied to [testFiles](../../../src/main/resources/templates/java/test/testFiles) in Step 1.
Otherwise, you risk breaking the real template of the programming exercise if these changes are pushed.
4. Make sure to revert these changes after running the script. The following script copies the original test case files from the [default](./testFiles-template/default) folder back into the [testFiles](../../../src/main/resources/templates/java/test/testFiles) folder and deletes the [RandomizedTestCases](./testFiles-template/randomized/RandomizedTestCases.java) file that was copied to [testFiles](../../../src/main/resources/templates/java/test/testFiles) in Step 1.
If you don't run this script after running the script in Step 1, you risk breaking the real template of the programming exercise if these changes are pushed and merged.
```shell
python3 randomize_results_after.py
```

### Optional: Using an Existing Programming Exercise (Can also be done on Test Server)
Alternatively, you can use an existing programming exercise and push the [RandomizedTestCases](./testFiles-template/randomized/RandomizedTestCases.java) file to the test repository of the programming exercise.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os
import shutil
from logging_config import logging

test_files_folder = "../../../src/main/resources/templates/java/test/testFiles"
default_folder = "./testFiles-template/default"
random_test_case_dest = os.path.join(test_files_folder, "RandomizedTestCases.java")

def delete_random_test_case():
if os.path.exists(random_test_case_dest):
os.remove(random_test_case_dest)
logging.info(f"Deleted file: {random_test_case_dest}")
else:
logging.info(f"RandomizedTestCases.java file not found at {random_test_case_dest}")

def copy_default_folders():
for folder_name in os.listdir(default_folder):
src_folder_path = os.path.join(default_folder, folder_name)
dest_folder_path = os.path.join(test_files_folder, folder_name)
if os.path.isdir(src_folder_path):
shutil.copytree(src_folder_path, dest_folder_path)
logging.info(f"Copied folder {src_folder_path} to {dest_folder_path}")

if __name__ == "__main__":
# Run this after running the script
delete_random_test_case()
copy_default_folders()
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os
import shutil
from logging_config import logging

test_files_folder = "../../../src/main/resources/templates/java/test/testFiles"
random_test_case_file = "./testFiles-template/randomized/RandomizedTestCases.java"
random_test_case_dest = os.path.join(test_files_folder, "RandomizedTestCases.java")

def delete_existing_folders():
folders_to_delete = ["behavior", "structural"]
for folder in folders_to_delete:
folder_path = os.path.join(test_files_folder, folder)
if os.path.exists(folder_path) and os.path.isdir(folder_path):
shutil.rmtree(folder_path)
logging.info(f"Deleted folder: {folder_path}")
else:
logging.info(f"Folder not found: {folder_path}")

def copy_random_test_case():
if os.path.exists(random_test_case_file):
shutil.copy(random_test_case_file, random_test_case_dest)
logging.info(f"Copied {random_test_case_file} to {random_test_case_dest}")
else:
logging.info(f"RandomizedTestCases.java file not found at {random_test_case_file}")

if __name__ == "__main__":
# Run this before running the script
delete_existing_folders()
copy_random_test_case()

0 comments on commit 413557f

Please sign in to comment.