diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /taskcluster/gecko_taskgraph/test/test_main.py | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'taskcluster/gecko_taskgraph/test/test_main.py')
-rw-r--r-- | taskcluster/gecko_taskgraph/test/test_main.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/taskcluster/gecko_taskgraph/test/test_main.py b/taskcluster/gecko_taskgraph/test/test_main.py new file mode 100644 index 0000000000..bb1aa1caeb --- /dev/null +++ b/taskcluster/gecko_taskgraph/test/test_main.py @@ -0,0 +1,67 @@ +# Any copyright is dedicated to the public domain. +# http://creativecommons.org/publicdomain/zero/1.0/ + +import pytest +from mozunit import main as mozunit_main + +import gecko_taskgraph +from gecko_taskgraph.main import main as taskgraph_main + + +@pytest.fixture +def run_main(maketgg, monkeypatch): + def inner(args, **kwargs): + kwargs.setdefault("target_tasks", ["_fake-t-0", "_fake-t-1"]) + tgg = maketgg(**kwargs) + + def fake_get_taskgraph_generator(*args): + return tgg + + monkeypatch.setattr( + gecko_taskgraph.main, + "get_taskgraph_generator", + fake_get_taskgraph_generator, + ) + taskgraph_main(args) + return tgg + + return inner + + +@pytest.mark.parametrize( + "attr,expected", + ( + ("tasks", ["_fake-t-0", "_fake-t-1", "_fake-t-2"]), + ("full", ["_fake-t-0", "_fake-t-1", "_fake-t-2"]), + ("target", ["_fake-t-0", "_fake-t-1"]), + ("target-graph", ["_fake-t-0", "_fake-t-1"]), + ("optimized", ["_fake-t-0", "_fake-t-1"]), + ("morphed", ["_fake-t-0", "_fake-t-1"]), + ), +) +def test_show_taskgraph(run_main, capsys, attr, expected): + run_main([attr]) + out, err = capsys.readouterr() + assert out.strip() == "\n".join(expected) + assert "Dumping result" in err + + +def test_tasks_regex(run_main, capsys): + run_main(["full", "--tasks=_.*-t-1"]) + out, _ = capsys.readouterr() + assert out.strip() == "_fake-t-1" + + +def test_output_file(run_main, tmpdir): + output_file = tmpdir.join("out.txt") + assert not output_file.check() + + run_main(["full", f"--output-file={output_file.strpath}"]) + assert output_file.check() + assert output_file.read_text("utf-8").strip() == "\n".join( + ["_fake-t-0", "_fake-t-1", "_fake-t-2"] + ) + + +if __name__ == "__main__": + mozunit_main() |