xref: /trunk/test/aoo-test/tests/harness/test_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"""aootest.expect: reading expectation rows and matching test names."""
21*2cb6d6f1SJim Jagielskiimport pytest
22*2cb6d6f1SJim Jagielski
23*2cb6d6f1SJim Jagielskifrom aootest import expect
24*2cb6d6f1SJim Jagielski
25*2cb6d6f1SJim Jagielski
26*2cb6d6f1SJim Jagielskidef rows(tmp_path, text):
27*2cb6d6f1SJim Jagielski    (tmp_path / "x.tsv").write_text(text, encoding="utf-8")
28*2cb6d6f1SJim Jagielski    return expect.load(tmp_path)
29*2cb6d6f1SJim Jagielski
30*2cb6d6f1SJim Jagielski
31*2cb6d6f1SJim Jagielskidef test_rows_of_each_kind_are_read(tmp_path):
32*2cb6d6f1SJim Jagielski    r = rows(tmp_path, "# comment\n\na[1]\txfail\twhy\nb\tflaky\tsometimes\nc\tskip\tnot here\n")
33*2cb6d6f1SJim Jagielski    assert [(x.pattern, x.kind, x.reason) for x in r] == [("a[1]", "xfail", "why"), ("b", "flaky", "sometimes"), ("c", "skip", "not here")]
34*2cb6d6f1SJim Jagielski
35*2cb6d6f1SJim Jagielski
36*2cb6d6f1SJim Jagielski@pytest.mark.parametrize("line", ["a\tmaybe\twhy\n", "a\txfail\t\n", "a\txfail\n", "a\txfail\twhy\textra\n"])
37*2cb6d6f1SJim Jagielskidef test_malformed_rows_are_refused(tmp_path, line):
38*2cb6d6f1SJim Jagielski    with pytest.raises(ValueError):
39*2cb6d6f1SJim Jagielski        rows(tmp_path, line)
40*2cb6d6f1SJim Jagielski
41*2cb6d6f1SJim Jagielski
42*2cb6d6f1SJim Jagielskidef test_star_matches_any_characters_and_brackets_are_literal(tmp_path):
43*2cb6d6f1SJim Jagielski    r = rows(tmp_path, "test_x[*|name.ods]\txfail\twhy\n")
44*2cb6d6f1SJim Jagielski    assert expect.match(r, "test_x[v12-v13|name.ods]") is r[0]
45*2cb6d6f1SJim Jagielski    assert expect.match(r, "test_x[v12-v13|nameXods]") is None
46*2cb6d6f1SJim Jagielski    assert expect.match(r, "test_y[v12-v13|name.ods]") is None
47