-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make test-gathering script accessible through CLI
- Loading branch information
1 parent
9d90ff9
commit f564e5b
Showing
4 changed files
with
95 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import shutil | ||
import argparse | ||
from pathlib import Path | ||
|
||
def gather(ccids_file: str, | ||
search_path: str, | ||
project_name: str, | ||
output_dir: str = "submitted-testfiles"): | ||
""" | ||
Gather all the testfiles in student directories. Look for directories in | ||
@search_path that contain @project_name. Inside each project look for | ||
tests/testfiles/TEAM_NAME and copy it out. | ||
""" | ||
search_dir = Path(search_path) | ||
|
||
if not search_dir.is_dir(): | ||
error = "Could not create test directory." | ||
print(error) | ||
return 1 | ||
|
||
directories = [d for d in search_dir.iterdir() if d.is_dir() and project_name in d.name] | ||
ccids = Path(ccids_file).read_text().splitlines() | ||
|
||
output_path = Path(output_dir) | ||
output_path.mkdir(parents=True, exist_ok=True) | ||
|
||
for dir_path in directories: | ||
for ccid in ccids: | ||
if ccid in str(dir_path): | ||
expected_test_dir = dir_path / "tests" / "testfiles" / ccid | ||
if expected_test_dir.is_dir(): | ||
print(f"-- Found properly formatted testfiles for {ccid}") | ||
shutil.copytree(expected_test_dir, output_path / ccid, dirs_exist_ok=True) | ||
else: | ||
print(f"-- Could NOT find testfiles for {ccid}") | ||
|
||
if __name__ == '__main__': | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument("ccids_file", type=Path, help="File containing CCIDs") | ||
parser.add_argument("search_path", type=Path, help="Path to search for test files") | ||
parser.add_argument("project_name", type=Path, help="Path to search for test files") | ||
args = parser.parse_args() | ||
|
||
gather(args.ccids_file, args.search_path, args.project_name) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,39 @@ | ||
|
||
from typing import List | ||
from pathlib import Path | ||
from dragon_runner.scripts.build import build | ||
# from dragon_runner.scripts.gather import gather | ||
from dragon_runner.scripts.gather import gather | ||
|
||
class Loader: | ||
""" | ||
Dragon runner allows grading scripts to be run through its CLI. | ||
""" | ||
|
||
def __init__(self, script: str, args: List[str]): | ||
self.script = script | ||
self.args = args | ||
|
||
self.errors = [] | ||
|
||
def run(self): | ||
|
||
""" | ||
Select the script to run from the mode argument passed through | ||
dragon-runner CLI. | ||
""" | ||
|
||
def unknown_script(): | ||
print(f"script: {self.script} did not match any registered script.") | ||
|
||
print(f"Running: {self.script} with args {self.args}") | ||
|
||
{ | ||
"build": lambda: build(*self.args), | ||
}.get(self.script, lambda: unknown_script)() | ||
|
||
script_dispatch = { | ||
"build": lambda: build(*self.args), | ||
"gather": lambda: gather(*self.args), | ||
"anon-tests": lambda: print("TODO"), | ||
"anon-csv": lambda: print("TODO"), | ||
"preview": lambda: print("TODO") | ||
} | ||
|
||
try: | ||
print(f"Running: {self.script} with args {self.args}") | ||
script_dispatch.get(self.script, lambda: unknown_script)() | ||
|
||
except Exception as e: | ||
print(f"Failed to run script: {e}") | ||
|
This file was deleted.
Oops, something went wrong.