diff --git a/source/utils/config/Config.py b/source/utils/config/Config.py index 1d079a0..6a697ab 100644 --- a/source/utils/config/Config.py +++ b/source/utils/config/Config.py @@ -116,31 +116,13 @@ class AutograderConfigurationSchema(BaseSchema[AutograderConfiguration]): This class builds to :ref:`AutograderConfiguration` for easy typing. """ - TAGS_ENDPOINT = "https://api.github.com/repos/CSCI128/128Autograder/tags" IMPL_SOURCE = "./StudentSubmissionImpl" - @staticmethod - def getAvailableTags() -> List[str]: - """ - Description - --- - This method gets the currently available version tags from GitHub. - This ensures that any version of the autorgader is using a spefic version of the autograder. - :return: a list of all the valid tags from GitHub - """ - headers = {"X-GitHub-Api-Version": "2022-11-28"} - - tags = requests.get(url=AutograderConfigurationSchema.TAGS_ENDPOINT, headers=headers).json() - - return [el["name"] for el in tags] - @staticmethod def validateImplSource(implName: str) -> bool: return implName in os.listdir(AutograderConfigurationSchema.IMPL_SOURCE) def __init__(self): - self.TAGS = self.getAvailableTags() - self.currentSchema: Schema = Schema( { "assignment_name": And(str, Regex(r"^(\w+-?)+$")), @@ -148,7 +130,7 @@ def __init__(self): "config": { "impl_to_use": And(str, AutograderConfigurationSchema.validateImplSource), Optional("student_submission_directory", default="."): And(str, os.path.exists, os.path.isdir), - "autograder_version": And(str, lambda x: x in self.TAGS), + "autograder_version": And(str, Regex(r"\d+\.\d+\.\d+")), "test_directory": And(str, os.path.exists), "enforce_submission_limit": bool, Optional("submission_limit", default=1000): And(int, lambda x: x >= 1), diff --git a/source/utils/student/test_my_work.py b/source/utils/student/test_my_work.py index 177dc92..4ef3690 100644 --- a/source/utils/student/test_my_work.py +++ b/source/utils/student/test_my_work.py @@ -14,7 +14,7 @@ SUBMISSION_REGEX: re.Pattern = re.compile(r"^(\w|\s)+\.py$") FILE_HASHES_NAME: str = ".filehashes" -REQUIRED_PACKAGES = {"gradescope_utils":"gradescope-utils", "dill":"dill", "BetterPytUnitFormat":"Better-PyUnit-Format", "schema":"schema", "requests":"requests", "tomli":"tomli"} +REQUIRED_PACKAGES = {"gradescope_utils":"gradescope-utils", "dill":"dill", "BetterPyUnitFormat":"Better-PyUnit-Format", "schema":"schema", "requests":"requests", "tomli":"tomli"} def printErrorMessage(errorType: str, errorText: str) -> None: """ @@ -40,8 +40,9 @@ def verifyRequiredPackages(packagesToVerify: dict[str, str]) -> bool: for name, package in packagesToVerify.items(): if importlib.util.find_spec(name) is None: - print(f"Installing missing dependancy: {package}") - subprocess.run([sys.executable, "-m", "pip", "install", package]) + print(f"Installing missing dependancy: {package}...", end="") + subprocess.run([sys.executable, "-m", "pip", "install", package], stdout=subprocess.DEVNULL) + print(f"Done.") return not errorOccurred @@ -157,10 +158,7 @@ def verifyFileChanged(submissionDirectory: str) -> bool: command: list[str] = [sys.executable, "run.py", "--unit-test-only", "--submission-directory", submissionDirectory] - with subprocess.Popen(command, stdout=subprocess.PIPE, bufsize=1, universal_newlines=True) as p: - if p.stdout is not None: - for line in p.stdout: - print(line, end="") + subprocess.run(command) if not fileChanged: printWarningMessage("Student Submission Warning", "Student submision may not have changed") diff --git a/tests/testAutograderConfigurationSchema.py b/tests/testAutograderConfigurationSchema.py index a690b9b..3ce642b 100644 --- a/tests/testAutograderConfigurationSchema.py +++ b/tests/testAutograderConfigurationSchema.py @@ -6,24 +6,6 @@ from utils.config.Config import AutograderConfigurationSchema, InvalidConfigException -def mockRequestsGet(url, **kwargs): - class Response: - def __init__(self, jsonData, status: int): - self.jsonData = jsonData - self.statusCode = status - - def json(self): - return self.jsonData - - if re.match(r"https://api\.github\.com/repos/(\w|\d)+/(\w|\d)+/tags", url): - data = \ - [ - {"name": "1.0.0"}, - {"name": "2.0.0"} - ] - - return Response(data, 200) - def mockValidateImpl(_) -> bool: return True class TestAutograderConfigurationSchema(unittest.TestCase): @@ -51,9 +33,8 @@ def setUp(self) -> None: @staticmethod def createAutograderConfigurationSchema() -> AutograderConfigurationSchema: - with mock.patch('requests.get', side_effect=mockRequestsGet): - AutograderConfigurationSchema.validateImplSource = mockValidateImpl # type: ignore - return AutograderConfigurationSchema() + AutograderConfigurationSchema.validateImplSource = mockValidateImpl # type: ignore + return AutograderConfigurationSchema() def testValidNoOptionalFields(self): schema = self.createAutograderConfigurationSchema() @@ -98,7 +79,7 @@ def testExtraFields(self): def testInvalidAutograderVersion(self): schema = self.createAutograderConfigurationSchema() - self.configFile["config"]["autograder_version"] = "0.0.0" + self.configFile["config"]["autograder_version"] = "0.0" with self.assertRaises(InvalidConfigException): schema.validate(self.configFile)