Skip to content

Commit

Permalink
Fix metric parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
donn committed Nov 23, 2023
1 parent 0f521c9 commit 2334ed0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion openlane/common/metrics/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def parse_metric_modifiers(metric_name: str) -> Tuple[str, Mapping[str, str]]:
mn_mut = metric_name.split("__")
modifiers = {}
while ":" in mn_mut[-1]:
key, value = mn_mut.pop().split(":")
key, value = mn_mut.pop().split(":", maxsplit=1)
modifiers[key] = value
return "__".join(mn_mut), modifiers

Expand Down
12 changes: 7 additions & 5 deletions test/common/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ def test_is_string():
def test_parse_metric_modifiers():
from openlane.common import parse_metric_modifiers

assert parse_metric_modifiers("category__name__optional_name_modifier__etc",) == (
assert parse_metric_modifiers(
"category__name__optional_name_modifier__etc",
) == (
"category__name__optional_name_modifier__etc",
{},
), "Improperly parsed metric without modifiers"

assert parse_metric_modifiers(
"category__name__optional_name_modifier__etc__mod1:one:mod2:two"
"category__name__optional_name_modifier__etc__mod1:one__mod2:two"
) == (
"category__name__optional_name_modifier__etc",
{"mod1": "one", "mod2": "two"},
Expand All @@ -77,9 +79,9 @@ def test_parse_metric_modifiers():
assert parse_metric_modifiers(
"category__name__optional_name_modifier__etc:etc:etc",
) == (
"category__name__optional_name_modifier__etc:etc:etc",
{},
), "Improperly parsed metric with improper modifier syntax"
"category__name__optional_name_modifier",
{"etc": "etc:etc"},
), "Improperly parsed metric with modifier containing a colon"


@pytest.mark.parametrize(
Expand Down

0 comments on commit 2334ed0

Please sign in to comment.