Skip to content

Efficiency improvements for unit tests #2223

Draft
GernotMaier wants to merge 3 commits into
mainfrom
some-unit-tests-are-slow
Draft

Efficiency improvements for unit tests #2223
GernotMaier wants to merge 3 commits into
mainfrom
some-unit-tests-are-slow

Conversation

@GernotMaier
Copy link
Copy Markdown
Contributor

@GernotMaier GernotMaier commented May 29, 2026

Improvements mostly in unit tests of the plotting routines - a lot can be achieved to set DPI to 10...

Was:

3.40s call     tests/unit_tests/visualization/test_plot_event_level_production_comparison.py::test_plot_writes_per_type_comparison_figures
2.43s call     tests/unit_tests/visualization/test_plot_event_level_production_comparison.py::test_plot_writes_event_level_comparison_figures
2.36s call     tests/unit_tests/visualization/test_plot_incident_angles.py::test_debug_plots_generate_expected_files
2.23s call     tests/unit_tests/visualization/test_plot_incident_angles.py::test_plot_incident_angles_debug_plots_true
2.17s call     tests/unit_tests/visualization/test_plot_event_level_production_comparison.py::test_plot_invokes_triggered_fraction_branch_when_enabled
1.56s call     tests/unit_tests/layout/test_array_layout.py::test_build_layout
1.41s call     tests/unit_tests/visualization/test_plot_production_grid.py::test_plot_sky_projection_creates_outputs
1.06s call     tests/unit_tests/data_model/test_metadata_collector.py::test_get_top_level_metadata
0.94s call     tests/unit_tests/visualization/test_plot_production_grid.py::test_normalize_altaz_point_creates_radec_coordinates
0.90s call     tests/unit_tests/utils/test_general.py::test_url_exists
0.89s call     tests/unit_tests/visualization/test_plot_incident_angles.py::test_plot_incident_angles_with_model_version
0.81s call     tests/unit_tests/data_model/test_schema.py::test_validate_dict_using_schema_remote
0.62s call     tests/unit_tests/visualization/test_plot_production_grid.py::test_plot_sky_projection_infers_radec_grid_tracks
0.56s call     tests/unit_tests/visualization/test_plot_incident_angles.py::test_plot_incident_angles_custom_bin_widths
0.51s call     tests/unit_tests/production_configuration/test_observation_grid.py::test_convert_altaz_to_radec_returns_icrs_coordinates
0.50s call     tests/unit_tests/simtel/test_simtel_output_validator.py::test_assert_model_parameters[metadata0-parameters0-mock_value0-0-None-None]
0.49s call     tests/unit_tests/visualization/test_plot_incident_angles.py::test_plot_incident_angles_debug_plots_false
0.48s call     tests/unit_tests/production_configuration/test_observation_grid.py::test_generate_simulation_grid_keeps_horizontal_coordinates_for_radec_axes
0.47s call     tests/unit_tests/visualization/test_plot_incident_angles.py::test_plot_incident_angles_dual_mirror
0.46s call     tests/unit_tests/simtel/test_simtel_config_writer.py::test_get_parameters_for_sim_telarray_maps_flasher_photons_from_calibration_model

is now:

1.95s call     tests/unit_tests/layout/test_array_layout.py::test_build_layout
1.06s call     tests/unit_tests/visualization/test_plot_event_level_production_comparison.py::test_plot_writes_per_type_comparison_figures
0.81s call     tests/unit_tests/visualization/test_plot_production_grid.py::test_plot_sky_projection_creates_outputs
0.80s call     tests/unit_tests/visualization/test_plot_incident_angles.py::test_debug_plots_generate_expected_files
0.80s call     tests/unit_tests/visualization/test_plot_incident_angles.py::test_plot_incident_angles_debug_plots_true
0.71s call     tests/unit_tests/production_configuration/test_observation_grid.py::test_generate_simulation_grid_keeps_horizontal_coordinates_for_radec_axes
0.70s call     tests/unit_tests/visualization/test_plot_event_level_production_comparison.py::test_plot_writes_event_level_comparison_figures
0.62s call     tests/unit_tests/production_configuration/test_observation_grid.py::test_convert_altaz_to_radec_returns_icrs_coordinates
0.57s call     tests/unit_tests/simtel/test_simtel_output_validator.py::test_assert_model_parameters[metadata0-parameters0-mock_value0-0-None-None]
0.57s call     tests/unit_tests/model/test_model_repository.py::test_update_parameters_dict_new_function
0.57s call     tests/unit_tests/visualization/test_plot_event_level_production_comparison.py::test_plot_invokes_triggered_fraction_branch_when_enabled
0.56s call     tests/unit_tests/simtel/test_simtel_config_writer.py::test_get_parameters_for_sim_telarray_maps_flasher_photons_from_calibration_model
0.55s call     tests/unit_tests/data_model/test_data_reader.py::test_read_table_from_file_and_validate
0.54s call     tests/unit_tests/data_model/test_schema.py::test_get_model_parameter_schema_files
0.54s call     tests/unit_tests/model/test_model_parameter.py::test_overwrite_parameters_flat_dict_forwards_to_parameter_store
0.53s call     tests/unit_tests/camera/test_camera_efficiency.py::test_simulate
0.52s call     tests/unit_tests/reporting/test_docs_read_parameters.py::test_get_all_parameter_descriptions
0.38s call     tests/unit_tests/layout/test_array_layout_utils.py::test_write_array_elements_from_file_to_repository_utm
0.37s call     tests/unit_tests/data_model/test_metadata_collector.py::test_read_input_metadata_from_file
0.36s call     tests/unit_tests/layout/test_telescope_position.py::test_convert

GernotMaier and others added 3 commits May 29, 2026 16:36
- Mock HTTP requests globally (urlretrieve) to serve local repo files
- Cache pyproj Transformer construction with lru_cache (layout/telescope_position.py)
- Write stub PNG bytes instead of real matplotlib renders for file saves
- Patch Figure.tight_layout to no-op (eliminates text-extent rendering)
- Patch Figure.colorbar to MagicMock (eliminates quad-mesh rendering)
- Add session-scoped ERFA warm-up fixture to pre-initialise astropy
  coordinate transforms before any test measures them

Typical improvements on slow test hardware (original -> new):
  test_plot_writes_per_type_comparison_figures:  1.96s -> ~0.25s
  test_plot_incident_angles_debug_plots_true:    1.73s -> ~0.25s
  test_generate_simulation_grid (ERFA):          1.12s -> ~0.30s
  test_build_layout (pyproj):                    1.56s -> ~0.10s
  test_read_table_from_file_and_validate:        1.24s -> ~0.25s

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ctao-sonarqube
Copy link
Copy Markdown

Quality Gate failed Quality Gate failed

Failed conditions
2 New issues

See analysis details on SonarQube

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE SonarQube for IDE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant