tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_reftest_manifest_parser.py (2147B)


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