1# This Source Code Form is subject to the terms of the Mozilla Public 2# License, v. 2.0. If a copy of the MPL was not distributed with this 3# file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 5from __future__ import absolute_import, print_function 6 7import mozunit 8import pytest 9 10 11@pytest.fixture 12def parse(get_reftest, normalize): 13 output = pytest.importorskip("output") 14 15 reftest, options = get_reftest(tests=["dummy"]) 16 reftest._populate_logger(options) 17 reftest.outputHandler = output.OutputHandler( 18 reftest.log, options.utilityPath, options.symbolsPath 19 ) 20 21 def resolve(path): 22 path = normalize(path) 23 return "file://{}".format(path) 24 25 def inner(*manifests): 26 assert len(manifests) > 0 27 manifests = {m: (None, "id") for m in map(resolve, manifests)} 28 return reftest.getActiveTests(manifests, options) 29 30 return inner 31 32 33def test_parse_test_types(parse): 34 tests = parse("types.list") 35 assert tests[0]["type"] == "==" 36 assert tests[1]["type"] == "!=" 37 assert tests[2]["type"] == "load" 38 assert tests[3]["type"] == "script" 39 assert tests[4]["type"] == "print" 40 41 42def test_parse_failure_type_interactions(parse): 43 """Tests interactions between skip and fails.""" 44 tests = parse("failure-type-interactions.list") 45 for t in tests: 46 if "skip" in t["name"]: 47 assert t["skip"] 48 else: 49 assert not t["skip"] 50 51 # 0 => EXPECTED_PASS, 1 => EXPECTED_FAIL 52 if "fails" in t["name"]: 53 assert t["expected"] == 1 54 else: 55 assert t["expected"] == 0 56 57 58def test_parse_invalid_manifests(parse): 59 # XXX We should assert that the output contains the appropriate error 60 # message, but we seem to be hitting an issue in pytest that is preventing 61 # us from capturing the Gecko output with the capfd fixture. See: 62 # https://github.com/pytest-dev/pytest/issues/5997 63 with pytest.raises(SystemExit): 64 parse("invalid-defaults.list") 65 66 with pytest.raises(SystemExit): 67 parse("invalid-defaults-include.list") 68 69 with pytest.raises(SystemExit): 70 parse("invalid-include.list") 71 72 73if __name__ == "__main__": 74 mozunit.main() 75