Skip to content

Commit

Permalink
feat: metric to trim flanking whitespace
Browse files Browse the repository at this point in the history
Fixes #216
  • Loading branch information
nh13 authored Jan 28, 2025
1 parent f1f89e9 commit 6315fbd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions fgpyo/util/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,11 @@ def format_value(cls, value: Any) -> str: # noqa: C901
+ "}"
)
elif isinstance(value, float):
return str(round(value, 5))
return str(round(value, 5)).strip()
elif value is None:
return ""
else:
return str(value)
return str(value).strip()

@classmethod
def to_list(cls, value: str) -> List[Any]:
Expand Down
5 changes: 5 additions & 0 deletions tests/fgpyo/util/test_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,11 @@ def test_metric_values(data_and_classes: DataBuilder) -> None:
assert list(data_and_classes.Person(name="name", age=42).values()) == ["name", 42]


@pytest.mark.parametrize("data_and_classes", (attr_data_and_classes, dataclasses_data_and_classes))
def test_metric_whitespace_padded_strip(data_and_classes: DataBuilder) -> None:
assert list(data_and_classes.Person(name=" John Doe \t ", age=42).values()) == ["John Doe", 42]


@pytest.mark.parametrize("data_and_classes", (attr_data_and_classes, dataclasses_data_and_classes))
def test_metric_items(data_and_classes: DataBuilder) -> None:
"""`metric.items()` should return a list of (key, value) tuples."""
Expand Down

0 comments on commit 6315fbd

Please sign in to comment.