Esempio n. 1
0
def test_gifft_codegen():
    """
    A regression test. Very fragile.
    It generates C++ for GIFFT for metrics_test.yaml and compares it
    byte-for-byte with expected output C++ files.
    To generate new expected output files, set `UPDATE_EXPECT=1` when running the test suite:

    UPDATE_EXPECT=1 mach test toolkit/components/glean/pytest
    """

    options = {"allow_reserved": False}
    here_path = Path(path.dirname(__file__))
    input_files = [here_path / "metrics_test.yaml"]

    all_objs, options = run_glean_parser.parse_with_options(
        input_files, options)

    for probe_type in ("Event", "Histogram", "Scalar"):
        output_fd = io.StringIO()
        cpp_fd = io.StringIO()
        run_glean_parser.output_gifft_map(output_fd, probe_type, all_objs,
                                          cpp_fd)

        expect(here_path / f"gifft_output_{probe_type}", output_fd.getvalue())

        if probe_type == "Event":
            expect(here_path / "gifft_output_EventExtra", cpp_fd.getvalue())
Esempio n. 2
0
def test_all_metric_types():
    """Honestly, this is a pretty bad test.
    It generates C++ for a given test metrics.yaml and compares it byte-for-byte
    with an expected output C++ file.
    Expect it to be fragile.
    To generate new expected output files, set `UPDATE_EXPECT=1` when running the test suite:

    UPDATE_EXPECT=1 mach test toolkit/components/glean/pytest
    """

    options = {"allow_reserved": False}
    input_files = [
        Path(path.join(path.dirname(__file__), "metrics_test.yaml"))
    ]

    all_objs, options = run_glean_parser.parse_with_options(
        input_files, options)

    output_fd = io.StringIO()
    cpp.output_cpp(all_objs, output_fd, options)

    expect(
        path.join(path.dirname(__file__), "metrics_test_output_cpp"),
        output_fd.getvalue(),
    )
Esempio n. 3
0
def test_expires_version():
    """This test relies on the intermediary object format output by glean_parser.
    Expect it to be fragile on glean_parser updates that change that format.
    """

    # The test file has 41, 42, 100. Use 42.0a1 here to ensure "expires == version" means expired.
    options = run_glean_parser.get_parser_options("42.0a1")
    input_files = [
        Path(
            path.join(path.dirname(__file__),
                      "metrics_expires_versions_test.yaml"))
    ]

    all_objs, options = run_glean_parser.parse_with_options(
        input_files, options)

    assert all_objs["test"]["expired1"].disabled is True
    assert all_objs["test"]["expired2"].disabled is True
    assert all_objs["test"]["unexpired"].disabled is False
Esempio n. 4
0
def test_fake_pings():
    """Another similarly-bad test.
    It generates Rust for pings_test.yaml, comparing it byte-for-byte
    with an expected output Rust file.
    Expect it to be fragile.
    To generate new expected output files, set `UPDATE_EXPECT=1` when running the test suite:

    UPDATE_EXPECT=1 mach test toolkit/components/glean/pytest
    """

    options = {"allow_reserved": False}
    input_files = [Path(path.join(path.dirname(__file__), "pings_test.yaml"))]

    all_objs, options = run_glean_parser.parse_with_options(
        input_files, options)

    output_fd = io.StringIO()
    rust.output_rust(all_objs, output_fd, options)

    expect(path.join(path.dirname(__file__), "pings_test_output"),
           output_fd.getvalue())