xref: /trunk/test/aoo-test/src/aootest/expect.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"""Known deviations as data: rows of test_name<TAB>kind<TAB>reason in data/expect/*.tsv, applied as pytest marks.
23*2cb6d6f1SJim Jagielski
24*2cb6d6f1SJim Jagielskitest_name is the pytest item name including its parameter ids, e.g. test_formula_result[DCOUNT.zero.crit];
25*2cb6d6f1SJim Jagielskia '*' matches any characters. kind is xfail (the item is expected to fail; it is reported XPASS when it starts to pass, and
26*2cb6d6f1SJim Jagielskifails then under --strict-expect), flaky (it fails in some runs; never strict) or skip. The reason must say what is known, not guess."""
27*2cb6d6f1SJim Jagielskiimport re
28*2cb6d6f1SJim Jagielski
29*2cb6d6f1SJim Jagielskifrom aootest.paths import DATA
30*2cb6d6f1SJim Jagielski
31*2cb6d6f1SJim JagielskiEXPECT_DIR = DATA / "expect"
32*2cb6d6f1SJim JagielskiKINDS = ("xfail", "flaky", "skip")
33*2cb6d6f1SJim Jagielski
34*2cb6d6f1SJim Jagielski
35*2cb6d6f1SJim Jagielskiclass Row:
36*2cb6d6f1SJim Jagielski    def __init__(self, pattern, kind, reason, origin):
37*2cb6d6f1SJim Jagielski        self.pattern, self.kind, self.reason, self.origin = pattern, kind, reason, origin
38*2cb6d6f1SJim Jagielski        self.regex = re.compile("".join(".*" if c == "*" else re.escape(c) for c in pattern))
39*2cb6d6f1SJim Jagielski        self.used = 0
40*2cb6d6f1SJim Jagielski
41*2cb6d6f1SJim Jagielski
42*2cb6d6f1SJim Jagielskidef load(directory=EXPECT_DIR):
43*2cb6d6f1SJim Jagielski    rows = []
44*2cb6d6f1SJim Jagielski    for path in sorted(directory.glob("*.tsv")):
45*2cb6d6f1SJim Jagielski        for n, line in enumerate(open(path, encoding="utf-8"), 1):
46*2cb6d6f1SJim Jagielski            if not line.strip() or line.startswith("#"):
47*2cb6d6f1SJim Jagielski                continue
48*2cb6d6f1SJim Jagielski            parts = line.rstrip("\n").split("\t")
49*2cb6d6f1SJim Jagielski            if len(parts) != 3 or parts[1] not in KINDS or not parts[2].strip():
50*2cb6d6f1SJim Jagielski                raise ValueError("%s:%d: expected test_name<TAB>xfail|flaky|skip<TAB>reason" % (path.name, n))
51*2cb6d6f1SJim Jagielski            rows.append(Row(parts[0], parts[1], parts[2], "%s:%d" % (path.name, n)))
52*2cb6d6f1SJim Jagielski    return rows
53*2cb6d6f1SJim Jagielski
54*2cb6d6f1SJim Jagielski
55*2cb6d6f1SJim Jagielskidef match(rows, name):
56*2cb6d6f1SJim Jagielski    """The first row that matches the item name, or None."""
57*2cb6d6f1SJim Jagielski    for r in rows:
58*2cb6d6f1SJim Jagielski        if r.regex.fullmatch(name):
59*2cb6d6f1SJim Jagielski            return r
60*2cb6d6f1SJim Jagielski    return None
61