tor-browser

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

test_transforms_job.py (2977B)


      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 """
      6 Tests for the 'job' transform subsystem.
      7 """
      8 
      9 import os
     10 from copy import deepcopy
     11 
     12 import pytest
     13 from mozunit import main
     14 from taskgraph.config import load_graph_config
     15 from taskgraph.transforms.base import TransformConfig
     16 
     17 from gecko_taskgraph import GECKO
     18 from gecko_taskgraph.test.conftest import FakeParameters
     19 from gecko_taskgraph.transforms import job
     20 from gecko_taskgraph.transforms.job import run_task  # noqa: F401
     21 from gecko_taskgraph.transforms.task import group_name_variant
     22 
     23 here = os.path.abspath(os.path.dirname(__file__))
     24 
     25 
     26 TASK_DEFAULTS = {
     27    "description": "fake description",
     28    "label": "fake-task-label",
     29    "run": {
     30        "using": "run-task",
     31    },
     32 }
     33 
     34 
     35 @pytest.fixture(scope="module")
     36 def config():
     37    graph_config = load_graph_config(os.path.join(GECKO, "taskcluster"))
     38    params = FakeParameters({
     39        "base_repository": "http://hg.example.com",
     40        "head_repository": "http://hg.example.com",
     41        "head_rev": "abcdef",
     42        "level": 1,
     43        "project": "example",
     44    })
     45    return TransformConfig(
     46        "job_test", here, {}, params, {}, graph_config, write_artifacts=False
     47    )
     48 
     49 
     50 @pytest.fixture()
     51 def transform(monkeypatch, config):
     52    """Run the job transforms on the specified task but return the inputs to
     53    `configure_taskdesc_for_run` without executing it.
     54 
     55    This gives test functions an easy way to generate the inputs required for
     56    many of the `run_using` subsystems.
     57    """
     58 
     59    def inner(task_input):
     60        task = deepcopy(TASK_DEFAULTS)
     61        task.update(task_input)
     62        frozen_args = []
     63 
     64        def _configure_taskdesc_for_run(*args):
     65            frozen_args.extend(args)
     66 
     67        monkeypatch.setattr(
     68            job, "configure_taskdesc_for_run", _configure_taskdesc_for_run
     69        )
     70 
     71        for _ in job.transforms(config, [task]):
     72            # This forces the generator to be evaluated
     73            pass
     74 
     75        return frozen_args
     76 
     77    return inner
     78 
     79 
     80 @pytest.mark.parametrize(
     81    "groupSymbol,description",
     82    [
     83        pytest.param("M", "Mochitests", id="no_variants"),
     84        pytest.param(
     85            "M-spi",
     86            "Mochitests with socket process enabled",
     87            id="spi variant",
     88        ),
     89        pytest.param(
     90            "M-spi-nofis",
     91            "Mochitests without fission enabled with socket process enabled",
     92            id="spi and nofis variants",
     93        ),
     94        pytest.param("M-fake", "", id="invalid group name"),
     95    ],
     96    ids=lambda t: t["worker-type"],
     97 )
     98 def test_group_name(config, groupSymbol, description):
     99    group_names = config.graph_config["treeherder"]["group-names"]
    100    generated_description = group_name_variant(group_names, groupSymbol)
    101    assert description == generated_description
    102 
    103 
    104 if __name__ == "__main__":
    105    main()