Skip to content

Commit

Permalink
rm unnecessary @allow_function_scoped calls
Browse files Browse the repository at this point in the history
  • Loading branch information
kaitj committed Sep 15, 2023
1 parent 827c6d8 commit f514956
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 46 deletions.
40 changes: 17 additions & 23 deletions afids_utils/tests/test_afids.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"))

Expand All @@ -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")

Expand Down Expand Up @@ -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}"
Expand All @@ -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}"
Expand All @@ -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(
Expand All @@ -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

Expand All @@ -318,19 +314,17 @@ 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
assert isinstance(afid_pos, AfidPosition)

@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"):
Expand Down
31 changes: 8 additions & 23 deletions afids_utils/tests/test_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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,
Expand All @@ -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"
Expand All @@ -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
):
Expand Down Expand Up @@ -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
):
Expand Down Expand Up @@ -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
):
Expand All @@ -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
):
Expand All @@ -291,21 +282,15 @@ 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,
):
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"
Expand Down

0 comments on commit f514956

Please sign in to comment.