-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate AfidSet for testing #24
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,15 +10,15 @@ | |
from hypothesis import HealthCheck, assume, given, settings | ||
from hypothesis import strategies as st | ||
|
||
from afids_utils.afids import AfidPosition | ||
from afids_utils.afids import AfidPosition, AfidSet | ||
from afids_utils.exceptions import InvalidFileError | ||
from afids_utils.ext.fcsv import ( | ||
FCSV_FIELDNAMES, | ||
_get_afids, | ||
_get_metadata, | ||
save_fcsv, | ||
) | ||
from afids_utils.tests.strategies import afid_coords | ||
from afids_utils.tests.strategies import afid_set | ||
|
||
|
||
@pytest.fixture | ||
|
@@ -164,32 +164,29 @@ def test_valid_get_afids(self, valid_fcsv_file: PathLike[str], label: int): | |
|
||
|
||
class TestSaveFcsv: | ||
@given(afids_coords=afid_coords()) | ||
@given(afids_set=afid_set()) | ||
kaitj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@settings( | ||
suppress_health_check=[HealthCheck.function_scoped_fixture], | ||
) | ||
def test_save_fcsv_invalid_template( | ||
self, | ||
afids_coords: list[AfidPosition], | ||
valid_fcsv_file: PathLike[str], | ||
afids_set: AfidSet, | ||
): | ||
with pytest.raises(FileNotFoundError): | ||
save_fcsv(afids_coords, "/invalid/template/path.fcsv") | ||
save_fcsv(afids_set.afids, "/invalid/template/path.fcsv") | ||
|
||
@given(afids_coords=afid_coords()) | ||
@given(afids_set=afid_set()) | ||
@settings( | ||
suppress_health_check=[HealthCheck.function_scoped_fixture], | ||
) | ||
def test_save_fcsv_valid_template( | ||
self, | ||
afids_coords: list[AfidPosition], | ||
valid_fcsv_file: PathLike[str], | ||
self, afids_set: list[AfidPosition], valid_fcsv_file: PathLike[str] | ||
): | ||
with tempfile.NamedTemporaryFile( | ||
mode="w", prefix="sub-test_desc-", suffix="_afids.fcsv" | ||
) as out_fcsv_file: | ||
# Create and check output file | ||
save_fcsv(afids_coords, out_fcsv_file.name) | ||
save_fcsv(afids_set.afids, out_fcsv_file.name) | ||
|
||
# Load files | ||
with open( | ||
|
@@ -211,17 +208,21 @@ def test_save_fcsv_valid_template( | |
# Check contents | ||
for idx, row in enumerate(output_fcsv): | ||
assert (row["x"], row["y"], row["z"]) == ( | ||
str(afids_coords[idx].x), | ||
str(afids_coords[idx].y), | ||
str(afids_coords[idx].z), | ||
str(afids_set.afids[idx].x), | ||
str(afids_set.afids[idx].y), | ||
str(afids_set.afids[idx].z), | ||
) | ||
|
||
@given(afids_coords=afid_coords(bad_range=True)) | ||
def test_invalid_num_afids(self, afids_coords: list[AfidPosition]) -> None: | ||
# Check to see if file can be loaded with afids-utils | ||
test_load = AfidSet.load(out_fcsv_file.name) | ||
assert isinstance(test_load, AfidSet) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we could even There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh yeah, this test can be simplified quite a bit with the new |
||
|
||
@given(afids_set=afid_set(bad_range=True)) | ||
def test_invalid_num_afids(self, afids_set: list[AfidPosition]) -> None: | ||
with tempfile.NamedTemporaryFile( | ||
mode="w", prefix="sub-test_desc-", suffix="_afids.fcsv" | ||
) as out_fcsv_file: | ||
with pytest.raises(TypeError) as err: | ||
save_fcsv(afids_coords, out_fcsv_file) | ||
save_fcsv(afids_set.afids, out_fcsv_file) | ||
|
||
assert "AFIDs, but received" in str(err.value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather not have a default value that's invalid here (even if you want to leave the invalid
desc
s in the test for now)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, I think alternatively I can load in the valid
descs
and any invalid ones set to "Unknown".There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable to me, or you can just leave it without a default until we implement the validation