1################################################################ 2# 3# Licensed to the Apache Software Foundation (ASF) under one 4# or more contributor license agreements. See the NOTICE file 5# distributed with this work for additional information 6# regarding copyright ownership. The ASF licenses this file 7# to you under the Apache License, Version 2.0 (the 8# "License"); you may not use this file except in compliance 9# with the License. You may obtain a copy of the License at 10# 11# http://www.apache.org/licenses/LICENSE-2.0 12# 13# Unless required by applicable law or agreed to in writing, 14# software distributed under the License is distributed on an 15# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16# KIND, either express or implied. See the License for the 17# specific language governing permissions and limitations 18# under the License. 19 20"""Calc formula results against what ODF 1.3 Part 4 (OpenFormula) requires: one test per case in data/calcval-cases.tsv. 21A case with no expected value ('-') only has to evaluate. Deviations that are known are rows in data/expect/calcval.tsv.""" 22import pytest 23 24from aootest import calcval 25from aootest.client import WorkerFailure 26 27CASES = calcval.read_cases() 28CHUNK = 25 29 30 31@pytest.fixture(scope="module") 32def results(aoo_offices): 33 """{case id: record}, from the worker in chunks, so a crash costs one chunk and the office is restarted for the next.""" 34 session, out = aoo_offices.get(None), {} 35 for i in range(0, len(CASES), CHUNK): 36 chunk = CASES[i:i + CHUNK] 37 try: 38 res = session.call("calc_eval", {"cases": [{k: c[k] for k in ("id", "formula", "mode")} for c in chunk]}, timeout=300) 39 except WorkerFailure as e: 40 out.update({c["id"]: {"id": c["id"], "exception": "%s: %s" % (type(e).__name__, e)} for c in chunk}) 41 continue 42 out.update({r["id"]: r for r in res["cases"]}) 43 out.update({c["id"]: {"id": c["id"], "exception": "not evaluated: the batch stopped at %s" % res["aborted_at"]} 44 for c in chunk if c["id"] not in out}) 45 return out 46 47 48@pytest.mark.parametrize("case", CASES, ids=[c["id"] for c in CASES]) 49def test_formula_result(results, case): 50 rec = results[case["id"]] 51 assert "exception" not in rec, rec["exception"] 52 assert calcval.judge(case["expected"], rec["result"]) in ("match", "record"), \ 53 "%s: expected %s, got %s" % (case["formula"], case["expected"], calcval.summary(rec["result"])) 54