def test_ver_map_verions_in_range(): spec = SpecVerifier.demo() vm = make_random_version_map(spec) vm[1][1] = -1 raises(AssertionError, lambda: check_version_map(vm)) vm[1][1] = spec["numberOfQuestions"] + 1 raises(AssertionError, lambda: check_version_map(vm, spec))
def test_ver_map_json_roundtrip(): spec = SpecVerifier.demo() vm = make_random_version_map(spec) s = json.dumps(vm) vm2 = json.loads(s) assert vm != vm2 # I mean, we'd like, but Json doesn't vm3 = undo_json_packing_of_version_map(vm2) assert vm == vm3
def test_spec_question_label_printer(): sd = SpecVerifier.demo() r = deepcopy(raw) r["question"]["1"]["label"] = "Track 1" r["question"]["2"]["label"] = "" s = SpecVerifier(r) assert get_question_label(s, 1) == "Track 1" assert get_question_label(s, 2) == "Q2" assert get_question_label(s, 3) == get_question_label(sd, 3)
def test_spec_question_label_printer_errors(): s = SpecVerifier.demo() N = s["numberOfQuestions"] raises(ValueError, lambda: get_question_label(s, N + 1)) raises(ValueError, lambda: get_question_label(s, -1)) raises(ValueError, lambda: get_question_label(s, 0))
def test_spec_verify(): s = SpecVerifier.demo() s.verifySpec(verbose=False)
def test_spec_demo(): s = SpecVerifier.demo() assert s.number_to_name assert s.number_to_produce
# SPDX-License-Identifier: AGPL-3.0-or-later # Copyright (C) 2021 Colin B. Macdonald from pytest import raises from copy import deepcopy from plom import SpecVerifier, get_question_label raw = SpecVerifier.demo().spec def test_spec_demo(): s = SpecVerifier.demo() assert s.number_to_name assert s.number_to_produce def test_spec_verify(): s = SpecVerifier.demo() s.verifySpec(verbose=False) def test_spec_too_many_named(): r = raw.copy() r["numberToProduce"] = 50 r["numberToName"] = 60 s = SpecVerifier(r) raises(ValueError, lambda: s.verifySpec(verbose=False)) def test_spec_negatives_still_pass(): r = raw.copy()
def test_ver_map_from_dict(): spec = SpecVerifier.demo() spec_dict = spec.get_public_spec_dict() vm = make_random_version_map(spec_dict) check_version_map(vm, spec_dict) check_version_map(vm, spec)
def test_ver_map_check_spec_or_dict(): spec = SpecVerifier.demo() vm = make_random_version_map(spec) vm.pop(1) raises(AssertionError, lambda: check_version_map(vm, spec)) raises(AssertionError, lambda: check_version_map(vm, spec.get_public_spec_dict()))
def test_ver_map_fix_has_ver1_only(): # assumes version 2 is fixed in demo: test will need adjusting if that changes spec = SpecVerifier.demo() vm = make_random_version_map(spec) vm[1][2] = 2 raises(AssertionError, lambda: check_version_map(vm, spec))
def test_ver_map_types4(): spec = SpecVerifier.demo() vm = make_random_version_map(spec) vm[1][2] = "str" raises(AssertionError, lambda: check_version_map(vm))
def test_ver_map_types3(): spec = SpecVerifier.demo() vm = make_random_version_map(spec) vm[1]["2"] = vm[1].pop(2) raises(AssertionError, lambda: check_version_map(vm))
def test_ver_map_fails_if_too_short(): spec = SpecVerifier.demo() vm = make_random_version_map(spec) vm.pop(1) check_version_map(vm) # passes if we don't know spec raises(AssertionError, lambda: check_version_map(vm, spec))
def test_make_rand_ver_map(): spec = SpecVerifier.demo() vm = make_random_version_map(spec) check_version_map(vm) check_version_map(vm, spec)