Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #393 from SELab-2/constraint-bug-parsing
Browse files Browse the repository at this point in the history
Constraint bug parsing
  • Loading branch information
msathieu authored May 23, 2024
2 parents c3c78d5 + c1a84a4 commit a5c5ef9
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@

class ExtensionNotPresentConstraint(BaseModel):
type: ConstraintType = ConstraintType.EXTENSION_NOT_PRESENT
extension: str
not_present_extension: str

def validate_constraint(self, path: Path) -> ExtensionNotPresentConstraintResult:
directory = os.listdir(path)

files_with_extension = [file for file in directory if file.endswith(self.extension)]
files_with_extension = [file for file in directory if file.endswith(self.not_present_extension)]

if files_with_extension:
return ExtensionNotPresentConstraintResult(
extension=self.extension,
extension=self.not_present_extension,
is_ok=False,
files_with_extension=files_with_extension,
)

return ExtensionNotPresentConstraintResult(
extension=self.extension,
extension=self.not_present_extension,
is_ok=True,
files_with_extension=files_with_extension,
)
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class FaultyProjectConstraintValidationTest(unittest.TestCase):
submission_constraint = SubmissionConstraint(
root_constraint=ZipConstraint(
zip_name="project.zip",
global_constraints=[ExtensionNotPresentConstraint(extension=".exe")],
global_constraints=[ExtensionNotPresentConstraint(not_present_extension=".exe")],
sub_constraints=[
DirectoryConstraint(
directory_name="src",
Expand All @@ -72,7 +72,7 @@ class FaultyProjectConstraintValidationTest(unittest.TestCase):
FileConstraint(file_name="README.md"),
FileConstraint(file_name=".gitignore"),
NotPresentConstraint(file_or_directory_name="dist"),
ExtensionNotPresentConstraint(extension=".log"),
ExtensionNotPresentConstraint(not_present_extension=".log"),
],
),
)
Expand Down
6 changes: 3 additions & 3 deletions backend/tests/test_simple_submissions/test_everything_ok.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class EverythingOkTest(unittest.TestCase):
submission_constraint = SubmissionConstraint(
root_constraint=ZipConstraint(
zip_name="project.zip",
global_constraints=[ExtensionNotPresentConstraint(extension=".exe")],
global_constraints=[ExtensionNotPresentConstraint(not_present_extension=".exe")],
sub_constraints=[
DirectoryConstraint(
directory_name="src",
Expand All @@ -71,8 +71,8 @@ class EverythingOkTest(unittest.TestCase):
FileConstraint(file_name="README.md"),
FileConstraint(file_name=".gitignore"),
NotPresentConstraint(file_or_directory_name="dist"),
ExtensionNotPresentConstraint(extension=".class"),
ExtensionNotPresentConstraint(extension=".log"),
ExtensionNotPresentConstraint(not_present_extension=".class"),
ExtensionNotPresentConstraint(not_present_extension=".log"),
],
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ class ExtensionNotPresentConstraintValidationTest(unittest.TestCase):
zip_name="submission.zip",
global_constraints=[],
sub_constraints=[
ExtensionNotPresentConstraint(extension=".java"), # .java is present, should fail
ExtensionNotPresentConstraint(extension=".c"), # .c is present, should fail
ExtensionNotPresentConstraint(extension=".cpp"), # .cpp is not present, should pass
ExtensionNotPresentConstraint(not_present_extension=".java"), # .java is present, should fail
ExtensionNotPresentConstraint(not_present_extension=".c"), # .c is present, should fail
ExtensionNotPresentConstraint(not_present_extension=".cpp"), # .cpp is not present, should pass
DirectoryConstraint( # Directory is present, should pass
directory_name="no_txt_in_this_folder",
sub_constraints=[ExtensionNotPresentConstraint(extension=".txt")], # .txt is present, should fail
sub_constraints=[ExtensionNotPresentConstraint(not_present_extension=".txt")], # .txt is
# present, should fail
),
],
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class GlobalConstraintValidationTest(unittest.TestCase):
root_constraint=ZipConstraint(
zip_name="submission.zip",
global_constraints=[
ExtensionNotPresentConstraint(extension=".java"),
ExtensionNotPresentConstraint(extension=".c"),
ExtensionNotPresentConstraint(extension=".cpp"),
ExtensionNotPresentConstraint(not_present_extension=".java"),
ExtensionNotPresentConstraint(not_present_extension=".c"),
ExtensionNotPresentConstraint(not_present_extension=".cpp"),
NotPresentConstraint(file_or_directory_name="dir4"),
],
sub_constraints=[],
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/SimpleTests/SimpleTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function json_to_submission(json: any): Submission {
break;
}
case 'EXTENSION_NOT_PRESENT': {
constraint = new Constraint('EXTENSION_NOT_PRESENT', json['extension'], id, parent_id, depth);
constraint = new Constraint('EXTENSION_NOT_PRESENT', json['not_present_extension'], id, parent_id, depth);
break;
}
case 'EXTENSION_ONLY_PRESENT': {
Expand Down Expand Up @@ -147,7 +147,7 @@ function json_to_submission(json: any): Submission {
break;
}
case 'EXTENSION_NOT_PRESENT': {
constraint = new Constraint('EXTENSION_NOT_PRESENT', json['extension'], id, undefined, 0);
constraint = new Constraint('EXTENSION_NOT_PRESENT', json['not_present_extension'], id, undefined, 0);
break;
}
case 'EXTENSION_ONLY_PRESENT': {
Expand Down Expand Up @@ -194,7 +194,7 @@ function submission_to_json(submission: Submission): object {
constraint_object['file_or_directory_name'] = constraint.value;
break;
case 'EXTENSION_NOT_PRESENT':
constraint_object['extension'] = constraint.value;
constraint_object['not_present_extension'] = constraint.value;
break;
case 'EXTENSION_ONLY_PRESENT':
constraint_object['extension'] = constraint.value;
Expand Down

0 comments on commit a5c5ef9

Please sign in to comment.