tor-browser

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

test_main.py (1840B)


      1 # Any copyright is dedicated to the public domain.
      2 # http://creativecommons.org/publicdomain/zero/1.0/
      3 
      4 import pytest
      5 import taskgraph
      6 from mozunit import main as mozunit_main
      7 
      8 from gecko_taskgraph.main import main as taskgraph_main
      9 
     10 
     11 @pytest.fixture
     12 def run_main(maketgg, monkeypatch):
     13    def inner(args, **kwargs):
     14        kwargs.setdefault("target_tasks", ["_fake-t-0", "_fake-t-1"])
     15        tgg = maketgg(**kwargs)
     16 
     17        def fake_get_taskgraph_generator(*args):
     18            return tgg
     19 
     20        monkeypatch.setattr(
     21            taskgraph.main,
     22            "get_taskgraph_generator",
     23            fake_get_taskgraph_generator,
     24        )
     25        taskgraph_main(args)
     26        return tgg
     27 
     28    return inner
     29 
     30 
     31 @pytest.mark.parametrize(
     32    "attr,expected",
     33    (
     34        ("tasks", ["_fake-t-0", "_fake-t-1", "_fake-t-2"]),
     35        ("full", ["_fake-t-0", "_fake-t-1", "_fake-t-2"]),
     36        ("target", ["_fake-t-0", "_fake-t-1"]),
     37        ("target-graph", ["_fake-t-0", "_fake-t-1"]),
     38        ("optimized", ["_fake-t-0", "_fake-t-1"]),
     39        ("morphed", ["_fake-t-0", "_fake-t-1"]),
     40    ),
     41 )
     42 def test_show_taskgraph(run_main, capsys, attr, expected):
     43    run_main([attr])
     44    out, err = capsys.readouterr()
     45    assert out.strip() == "\n".join(expected)
     46    assert "Dumping result" in err
     47 
     48 
     49 def test_tasks_regex(run_main, capsys):
     50    run_main(["full", "--tasks=_.*-t-1"])
     51    out, _ = capsys.readouterr()
     52    assert out.strip() == "_fake-t-1"
     53 
     54 
     55 def test_output_file(run_main, tmpdir):
     56    output_file = tmpdir.join("out.txt")
     57    assert not output_file.check()
     58 
     59    run_main(["full", f"--output-file={output_file.strpath}"])
     60    assert output_file.check()
     61    assert output_file.read_text("utf-8").strip() == "\n".join([
     62        "_fake-t-0",
     63        "_fake-t-1",
     64        "_fake-t-2",
     65    ])
     66 
     67 
     68 if __name__ == "__main__":
     69    mozunit_main()