diff --git a/afids_utils/tests/test_afids.py b/afids_utils/tests/test_afids.py index aa539100..aef8d6bd 100644 --- a/afids_utils/tests/test_afids.py +++ b/afids_utils/tests/test_afids.py @@ -159,13 +159,9 @@ def test_repeated_incomplete_afid_set( class TestAfidsIO: - @given(label=af_st.valid_labels()) + @given(label=af_st.valid_labels(), ext=st.sampled_from(["fcsv", "json"])) @allow_function_scoped - def test_valid_load( - self, - valid_fcsv_file: PathLike[str], - label: int, - ): + def test_valid_load(self, valid_file: PathLike[str], label: int, ext: str): # Load valid file to check internal types afids_set = AfidSet.load(valid_file.with_suffix(f".{ext}")) @@ -183,7 +179,6 @@ def test_invalid_fpath(self): AfidSet.load("invalid/fpath.fcsv") @given(ext=af_st.short_ascii_text()) - @allow_function_scoped def test_invalid_ext(self, ext: str): assume(not ext == "fcsv" or not ext == "json") @@ -253,9 +248,7 @@ def test_invalid_desc( AfidSet.load(out_fcsv_file.name) @given(ext=st.sampled_from(["fcsv", "json"])) - @settings( - suppress_health_check=[HealthCheck.function_scoped_fixture], - ) + @allow_function_scoped def test_valid_save(self, valid_file: PathLike[str], ext: str): with tempfile.NamedTemporaryFile( mode="w", prefix="sub-test_desc-", suffix=f"_afids.{ext}" @@ -265,10 +258,15 @@ def test_valid_save(self, valid_file: PathLike[str], ext: str): assert Path(out_fcsv_file.name).exists() - @given(ext=af_st.short_ascii_text()) + @given( + ext=st.sampled_from(["fcsv", "json"]), + invalid_ext=af_st.short_ascii_text(), + ) @allow_function_scoped - def test_invalid_ext_save(self, valid_fcsv_file: PathLike[str], ext: str): - assume(not ext == "fcsv" or not ext == "json") + def test_invalid_ext_save( + self, valid_file: PathLike[str], ext: str, invalid_ext: str + ): + assume(not invalid_ext == "fcsv" or not invalid_ext == "json") with tempfile.NamedTemporaryFile( mode="w", prefix="sub-test_desc-", suffix=f"_afids.{invalid_ext}" @@ -277,9 +275,8 @@ def test_invalid_ext_save(self, valid_fcsv_file: PathLike[str], ext: str): with pytest.raises(ValueError, match="Unsupported file extension"): afid_set.save(out_file.name) - @given(afid_set=af_st.afid_sets()) - @allow_function_scoped - def test_save_invalid_coord_system(self, afid_set: AfidSet): + @given(afid_set=af_st.afid_sets(), ext=st.sampled_from(["fcsv", "json"])) + def test_save_invalid_coord_system(self, afid_set: AfidSet, ext: str): afid_set.coord_system = "invalid" with tempfile.NamedTemporaryFile( @@ -293,7 +290,6 @@ def test_save_invalid_coord_system(self, afid_set: AfidSet): @given( afid_set=af_st.afid_sets(), coord_sys=st.sampled_from(["RAS", "LPS"]) ) - @allow_function_scoped def test_update_coord_system(self, afid_set: AfidSet, coord_sys: str): afid_set.coord_system = coord_sys @@ -318,8 +314,8 @@ def test_update_coord_system(self, afid_set: AfidSet, coord_sys: str): class TestAfidsCore: @given(label=af_st.valid_labels()) @allow_function_scoped - def test_valid_get_afid(self, valid_fcsv_file: PathLike[str], label: int): - afid_set = AfidSet.load(valid_fcsv_file) + def test_valid_get_afid(self, valid_file: PathLike[str], label: int): + afid_set = AfidSet.load(valid_file) afid_pos = afid_set.get_afid(label) # Check array type @@ -327,10 +323,8 @@ def test_valid_get_afid(self, valid_fcsv_file: PathLike[str], label: int): @given(label=st.integers(min_value=-100, max_value=100)) @allow_function_scoped - def test_invalid_get_afid( - self, valid_fcsv_file: PathLike[str], label: int - ): - afid_set = AfidSet.load(valid_fcsv_file) + def test_invalid_get_afid(self, valid_file: PathLike[str], label: int): + afid_set = AfidSet.load(valid_file) assume(not 1 <= label <= len(afid_set.afids)) with pytest.raises(InvalidFiducialError, match=".*not valid"): diff --git a/afids_utils/tests/test_ext.py b/afids_utils/tests/test_ext.py index 66cf3a1b..5a15f895 100644 --- a/afids_utils/tests/test_ext.py +++ b/afids_utils/tests/test_ext.py @@ -13,7 +13,8 @@ import afids_utils.tests.strategies as af_st from afids_utils.afids import AfidPosition, AfidSet from afids_utils.exceptions import InvalidFileError -from afids_utils.ext.fcsv import _get_afids, _get_metadata, save_fcsv +from afids_utils.ext import fcsv as af_fcsv +from afids_utils.ext import json as af_json from afids_utils.tests.helpers import allow_function_scoped @@ -153,7 +154,6 @@ def test_valid_get_afids(self, valid_fcsv_file: PathLike[str], label: int): class TestSaveFcsv: @given(afid_set=af_st.afid_sets()) - @allow_function_scoped def test_save_fcsv_invalid_template( self, afid_set: AfidSet, @@ -162,7 +162,6 @@ def test_save_fcsv_invalid_template( af_fcsv.save_fcsv(afid_set, "/invalid/template/path.fcsv") @given(afid_set=af_st.afid_sets(randomize_header=False)) - @allow_function_scoped def test_save_fcsv_valid_template(self, afid_set: AfidSet): with tempfile.NamedTemporaryFile( mode="w", prefix="sub-test_desc-", suffix="_afids.fcsv" @@ -178,9 +177,7 @@ def test_save_fcsv_valid_template(self, afid_set: AfidSet): class TestLoadJson: @given(coord=st.sampled_from(["RAS", "LPS", "0", "1"])) - @settings( - suppress_health_check=[HealthCheck.function_scoped_fixture], - ) + @allow_function_scoped def test_json_get_valid_metadata( self, valid_json_file: PathLike[str], coord: str ): @@ -213,9 +210,7 @@ def test_json_get_valid_metadata( assert parsed_coord == "LPS" @given(coord_num=st.integers(min_value=2)) - @settings( - suppress_health_check=[HealthCheck.function_scoped_fixture], - ) + @allow_function_scoped def test_json_invalid_num_coord( self, valid_json_file: PathLike[str], coord_num: int ): @@ -246,9 +241,7 @@ def test_json_invalid_num_coord( ), ) ) - @settings( - suppress_health_check=[HealthCheck.function_scoped_fixture], - ) + @allow_function_scoped def test_json_invalid_str_coord( self, valid_json_file: PathLike[str], coord_str: str ): @@ -274,9 +267,7 @@ def test_json_invalid_str_coord( af_json._get_metadata(temp_afids_json["markups"][0]) @given(label=st.integers(min_value=0, max_value=31)) - @settings( - suppress_health_check=[HealthCheck.function_scoped_fixture], - ) + @allow_function_scoped def test_json_valid_get_afids( self, valid_json_file: PathLike[str], label: int ): @@ -291,10 +282,7 @@ def test_json_valid_get_afids( class TestSaveJson: - @given(afid_set=afid_sets()) - @settings( - suppress_health_check=[HealthCheck.function_scoped_fixture], - ) + @given(afid_set=af_st.afid_sets()) def test_save_json_invalid_template( self, afid_set: AfidSet, @@ -302,10 +290,7 @@ def test_save_json_invalid_template( with pytest.raises(FileNotFoundError): af_json.save_json(afid_set, "/invalid/template/path.json") - @given(afid_set=afid_sets(randomize_header=False)) - @settings( - suppress_health_check=[HealthCheck.function_scoped_fixture], - ) + @given(afid_set=af_st.afid_sets(randomize_header=False)) def test_save_json_valid_template(self, afid_set: AfidSet): with tempfile.NamedTemporaryFile( mode="w", prefix="sub-test_desc-", suffix="_afids.json"