コード例 #1
0

@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",
コード例 #2
0
                {"numberFormat": {"type": "NUMBER", "pattern": "0.00"}},
                {"numberFormat": {"type": "NUMBER", "pattern": "0.00"}},
                {"numberFormat": {"type": "NUMBER", "pattern": "0.00"}},
                {"numberFormat": {"type": "NUMBER", "pattern": "0.00"}},
                {"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",
コード例 #3
0
    }


@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)
コード例 #4
0
from tests.helper import Identity, Mutation, Deletion, setup_state, verify_success
from sheetwhat.checks import check_range, has_equal_value


@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",
    [
コード例 #5
0
def solution_data(charts):
    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))
コード例 #6
0

# 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),
コード例 #7
0
                        "values": [
                            {"userEnteredValue": "1"},
                            {"userEnteredValue": "10"},
                        ],
                    }
                }
            ]
        ]
    }


# 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",
コード例 #8
0

@pytest.fixture()
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",