Spaces:
Runtime error
Runtime error
import json | |
import os | |
from random import choices | |
from typing import List | |
from src.common import data_dir | |
class TestGenerator: | |
""" | |
Wrapper to hold testing questions and serve up examples | |
""" | |
questions: List[str] = None | |
def load_questions(cls, reload=False) -> None: | |
""" | |
Load the available questions from the json file. | |
Default to not re-loading if already done, but allow for the option to do so | |
""" | |
if cls.questions is not None and not reload: | |
return | |
question_file = os.path.join(data_dir, 'json', 'test_questions.json') | |
with open(question_file, 'r') as f: | |
question_json = json.load(f) | |
cls.questions = question_json['questions'] | |
def question_count(cls) -> int: | |
cls.load_questions() | |
return len(cls.questions) | |
def get_random_questions(cls, n: int): | |
""" | |
Return n random questions | |
""" | |
return choices(cls.questions, k=n) | |