xref: /trunk/test/aoo-test/tests/selftest/test_idcheck.py (revision 2cb6d6f119bbe2f78742f1c5c8538cb0d4e72ede)
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"""idcheck.check() on the negative controls."""
23import pytest
24
25pytestmark = pytest.mark.selftest
26
27
28def ierrs(ids, pkg):
29    return [e[3] for e in ids["errors"] if e[0].startswith(pkg + "/")]
30
31
32ROWS = [
33    ("good.odt, goodid.odt (normalized ids) clean", lambda I: not I("good.odt") and not I("goodid.odt")),
34    ("dupid.odt flags the duplicate after normalization", lambda I: any("duplicates" in m for m in I("dupid.odt"))),
35    ("badid.odt, badid2.odt flag non-NCName ids", lambda I: all(any("not an NCName" in m for m in I(p)) for p in ("badid.odt", "badid2.odt"))),
36    ("badns.odt flags the unbound prefix", lambda I: any("unbound prefix" in m for m in I("badns.odt"))),
37    ("badsig.odt flags a duplicate id in a signature file", lambda I: any("duplicates" in m for m in I("badsig.odt"))),
38]
39
40
41@pytest.mark.parametrize("row", [pytest.param(r[1], id=r[0]) for r in ROWS])
42def test_idcheck_controls(row, ids):
43    assert row(lambda pkg: ierrs(ids, pkg))
44
45
46def test_idcheck_no_errors_in_other_packages(ids):
47    assert {e[0].split("/")[0] for e in ids["errors"]} == {"dupid.odt", "badid.odt", "badid2.odt", "badns.odt", "badsig.odt"}
48