Skip to content

Commit

Permalink
fix: PackageNameError type name fix [APE-1597] (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Dec 9, 2023
1 parent f1ae4f7 commit dd22626
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
5 changes: 3 additions & 2 deletions ethpm_types/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def validate_package_name(name: str) -> str:
),
BeforeValidator(validate_package_name),
]
PackageName.__name__ = "PackageName"


class PackageMeta(BaseModel):
Expand Down Expand Up @@ -97,7 +98,7 @@ class PackageManifest(BaseModel):
manifest: str = "ethpm/3"
"""The specification version that the project conforms to."""

name: Optional[PackageName] = None # type: ignore [valid-type]
name: Optional[PackageName] = None # type: ignore[valid-type]
"""A human-readable name for the package."""

version: Optional[str] = None
Expand Down Expand Up @@ -145,7 +146,7 @@ class PackageManifest(BaseModel):
must be unique across all other contract instances for the given chain.
"""

dependencies: Optional[Dict[PackageName, AnyUrl]] = Field( # type: ignore [valid-type]
dependencies: Optional[Dict[PackageName, AnyUrl]] = Field( # type: ignore[valid-type]
None, alias="buildDependencies"
)
"""
Expand Down
20 changes: 19 additions & 1 deletion tests/test_package_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@
from pydantic import ValidationError

from ethpm_types import ContractType
from ethpm_types.manifest import ALPHABET, NUMBERS, PackageManifest, PackageMeta
from ethpm_types.manifest import (
ALPHABET,
NUMBERS,
PackageManifest,
PackageMeta,
PackageName,
PackageNameError,
)
from ethpm_types.source import Compiler, Content, Source

ETHPM_SPEC_REPO = github.Github(os.environ.get("GITHUB_ACCESS_TOKEN", None)).get_repo(
Expand Down Expand Up @@ -161,6 +168,17 @@ def test_unpack_sources():
assert baz_expected.read_text() == str(baz_txt)


def test_package_name_name():
assert PackageName.__name__ == "PackageName"


def test_package_name_error_str():
error = PackageNameError(name="!!!", message="Oh no!")
assert str(error) == "Oh no!"
assert error.type == "PackageNameError"
assert error.context == {"name": "!!!"}


def test_package_name_using_all_valid_characters():
"""
Tests against a bug where we were unable to create a
Expand Down

0 comments on commit dd22626

Please sign in to comment.