diff --git a/pyproject.toml b/pyproject.toml index 8cd15c35..fe20d964 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -106,5 +106,6 @@ exclude_lines = [ [tool.ruff] extend-exclude = ["examples"] -[tool.ruff.lint.isort] -known-first-party = ["qusi", "ramjet"] \ No newline at end of file +[tool.ruff.lint] +ignore = ["RET504"] +isort.known-first-party = ["qusi", "ramjet"] \ No newline at end of file diff --git a/tests/photometric_database/test_tess_ffi_light_curve.py b/tests/photometric_database/test_tess_ffi_light_curve.py index 72468178..319c349b 100644 --- a/tests/photometric_database/test_tess_ffi_light_curve.py +++ b/tests/photometric_database/test_tess_ffi_light_curve.py @@ -11,7 +11,7 @@ class TestTessFfiDataInterface: @pytest.fixture def ffi_pickle_contents(self) -> tuple[int, float, float, float, int, int, np.ndarray, np.ndarray, np.ndarray, - np.ndarray, np.ndarray, np.ndarray]: + np.ndarray, np.ndarray, np.ndarray]: """ Creates a mock content of one of Brian Powell's FFI data files. @@ -119,7 +119,8 @@ def test_can_get_floor_magnitude_from_ffi_style_file_path(self): magnitude1 = light_curve.get_floor_magnitude_from_file_path( 'data/ffi_microlensing_database/light_curves/tesslcs_sector_1/tesslcs_tmag_14_15/tesslc_1234567.pkl') assert magnitude1 == 14 - with pytest.raises(ValueError): + with pytest.raises(ValueError, + match='tesslc_12345678.pkl does not match a known pattern to extract magnitude from.'): light_curve.get_floor_magnitude_from_file_path('tesslc_12345678.pkl') def test_can_get_floor_magnitude_from_104_ffi_style_file_path(self): @@ -130,19 +131,21 @@ def test_can_get_floor_magnitude_from_104_ffi_style_file_path(self): magnitude1 = light_curve.get_floor_magnitude_from_file_path( 'data/ffi_microlensing_database/light_curves/tesslcs_sector_1_104/tesslcs_tmag_14_15/tesslc_1234567.pkl') assert magnitude1 == 14 - with pytest.raises(ValueError): + with pytest.raises(ValueError, + match='tesslc_12345678.pkl does not match a known pattern to extract magnitude from.'): light_curve.get_floor_magnitude_from_file_path('tesslc_12345678.pkl') def test_all_ffi_column_names_have_matches_in_the_pickle_indexes(self): - index_names = list(map(lambda index: index.name, TessFfiPickleIndex)) + index_names = [index.name for index in TessFfiPickleIndex] for column_name in TessFfiColumnName: assert column_name.name in index_names @patch.object(module.pickle, 'load') - @patch.object(Path, 'open') - def test_from_path_factory_sets_the_tic_id_and_sector_of_the_light_curve(self, mock_open, mock_pickle_load, + def test_from_path_factory_sets_the_tic_id_and_sector_of_the_light_curve(self, mock_pickle_load, ffi_pickle_contents): - mock_pickle_load.return_value = ffi_pickle_contents - light_curve = TessFfiLightCurve.from_path(Path('tesslcs_sector_1_104/tesslcs_tmag_14_15/tesslc_1234567.pkl')) - assert light_curve.tic_id == 1234567 - assert light_curve.sector == 1 + with patch.object(Path, 'open'): + mock_pickle_load.return_value = ffi_pickle_contents + light_curve = TessFfiLightCurve.from_path( + Path('tesslcs_sector_1_104/tesslcs_tmag_14_15/tesslc_1234567.pkl')) + assert light_curve.tic_id == 1234567 + assert light_curve.sector == 1 diff --git a/tests/photometric_database/test_tess_light_curve.py b/tests/photometric_database/test_tess_light_curve.py index a2237f36..d0339390 100644 --- a/tests/photometric_database/test_tess_light_curve.py +++ b/tests/photometric_database/test_tess_light_curve.py @@ -11,18 +11,18 @@ def test_setting_tic_rows_from_mast_for_list(self): light_curve0.tic_id = 266980320 light_curve1 = TessLightCurve() light_curve1.tic_id = 231663901 - assert light_curve0._tic_row is None - assert light_curve1._tic_row is None + assert light_curve0._tic_row is None # noqa SLF001 + assert light_curve1._tic_row is None # noqa SLF001 TessLightCurve.load_tic_rows_from_mast_for_list([light_curve0, light_curve1]) - assert light_curve0._tic_row is not None - assert light_curve1._tic_row is not None - assert float(light_curve0._tic_row['Tmag']) == pytest.approx(9.179, rel=1e-3) + assert light_curve0._tic_row is not None # noqa SLF001 + assert light_curve1._tic_row is not None # noqa SLF001 + assert float(light_curve0._tic_row['Tmag']) == pytest.approx(9.179, rel=1e-3) # noqa SLF001 @pytest.mark.slow @pytest.mark.external def test_setting_tic_rows_from_mast_for_list_notes_missing_row_for_tic_ids_not_in_tic(self): light_curve0 = TessLightCurve() light_curve0.tic_id = 99999999999999999 - assert light_curve0._tic_row is None + assert light_curve0._tic_row is None # noqa SLF001 TessLightCurve.load_tic_rows_from_mast_for_list([light_curve0]) - assert light_curve0._tic_row is MissingTicRow + assert light_curve0._tic_row is MissingTicRow # noqa SLF001 diff --git a/tests/photometric_database/test_tess_target.py b/tests/photometric_database/test_tess_target.py index 306a18d2..313d728c 100644 --- a/tests/photometric_database/test_tess_target.py +++ b/tests/photometric_database/test_tess_target.py @@ -31,7 +31,7 @@ def test_retrieving_radius_from_gaia(self): assert gaia_radius == pytest.approx(4.2563343) - @pytest.mark.parametrize('transit_depth, target_radius, target_contamination_ratio, expected_body_radius', + @pytest.mark.parametrize(('transit_depth', 'target_radius', 'target_contamination_ratio', 'expected_body_radius'), [(0.01011, 1.0, 0.0, 0.1005484), (0.02, 1.0, 0.1, 0.1483239), (0.01, 2.0, 0.5, 0.2449489)]) @@ -45,7 +45,7 @@ def test_can_estimate_radius_of_transiting_body(self, transit_depth, target_radi assert body_radius == pytest.approx(expected_body_radius) - @pytest.mark.parametrize('contamination_ratio, allow_unknown_contamination_ratio', + @pytest.mark.parametrize(('contamination_ratio', 'allow_unknown_contamination_ratio'), [(np.nan, False), (None, False)]) def test_not_allowing_estimate_radius_of_transiting_body_with_unknown_contamination( @@ -56,11 +56,11 @@ def test_not_allowing_estimate_radius_of_transiting_body_with_unknown_contaminat target.radius = target_radius target.contamination_ratio = contamination_ratio - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=r'Contamination ratio (None|nan) cannot be used to calculate the radius.'): _ = target.calculate_transiting_body_radius( transit_depth=transit_depth, allow_unknown_contamination_ratio=allow_unknown_contamination_ratio) - @pytest.mark.parametrize('contamination_ratio, allow_unknown_contamination_ratio', + @pytest.mark.parametrize(('contamination_ratio', 'allow_unknown_contamination_ratio'), [(np.nan, True), (None, True)]) def test_allowing_estimate_radius_of_transiting_body_with_unknown_contamination( diff --git a/tests/photometric_database/test_tess_two_minute_cadence_light_curve.py b/tests/photometric_database/test_tess_two_minute_cadence_light_curve.py index d015144f..7dbcb749 100644 --- a/tests/photometric_database/test_tess_two_minute_cadence_light_curve.py +++ b/tests/photometric_database/test_tess_two_minute_cadence_light_curve.py @@ -43,7 +43,8 @@ def test_from_path_factory_light_curve_uses_correct_default_times_and_fluxes(sel with patch.object(module.fits, 'open') as mock_open: mock_open.return_value.__enter__.return_value = fake_hdu_list light_curve = TessMissionLightCurve.from_path(Path('TIC 169480782 sector 5.fits')) - assert np.array_equal(light_curve.times, fake_hdu_list[1].data[TessMissionLightCurveFitsIndex.TIME__BTJD.value]) + assert np.array_equal(light_curve.times, + fake_hdu_list[1].data[TessMissionLightCurveFitsIndex.TIME__BTJD.value]) assert np.array_equal(light_curve.fluxes, fake_hdu_list[1].data[TessMissionLightCurveFitsIndex.PDCSAP_FLUX.value]) @@ -58,7 +59,8 @@ def test_can_get_tic_id_and_sector_from_human_readable_file_name(self): assert sector1 == 5 def test_get_tic_id_and_sector_raises_error_with_unknown_pattern(self): - with pytest.raises(ValueError): + with pytest.raises(ValueError, + match='a b c d e f g does not match a known pattern to extract TIC ID and sector from.'): TessMissionLightCurve.get_tic_id_and_sector_from_file_path(Path('a b c d e f g')) def test_can_get_tic_id_and_sector_from_tess_obs_id_style_file_name(self):