Skip to content

Commit

Permalink
Merge pull request #8 from ImageMarkup/isic-81-round-clinical-size
Browse files Browse the repository at this point in the history
Round and require positive clinical sizes
  • Loading branch information
danlamanna authored Jun 28, 2022
2 parents 2dbaa09 + 7322275 commit aab0ee0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
5 changes: 4 additions & 1 deletion isic_metadata/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ def validate(cls, value) -> float | None:
float_value, units = match.groups()
float_value = float(float_value)

if float_value <= 0:
raise ValueError(f'Invalid clinical size of {value}.')

# Convert to mm
if units == 'um':
float_value *= 1e-3
elif units == 'cm':
float_value *= 1e1

return float_value
return round(float_value, ndigits=1)


class Age(BaseStr):
Expand Down
23 changes: 9 additions & 14 deletions tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,12 @@ def test_age_special_case():
assert MetadataRow(age='85+').age == 85


# test that non numeric strings fail, this should capture negative values
# @given(age=st.text().filter(lambda s: not s.isnumeric() and s != ''))
# def test_age_fuzz(age):
# print(age)
# with pytest.raises(ValidationError) as excinfo:
# MetadataRow(age=age)


# assert 'foo' == excinfo.value
# except ValidationError as e:
# breakpoint()
# assert len(e.errors()) == 1
# assert e.errors()[0]['loc'][0] == 'age'
# print(e.errors())
@given(
clin_size=st.one_of(st.floats(min_value=0, exclude_min=True), st.integers(min_value=1)).map(
lambda x: f'{x} mm'
)
)
def test_clin_size_long_diam_mm_always_rounded(clin_size):
metadata = MetadataRow(clin_size_long_diam_mm=clin_size)
assert isinstance(metadata.clin_size_long_diam_mm, float)
assert metadata.clin_size_long_diam_mm == round(metadata.clin_size_long_diam_mm, ndigits=1)

0 comments on commit aab0ee0

Please sign in to comment.