def validate_challenge_details(ch_dir): details_file = ch_dir / DETAILS details_str = load_file(details_file) try: details = json.loads(details_str) except json.decoder.JSONDecodeError: raise AssertionError(f'File {details_file} is not a valid JSON.') assert isinstance( details, dict), f'File {details_file} should be a JSON dictionary.' assert 'title' in details, f'File {details_file} should have a key "title".' assert 'published' in details, f'File {details_file} should have a key "published".' assert 'terminal' in details, f'File {details_file} should have a key "terminal".' assert 'concept' in details, f'File {details_file} should have a key "concept".' concept = details['concept'] assert concept in CONCEPTS, f'The concept {concept} does not exist' return details
def validate_json(json_file): json_str = load_file(json_file) try: return json.loads(json_str) except json.decoder.JSONDecodeError: raise AssertionError(f'File {json_file} is not a valid JSON.')
def validate_not_empty(target, msg=None): content = load_file(target, msg) if not msg: msg = f'File {target} should not be empty.' assert content.strip(), msg
def run_test(code_file, test_file, function_name): code = load_file(code_file) tests = load_file(test_file) result = str_test.run_tests(code, tests, function_name) expected = 'solution' in str(code_file) assert expected == result.success, f'Result was different than the expected for the file {code_file}'
def validate_question(ch_dir): question_file = ch_dir / QUESTION question = load_file(question_file) assert question.strip(), f'File {question_file} should not be empty.'