xref: /trunk/test/aoo-test/tests/selftest/conftest.py (revision 2cb6d6f119bbe2f78742f1c5c8538cb0d4e72ede)
1*2cb6d6f1SJim Jagielski################################################################
2*2cb6d6f1SJim Jagielski#
3*2cb6d6f1SJim Jagielski#  Licensed to the Apache Software Foundation (ASF) under one
4*2cb6d6f1SJim Jagielski#  or more contributor license agreements.  See the NOTICE file
5*2cb6d6f1SJim Jagielski#  distributed with this work for additional information
6*2cb6d6f1SJim Jagielski#  regarding copyright ownership.  The ASF licenses this file
7*2cb6d6f1SJim Jagielski#  to you under the Apache License, Version 2.0 (the
8*2cb6d6f1SJim Jagielski#  "License"); you may not use this file except in compliance
9*2cb6d6f1SJim Jagielski#  with the License.  You may obtain a copy of the License at
10*2cb6d6f1SJim Jagielski#
11*2cb6d6f1SJim Jagielski#    http://www.apache.org/licenses/LICENSE-2.0
12*2cb6d6f1SJim Jagielski#
13*2cb6d6f1SJim Jagielski#  Unless required by applicable law or agreed to in writing,
14*2cb6d6f1SJim Jagielski#  software distributed under the License is distributed on an
15*2cb6d6f1SJim Jagielski#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2cb6d6f1SJim Jagielski#  KIND, either express or implied.  See the License for the
17*2cb6d6f1SJim Jagielski#  specific language governing permissions and limitations
18*2cb6d6f1SJim Jagielski#  under the License.
19*2cb6d6f1SJim Jagielski#
20*2cb6d6f1SJim Jagielski################################################################
21*2cb6d6f1SJim Jagielski
22*2cb6d6f1SJim Jagielski"""Fixtures for the checker self-tests: negative-control packages built in a temp dir, and the checkers run over them once per session.
23*2cb6d6f1SJim Jagielski
24*2cb6d6f1SJim JagielskiTests that need java, jing or the OASIS schemas skip with a reason when they are not available (AOO_JING, AOO_SCHEMA_DIR,
25*2cb6d6f1SJim JagielskiAOO_ODFVALIDATOR, AOO_JAVA, or the cache that `python -m aootest.fetch` fills).
26*2cb6d6f1SJim Jagielski"""
27*2cb6d6f1SJim Jagielskiimport pytest
28*2cb6d6f1SJim Jagielski
29*2cb6d6f1SJim Jagielskifrom aootest import controls, tools
30*2cb6d6f1SJim Jagielskifrom aootest.checkers import doctypecheck, idcheck, pkgcheck, validate
31*2cb6d6f1SJim Jagielski
32*2cb6d6f1SJim Jagielski
33*2cb6d6f1SJim Jagielski@pytest.fixture(scope="session")
34*2cb6d6f1SJim Jagielskidef jing_cmd():
35*2cb6d6f1SJim Jagielski    cmd = tools.jing_command()
36*2cb6d6f1SJim Jagielski    if cmd is None:
37*2cb6d6f1SJim Jagielski        pytest.skip("needs java and a jing jar (set AOO_JING or run: python -m aootest.fetch)")
38*2cb6d6f1SJim Jagielski    return cmd
39*2cb6d6f1SJim Jagielski
40*2cb6d6f1SJim Jagielski
41*2cb6d6f1SJim Jagielski@pytest.fixture(scope="session")
42*2cb6d6f1SJim Jagielskidef schema_dir():
43*2cb6d6f1SJim Jagielski    d = tools.schema_dir()
44*2cb6d6f1SJim Jagielski    if d is None:
45*2cb6d6f1SJim Jagielski        pytest.skip("needs the OASIS ODF schemas (set AOO_SCHEMA_DIR or run: python -m aootest.fetch)")
46*2cb6d6f1SJim Jagielski    return d
47*2cb6d6f1SJim Jagielski
48*2cb6d6f1SJim Jagielski
49*2cb6d6f1SJim Jagielski@pytest.fixture(scope="session")
50*2cb6d6f1SJim Jagielskidef odf_controls(tmp_path_factory):
51*2cb6d6f1SJim Jagielski    d = tmp_path_factory.mktemp("control")
52*2cb6d6f1SJim Jagielski    controls.make_odf_controls(d)
53*2cb6d6f1SJim Jagielski    return d
54*2cb6d6f1SJim Jagielski
55*2cb6d6f1SJim Jagielski
56*2cb6d6f1SJim Jagielski@pytest.fixture(scope="session")
57*2cb6d6f1SJim Jagielskidef val(odf_controls, jing_cmd, schema_dir, tmp_path_factory):
58*2cb6d6f1SJim Jagielski    return validate.check(odf_controls, tmp_path_factory.mktemp("validate"), jing_cmd, schema_dir)
59*2cb6d6f1SJim Jagielski
60*2cb6d6f1SJim Jagielski
61*2cb6d6f1SJim Jagielski@pytest.fixture(scope="session")
62*2cb6d6f1SJim Jagielskidef errs(val):
63*2cb6d6f1SJim Jagielski    """errs(version, package) -> the messages jing reported for that package in that schema version."""
64*2cb6d6f1SJim Jagielski    return lambda v, pkg: [e[3] for e in val["errors"][v] if e[0].startswith(pkg + "/")]
65*2cb6d6f1SJim Jagielski
66*2cb6d6f1SJim Jagielski
67*2cb6d6f1SJim Jagielski@pytest.fixture(scope="session")
68*2cb6d6f1SJim Jagielskidef ids(odf_controls):
69*2cb6d6f1SJim Jagielski    return idcheck.check(odf_controls)
70*2cb6d6f1SJim Jagielski
71*2cb6d6f1SJim Jagielski
72*2cb6d6f1SJim Jagielski@pytest.fixture(scope="session")
73*2cb6d6f1SJim Jagielskidef pkg_result(jing_cmd, schema_dir, tmp_path_factory):
74*2cb6d6f1SJim Jagielski    d = tmp_path_factory.mktemp("control-pkg")
75*2cb6d6f1SJim Jagielski    controls.make_pkg_controls(d)
76*2cb6d6f1SJim Jagielski    return pkgcheck.check(d, tmp_path_factory.mktemp("pkgcheck"), jing_cmd, schema_dir)
77*2cb6d6f1SJim Jagielski
78*2cb6d6f1SJim Jagielski
79*2cb6d6f1SJim Jagielski@pytest.fixture(scope="session")
80*2cb6d6f1SJim Jagielskidef doctype_result(tmp_path_factory):
81*2cb6d6f1SJim Jagielski    d = tmp_path_factory.mktemp("control-doctype")
82*2cb6d6f1SJim Jagielski    controls.make_doctype_controls(d)
83*2cb6d6f1SJim Jagielski    return doctypecheck.check(d)
84