Skip to content

Commit

Permalink
test: improve test err
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Dec 13, 2024
1 parent 7634a0b commit 62d56d9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
18 changes: 8 additions & 10 deletions src/ape/managers/_contractscache.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@
from ape.api.networks import ProxyInfoAPI
from ape.api.query import ContractCreation, ContractCreationQuery
from ape.contracts.base import ContractContainer, ContractInstance
from ape.exceptions import (
ContractNotFoundError,
ConversionError,
CustomError,
QueryEngineError,
ApeException,
)
from ape.exceptions import ApeException, ContractNotFoundError, ConversionError, CustomError
from ape.logging import logger
from ape.managers._deploymentscache import Deployment, DeploymentDiskCache
from ape.managers.base import BaseManager
Expand Down Expand Up @@ -695,9 +689,13 @@ def instance_at(
)

elif not isinstance(contract_type, ContractType):
raise TypeError(
f"Expected type '{ContractType.__name__}' for argument 'contract_type'."
)
prefix = f"Expected type '{ContractType.__name__}' for argument 'contract_type'"
try:
suffix = f"; Given '{type(contract_type).__name__}'."
except Exception:
suffix = "."

raise TypeError(f"{prefix}{suffix}")

if not txn_hash:
# Check for txn_hash in deployments.
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_contracts_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_instance_at_when_given_contract_type(chain, contract_instance):


def test_instance_at_when_given_name_as_contract_type(chain, contract_instance):
expected_match = "Expected type 'ContractType' for argument 'contract_type'."
expected_match = "Expected type 'ContractType' for argument 'contract_type'; Given 'str'."
with pytest.raises(TypeError, match=expected_match):
address = str(contract_instance.address)
bad_contract_type = contract_instance.contract_type.name
Expand Down

0 comments on commit 62d56d9

Please sign in to comment.