Skip to content

Commit

Permalink
fix: hyphenated ecosystem names (#1689)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Oct 5, 2023
1 parent 536d591 commit 74fdcbb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/ape/managers/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ def __getattr__(self, attr_name: str) -> EcosystemAPI:
"""

if attr_name not in self.ecosystems:
# First try alternating the hyphen and underscores.
attr_name_fix = (
attr_name.replace("_", "-") if "_" in attr_name else attr_name.replace("-", "_")
)
if attr_name_fix in self.ecosystems:
return self.ecosystems[attr_name_fix]

raise ApeAttributeError(f"{self.__class__.__name__} has no attribute '{attr_name}'.")

return self.ecosystems[attr_name]
Expand Down
6 changes: 6 additions & 0 deletions tests/functional/test_network_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,9 @@ def test_parse_network_choice_multiple_contexts(get_provider_with_unused_chain_i
# Second context should already know about connected providers
assert len(first_context.connected_providers) == expected_next_count
assert len(second_context.connected_providers) == expected_next_count


def test_getattr_ecosystem_with_hyphenated_name(networks, ethereum):
networks.ecosystems["hyphen-in-name"] = networks.ecosystems["ethereum"]
assert networks.hyphen_in_name # Make sure does not raise AttributeError
del networks.ecosystems["hyphen-in-name"]

0 comments on commit 74fdcbb

Please sign in to comment.