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())
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(), )
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())