@pytest.fixture() def solution_data(charts): return { "values": [[1, 1, 1], [1, 52, 8]], "formulas": [["=0+1", 1, 1], ["=1+0", "=52", 8]], "charts": charts, } # Tests @pytest.mark.parametrize( "trans, correct", [ (Identity(), True), (Mutation(["charts"], []), False), (Mutation(["charts", 0, "spec", "basicChart", "chartType"], "LINE"), False), (Mutation(["charts", 0, "spec", "title"], "Other title"), False), (Deletion(["charts", 0, "spec", "title"]), False), (Mutation(["charts", 0, "spec", "subTitle"], "something"), False), (Deletion(["charts", 0, "spec", "basicChart", "domains", 0]), False), ( Mutation( [ "charts", 0, "spec", "basicChart", "domains", 0,
{"numberFormat": {"type": "NUMBER", "pattern": "0.00"}}, {"numberFormat": {"type": "NUMBER", "pattern": "0.00"}}, ], ] } # Tests @pytest.mark.parametrize( "trans, sct_range, correct, match", [ (Identity(), "A1", True, None), (Identity(), "A1:B2", True, None), ( Mutation( ["numberFormats", 0, 0], {"numberFormat": {"type": "NUMBER", "pattern": "0.00"}}, ), "A1", True, None, ), ( Mutation(["numberFormats", 1, 0, "numberFormat", "type"], "TEXT"), "A2", False, "Expected a number, but got text", ), ( Mutation(["numberFormats", 0, 1, "numberFormat", "type"], "UNKONWN"), "B1", False,
@pytest.fixture() def user_data_norm_seed(): return { "values": [[1, 1, 1], [1, 52, 8]], "formulas": [["=SUM(A1:C1)", 1, 1], ["= AVaragE(A1)", "=52", 8]], } # Tests @pytest.mark.parametrize( "trans, sct_range, correct", [ (Identity(), "A1", True), (Identity(), "A1:B2", True), (Mutation(["values", 0, 0], 5), "B1", True), (Mutation(["values", 0, 0], 5), "A1", True), (Mutation(["formulas", 0, 0], "=1+0"), "A1", False), (Mutation(["formulas", 0, 0], "=1+0"), "B1", True), (Mutation(["values", 0, 1], 5), "B1", True), (Mutation(["values", 1, 0], "test"), "A1:B2", True), ], ) def test_has_equal_formula(user_data_seed, trans, sct_range, correct): user_data = trans(deepcopy(user_data_seed)) s = setup_state(user_data, user_data_seed, sct_range) with verify_success(correct): has_equal_formula(s) @pytest.mark.parametrize(
@pytest.fixture() def solution_data_normalize(): return { "values": [[1, 1, 1], [1, 52, 8]], "formulas": [["= $B$1", 1, 1], ["=c2", "= $B$2:$c$5", 8]], } # Tests @pytest.mark.parametrize( "trans, sct_range, correct", [ (Identity(), "A1", True), (Mutation(["formulas", 0, 0], "= C1"), "A1", False), (Mutation(["formulas", 0, 0], "= C1"), "B1", True), (Mutation(["formulas", 0, 1], "= C1"), "A1", True), (Mutation(["formulas", 1, 1], "= C1"), "B2", False), (Mutation(["formulas", 0, 1], "= C1"), "A2", True), (Identity(), "B2", True), (Mutation(["formulas", 1, 1], "= A1:A2"), "B2", False), ], ) def test_check_absolute_references(solution_data, trans, sct_range, correct): user_data = trans(deepcopy(solution_data)) s = setup_state(user_data, solution_data, sct_range) with verify_success(correct): has_equal_references(s, absolute=True)
@pytest.fixture() def user_data_seed(): return { "values": [[1, 1, 1], [1, 52, "b"]], "formulas": [["=0+1", 1, 1], ["=1+0", "=52", 8]], } @pytest.mark.parametrize( "trans, sct_range, correct", [ (Identity(), "A1", True), (Identity(), "Z10", False), (Mutation(["values", 0, 0], ""), "A1", False), (Mutation(["values", 0, 0], None), "A1", False), ], ) def test_check_range(user_data_seed, trans, sct_range, correct): user_data = trans(deepcopy(user_data_seed)) s = setup_state(user_data, user_data_seed, sct_range) with verify_success(correct): check_range(s, field="values", field_msg="value") @pytest.mark.parametrize( "trans, sct_range, correct", [ (Identity(), "A1", True), (Identity(), "A1:B2", True),
return { "values": [[1, 1, 1], [1, 52, 8]], "formulas": [["=0+1", 1, 1], ["=1+0", "=52", 8]], "charts": charts, } # Tests # check_chart @pytest.mark.parametrize( "trans, correct, match", [ (Identity(), True, None), (Mutation(["charts"], []), False, "Please create a chart near `E1`."), ( Mutation(["charts", 0, "spec", "basicChart", "chartType"], "LINE"), False, "The chart type .* is not correct", ), (Mutation(["charts", 0, "spec", "title"], "Other title"), True, None), (Mutation(["charts", 0, "spec", "subtitle"], "Other title"), True, None), ], ) def test_check_chart(solution_data, trans, correct, match): solution_data = deepcopy(solution_data) student_data = trans(deepcopy(solution_data)) s = setup_ex_state(student_data, solution_data, "E1")
# Fixtures @pytest.fixture() def user_data_seed(): return { "values": [[1, 1, 1], [1, 52, 8]], "formulas": [["=0+1", 1, 1], ["=1+0", "=52", 8]], } # Tests @pytest.mark.parametrize( "trans, sct_range, pattern, correct", [ (Identity(), "A1", "=0", True), (Identity(), "A1:A2", "=", True), (Mutation(["formulas", 0, 0], "= 1 + 0"), "A1", "=1+0", False), (Mutation(["values", 1, 1], "test"), "B2", "test", False), (Mutation(["formulas", 1, 1], "test"), "B2", "test", True), (Mutation(["formulas", 0, 1], "testtesttest"), "B1", "^(?:test)+$", True), (Mutation(["formulas", 0, 1], ""), "B1", "^(?:test)+$", False), ( compose( Mutation(["formulas", 0, 0], "=0+0"), Mutation(["formulas", 0, 1], "=1+0"), Mutation(["formulas", 1, 0], "=0+1"), Mutation(["formulas", 1, 1], "=1-1"), Mutation(["values", 0, 0], 0), Mutation(["values", 0, 1], 1), Mutation(["values", 1, 0], 1), Mutation(["values", 1, 1], 2),
@pytest.fixture() def solution_data_calculated_field(pivot_tables_with_calculated_field): return { "values": [[1, 1, 1], [1, 52, 8]], "formulas": [["=0+1", 1, 1], ["=1+0", "=52", 8]], "pivotTables": pivot_tables_with_calculated_field, } # Tests @pytest.mark.parametrize( "trans, sct_range, correct, message_contains", [ (Identity(), "A1", True, None), ( Mutation(["pivotTables", 0, 0, "source", "startRowIndex"], 1), "A1", False, r"1 issue(.|\s)*source data", ), ( Mutation(["pivotTables", 0, 0, "source", "endRowIndex"], 1), "A1", False, r"1 issue(.|\s)*source data", ), ( Mutation(["pivotTables", 0, 0, "source", "startColumnIndex"], 1), "A1", False, r"1 issue(.|\s)*source data",
], } } ] ] } # Tests @pytest.mark.parametrize( "trans, sct_range, correct, match", [ (Identity(), "A1", True, None), ( Mutation( ["dataValidations", 0, 0, "condition", "type"], "NUMBER_NOT_BETWEEN" ), "A1", False, "In cell `A1`, did you use the correct data validation?", ), (Mutation(["dataValidations", 0, 0, "strict"], True), "A1", True, None), ( Mutation( ["dataValidations", 0, 0, "condition", "values", 0, "userEnteredValue"], "1", ), "A1", True, None, ),
def solution_data_2(conditional_format_2): return { "values": [[1, 1, 1], [1, 52, 8]], "formulas": [["=0+1", 1, 1], ["=1+0", "=52", 8]], "conditionalFormats": conditional_format_2, } # Tests @pytest.mark.parametrize( "trans, correct, match", [ (Identity(), True, None), ( Mutation( ["conditionalFormats", 0, "booleanRule", "condition", "type"], "other condition", ), False, "condition of the first rule is incorrect", ), ( Mutation( [ "conditionalFormats", 0, "booleanRule", "format", "backgroundColor", "red", ], 0,