-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be195a0
commit 6988ff0
Showing
3 changed files
with
58 additions
and
1 deletion.
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,15 @@ | ||
name: Validate questions | ||
|
||
# Configures this workflow to run every time a change is pushed to the branch called `release`. | ||
on: [pull_request] | ||
|
||
jobs: | ||
validate-questions: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Validate questions | ||
run: python scripts/validate_questions.py | ||
shell: sh |
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,33 @@ | ||
import os | ||
import json | ||
import logging | ||
|
||
logging.basicConfig(level=logging.DEBUG) | ||
|
||
for filename in os.listdir("data/questions"): | ||
logging.info("Analyzing " + filename) | ||
with open(os.path.join("data/questions", filename), 'r') as f: | ||
text = f.read() | ||
try: | ||
data = json.loads(text) | ||
|
||
for q in data: | ||
if q["quest"] == "" and q["image"] == "": | ||
raise Exception(str(data.index(q)) + ") Question's text and image cannot both be empty.") | ||
if q["quest"] is None or q["image"] is None or q["answers"] is None or q["correct"] is None: | ||
raise Exception(str(data.index(q)) + ") Some parameters are null or missing.") | ||
|
||
if len(q["answers"]) == 0: | ||
raise Exception(str(data.index(q)) + ") Question has no answers.") | ||
|
||
for a in q["answers"]: | ||
if a["text"] == "" and a["image"] == "": | ||
raise Exception(str(data.index(q)) + ") Answer's text and image cannot both be empty.") | ||
if a["text"] is None or a["image"] is None: | ||
raise Exception(str(data.index(q)) + ") Some answer's parameters are null or missing.") | ||
|
||
except Exception as e: | ||
logging.error(getattr(e, 'message', repr(e))) | ||
logging.fatal(filename + " is invalid. Aborting.") | ||
|
||
logging.info("Parsing successful!") |