Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changes/1959.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Minor code quality improvements reported by GitHub Code QL.
3 changes: 0 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ def get_python_version_from_pyproject():
project = "simtools"
copyright = "2024-2025, gammasim-tools, simtools developers" # noqa A001
author = get_authors_from_citation_file()
rst_epilog = f"""
.. |author| replace:: {author}
"""

python_min_requires, python_requires = get_python_version_from_pyproject()
rst_epilog = f"""
Expand Down
2 changes: 1 addition & 1 deletion src/simtools/configuration/commandline_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def initialize_simulation_model_arguments(self, model_options):
type=self.telescope,
)
if "layout" in model_options or "layout_file" in model_options:
_job_group = self._add_model_option_layout(
self._add_model_option_layout(
job_group=_job_group,
model_options=model_options,
# layout info is always required for layout related tasks with the exception
Expand Down
4 changes: 0 additions & 4 deletions src/simtools/data_model/metadata_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@

"""

import logging

import simtools.data_model.schema
import simtools.utils.general as gen

_logger = logging.getLogger(__name__)


def get_default_metadata_dict(
schema_file=None, observatory="CTA", schema_version="latest", lower_case=True
Expand Down
6 changes: 4 additions & 2 deletions src/simtools/io/ascii_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,11 @@ def write_data_to_file(data, output_file, sort_keys=False, numpy_types=False):
"""
output_file = Path(output_file)
if output_file.suffix.lower() == ".json":
return _write_to_json(data, output_file, sort_keys, numpy_types)
_write_to_json(data, output_file, sort_keys, numpy_types)
return
if output_file.suffix.lower() in [".yml", ".yaml"]:
return _write_to_yaml(data, output_file, sort_keys)
_write_to_yaml(data, output_file, sort_keys)
return

raise ValueError(
f"Unsupported file type {output_file.suffix}. Only .json, .yml, and .yaml are supported."
Expand Down
1 change: 0 additions & 1 deletion src/simtools/ray_tracing/psf_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,6 @@ def scan(dr, rad_min, rad_max):
if radius is not found (found_radius is False)
"""
r0, r1 = rad_min, rad_min + dr
s0, s1 = 0, 0
found_radius = False
while not found_radius:
s0, s1 = self._sum_photons_in_radius(r0), self._sum_photons_in_radius(r1)
Expand Down
3 changes: 0 additions & 3 deletions src/simtools/visualization/plot_corsika_histograms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Visualize Cherenkov photon distributions from CORSIKA."""

import logging
from pathlib import Path

import matplotlib.pyplot as plt
Expand All @@ -10,8 +9,6 @@

from simtools.visualization.visualize import save_figures_to_single_document

_logger = logging.getLogger(__name__)


def _plot_2d(hist_list, labels=None):
"""
Expand Down
3 changes: 2 additions & 1 deletion tests/unit_tests/corsika/test_corsika_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,8 @@ def test_write_seeds_use_test_seeds(corsika_config_mock_array_model):
expected_calls = [_call.args[0] for _call in mock_file.write.call_args_list]
expected_seeds = [534, 220, 1104, 382]
for _call in expected_calls:
assert _call == (f"SEED {expected_seeds.pop(0)} 0 0\n")
seed = expected_seeds.pop(0)
assert _call == f"SEED {seed} 0 0\n"


def test_get_corsika_telescope_list(corsika_config_mock_array_model):
Expand Down
5 changes: 2 additions & 3 deletions tests/unit_tests/data_model/test_metadata_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import simtools.data_model.metadata_collector as metadata_collector
from simtools.constants import METADATA_JSON_SCHEMA, SCHEMA_PATH
from simtools.data_model import schema
from simtools.data_model.metadata_collector import MetadataCollector
from simtools.utils import names

logger = logging.getLogger()
Expand Down Expand Up @@ -296,7 +295,7 @@ def test_fill_context_sim_list(args_dict_site):

# one entry with Nones only
_test_def = [{"site": None, "class": None, "type": None, "subtype": None, "id:": None}]
_test_def = _collector._fill_context_sim_list(_test_def, _new_element)
_collector._fill_context_sim_list(_test_def, _new_element)
assert _test_none == [_new_element]


Expand Down Expand Up @@ -661,6 +660,6 @@ def mock_getuser():


def test_read_input_metadata_from_yml_or_json_no_file():
collector = MetadataCollector(args_dict={})
collector = metadata_collector.MetadataCollector(args_dict={})
with pytest.raises(FileNotFoundError, match=r"Failed reading metadata from missing_file\.yml"):
collector._read_input_metadata_from_yml_or_json("missing_file.yml")
3 changes: 2 additions & 1 deletion tests/unit_tests/data_model/test_model_data_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def num_gains_schema(num_gains_schema_file):
def test_write(tmp_test_directory, args_dict_site):
# both none (no exception expected)
w_1 = writer.ModelDataWriter(output_path=tmp_test_directory)
assert w_1.write(metadata=None, product_data=None) is None
result = w_1.write(metadata=None, product_data=None)
assert result is None

# metadata not none; no data and metadata file
_metadata = metadata_collector.MetadataCollector(args_dict=args_dict_site)
Expand Down
3 changes: 1 addition & 2 deletions tests/unit_tests/io/test_ascii_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import simtools.io.ascii_handler as ascii_handler
from simtools.constants import MODEL_PARAMETER_METASCHEMA, MODEL_PARAMETER_SCHEMA_PATH
from simtools.io.ascii_handler import read_file_encoded_in_utf_or_latin

FAILED_TO_READ_FILE_ERROR = r"^Failed to read file"
url_simtools = "https://raw.githubusercontent.com/gammasim/simtools/main/"
Expand Down Expand Up @@ -194,7 +193,7 @@ def test_read_file_encoded_in_utf_or_latin_unicode_decode_error():
with pytest.raises(
UnicodeDecodeError, match=r"Unable to decode file.*using UTF-8 or Latin-1"
):
read_file_encoded_in_utf_or_latin(mock_file_name)
ascii_handler.read_file_encoded_in_utf_or_latin(mock_file_name)


def test_json_numpy_encoder():
Expand Down
5 changes: 2 additions & 3 deletions tests/unit_tests/job_execution/test_job_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import pytest

import simtools.job_execution.job_manager as jm
from simtools.job_execution.job_manager import JobExecutionError

LOG_EXCERPT = "log excerpt"
OS_SYSTEM = "os.system"
Expand Down Expand Up @@ -117,7 +116,7 @@ def test_submit_local_real_failure(
mock_subprocess = mocker.patch(subprocess_run)
mock_subprocess.side_effect = subprocess.CalledProcessError(1, str(script_file))

with pytest.raises(JobExecutionError, match="See excerpt from log file above"):
with pytest.raises(jm.JobExecutionError, match="See excerpt from log file above"):
job_submitter_real.submit(script_file, output_log, logfile_log)

job_submitter_real._logger.info.assert_any_call(job_messages["script_message"])
Expand Down Expand Up @@ -164,7 +163,7 @@ def test_submit_local_success(
mock_subprocess_run = mocker.patch(subprocess_run)
mock_subprocess_run.return_value.returncode = 42
with patch(builtins_open, mock_open(read_data="")):
with pytest.raises(JobExecutionError, match="Job submission failed with return code 42"):
with pytest.raises(jm.JobExecutionError, match="Job submission failed with return code 42"):
job_submitter_real.submit(script_file, output_log, logfile_log)


Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/layout/test_array_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def test_export_telescope_list_table(

layout_utm._telescope_list = []
try:
table_utm = layout_utm.export_telescope_list_table(crs_name="utm")
layout_utm.export_telescope_list_table(crs_name="utm")
except IndexError:
pytest.fail("IndexError raised")

Expand Down
Loading