Skip to content

Commit

Permalink
Update tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
plypaul committed Feb 7, 2025
1 parent 0547b66 commit a07b502
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -534,5 +534,8 @@ def _as_one_line(description: Optional[str], str_converted_dict: Dict[str, str],
return None

items = tuple(f"{key_str}={value_str}" for key_str, value_str in str_converted_dict.items())
if len(items) == 0:
return description

value_in_parenthesis = ", ".join(items)
return f"{description} ({value_in_parenthesis})"
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import logging

from metricflow_semantics.formatting.formatting_helpers import mf_dedent
from metricflow_semantics.mf_logging.lazy_formattable import LazyFormat
from typing_extensions import override

Expand All @@ -19,12 +18,8 @@ def test_log_kwargs() -> None:
recorded_logger.debug(
LazyFormat("Found candidates.", matches=[1, 2, 3], parameters={"field_0": "value_0", "field_1": "value_1"})
)
assert handler.get_last_message() == mf_dedent(
"""
Found candidates.
matches: [1, 2, 3]
parameters: {'field_0': 'value_0', 'field_1': 'value_1'}
"""
assert handler.get_last_message() == (
"Found candidates. (matches=[1, 2, 3], parameters={'field_0': 'value_0', 'field_1': 'value_1'})"
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@


def test_pformat_many() -> None: # noqa: D103
result = mf_pformat_dict("Example description:", obj_dict={"object_0": (1, 2, 3), "object_1": {4: 5}})
result = mf_pformat_dict(
"Example description:", obj_dict={"object_0": (1, 2, 3), "object_1": {4: 5}}, max_line_length=30
)

assert (
textwrap.dedent(
Expand All @@ -25,7 +27,9 @@ def test_pformat_many() -> None: # noqa: D103


def test_pformat_many_with_raw_strings() -> None: # noqa: D103
result = mf_pformat_dict("Example description:", obj_dict={"object_0": "foo\nbar"}, preserve_raw_strings=True)
result = mf_pformat_dict(
"Example description:", obj_dict={"object_0": "foo\nbar"}, preserve_raw_strings=True, max_line_length=30
)

assert (
textwrap.dedent(
Expand All @@ -42,7 +46,7 @@ def test_pformat_many_with_raw_strings() -> None: # noqa: D103

def test_pformat_dict_with_empty_message() -> None:
"""Test `mf_pformat_dict` without a description."""
result = mf_pformat_dict(obj_dict={"object_0": (1, 2, 3), "object_1": {4: 5}})
result = mf_pformat_dict(obj_dict={"object_0": (1, 2, 3), "object_1": {4: 5}}, max_line_length=30)

assert (
mf_dedent(
Expand All @@ -57,7 +61,9 @@ def test_pformat_dict_with_empty_message() -> None:

def test_pformat_dict_with_pad_sections_with_newline() -> None:
"""Test `mf_pformat_dict` with new lines between sections."""
result = mf_pformat_dict(obj_dict={"object_0": (1, 2, 3), "object_1": {4: 5}}, pad_items_with_newlines=True)
result = mf_pformat_dict(
obj_dict={"object_0": (1, 2, 3), "object_1": {4: 5}}, pad_items_with_newlines=True, max_line_length=30
)

assert (
mf_dedent(
Expand All @@ -72,7 +78,7 @@ def test_pformat_dict_with_pad_sections_with_newline() -> None:


def test_pformat_many_with_strings() -> None: # noqa: D103
result = mf_pformat_dict("Example description:", obj_dict={"object_0": "foo\nbar"})
result = mf_pformat_dict("Example description:", obj_dict={"object_0": "foo\nbar"}, max_line_length=30)
assert (
textwrap.dedent(
"""\
Expand All @@ -96,4 +102,4 @@ def test_minimal_length() -> None:

def test_one_line() -> None:
"""Test formatting as a one-line string if possible."""
assert mf_pformat_dict("Example output", {"a": 1, "b": 2}) == "Example output (a=1, b=2)"
assert mf_pformat_dict("Example output", {"a": 1, "b": 2}, max_line_length=80) == "Example output (a=1, b=2)"

0 comments on commit a07b502

Please sign in to comment.