-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support random choice from tmate relations (#208)
* feat: support random choice from tmate relations * chore: run src-docs * chore: type hint use default list * test: add failed test description * fix: json parsing
- Loading branch information
Showing
13 changed files
with
152 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
"""Factories for generating test data.""" | ||
|
||
# The factory definitions don't need public methods | ||
# pylint: disable=too-few-public-methods | ||
|
||
import random | ||
from typing import Generic, TypeVar | ||
|
||
import factory | ||
import factory.fuzzy | ||
from pydantic.networks import IPvAnyAddress | ||
|
||
from charm_state import SSHDebugInfo | ||
|
||
T = TypeVar("T") | ||
|
||
|
||
class BaseMetaFactory(Generic[T], factory.base.FactoryMetaClass): | ||
"""Used for type hints of factories.""" | ||
|
||
# No need for docstring because it is used for type hints | ||
def __call__(cls, *args, **kwargs) -> T: # noqa: N805 | ||
"""Used for type hints of factories.""" # noqa: DCO020 | ||
return super().__call__(*args, **kwargs) # noqa: DCO030 | ||
|
||
|
||
# The attributes of these classes are generators for the attributes of the meta class | ||
# mypy incorrectly believes the factories don't support metaclass | ||
class SSHDebugInfoFactory( | ||
factory.Factory, metaclass=BaseMetaFactory[SSHDebugInfo] # type: ignore | ||
): | ||
# Docstrings have been abbreviated for factories, checking for docstrings on model attributes | ||
# can be skipped. | ||
"""Generate PathInfos.""" # noqa: DCO060 | ||
|
||
class Meta: | ||
"""Configuration for factory.""" # noqa: DCO060 | ||
|
||
model = SSHDebugInfo | ||
abstract = False | ||
|
||
host: IPvAnyAddress = factory.Faker("ipv4") | ||
port: int = factory.LazyAttribute(lambda n: random.randrange(1024, 65536)) | ||
rsa_fingerprint: str = factory.fuzzy.FuzzyText(prefix="SHA256:") | ||
ed25519_fingerprint: str = factory.fuzzy.FuzzyText(prefix="SHA256:") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
factory-boy>=3,<4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.