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################################################################ 21 22"""Fixtures for the checker self-tests: negative-control packages built in a temp dir, and the checkers run over them once per session. 23 24Tests that need java, jing or the OASIS schemas skip with a reason when they are not available (AOO_JING, AOO_SCHEMA_DIR, 25AOO_ODFVALIDATOR, AOO_JAVA, or the cache that `python -m aootest.fetch` fills). 26""" 27import pytest 28 29from aootest import controls, tools 30from aootest.checkers import doctypecheck, idcheck, pkgcheck, validate 31 32 33@pytest.fixture(scope="session") 34def jing_cmd(): 35 cmd = tools.jing_command() 36 if cmd is None: 37 pytest.skip("needs java and a jing jar (set AOO_JING or run: python -m aootest.fetch)") 38 return cmd 39 40 41@pytest.fixture(scope="session") 42def schema_dir(): 43 d = tools.schema_dir() 44 if d is None: 45 pytest.skip("needs the OASIS ODF schemas (set AOO_SCHEMA_DIR or run: python -m aootest.fetch)") 46 return d 47 48 49@pytest.fixture(scope="session") 50def odf_controls(tmp_path_factory): 51 d = tmp_path_factory.mktemp("control") 52 controls.make_odf_controls(d) 53 return d 54 55 56@pytest.fixture(scope="session") 57def val(odf_controls, jing_cmd, schema_dir, tmp_path_factory): 58 return validate.check(odf_controls, tmp_path_factory.mktemp("validate"), jing_cmd, schema_dir) 59 60 61@pytest.fixture(scope="session") 62def errs(val): 63 """errs(version, package) -> the messages jing reported for that package in that schema version.""" 64 return lambda v, pkg: [e[3] for e in val["errors"][v] if e[0].startswith(pkg + "/")] 65 66 67@pytest.fixture(scope="session") 68def ids(odf_controls): 69 return idcheck.check(odf_controls) 70 71 72@pytest.fixture(scope="session") 73def pkg_result(jing_cmd, schema_dir, tmp_path_factory): 74 d = tmp_path_factory.mktemp("control-pkg") 75 controls.make_pkg_controls(d) 76 return pkgcheck.check(d, tmp_path_factory.mktemp("pkgcheck"), jing_cmd, schema_dir) 77 78 79@pytest.fixture(scope="session") 80def doctype_result(tmp_path_factory): 81 d = tmp_path_factory.mktemp("control-doctype") 82 controls.make_doctype_controls(d) 83 return doctypecheck.check(d) 84