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