Skip to content

Commit

Permalink
Test suite type hint metadata fixturization x 6.
Browse files Browse the repository at this point in the history
This commit is the next in a commit chain fundamentally refactoring our
test suite to leverage space- and time-efficient `pytest` session-scoped
fixtures rather than space- and time-inefficient ad-hoc machinery
previously defined by the `beartype_test.a00_unit.data.hint.pep`
subpackage, which @leycec requires to preserve personal sanity while
maintaining this lumbering juggernaut but nobody else particularly cares
about. It's best *not* to ask what this is about. Just know that our
test suite is demonstrably improving into something maintainable that
will no longer destroy @leycec's precious sanity points.
(*Still wistfully willful, ist es?*)
  • Loading branch information
leycec committed Nov 3, 2023
1 parent 2c0a7a8 commit fcb5d67
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 47 deletions.
5 changes: 3 additions & 2 deletions beartype_test/a00_unit/data/hint/pep/data_pep.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ def _init() -> None:
# Defer fixture-specific imports.
from beartype_test.a00_unit.data.hint.pep.proposal._data_pep544 import (
hints_pep_meta_pep544)
from beartype_test.a00_unit.data.hint.pep.proposal._data_pep585 import (
hints_pep_meta_pep585)
from beartype_test.a00_unit.data.hint.pep.proposal._data_pep586 import (
hints_pep_meta_pep586)
from beartype_test.a00_unit.data.hint.pep.proposal._data_pep589 import (
Expand All @@ -183,6 +185,7 @@ def _init() -> None:
# Tuple of all fixtures defining "HINTS_PEP_META" subiterables.
HINTS_PEP_META_FIXTURES = (
hints_pep_meta_pep544,
hints_pep_meta_pep585,
hints_pep_meta_pep586,
hints_pep_meta_pep589,
hints_pep_meta_pep593,
Expand All @@ -207,7 +210,6 @@ def _init() -> None:
from beartype_test.a00_unit.data.hint.pep.proposal import (
data_pep484,
_data_pep544,
_data_pep585,
_data_pep593,
_data_pep604,
)
Expand All @@ -221,7 +223,6 @@ def _init() -> None:
_data_hintmodnumpy,
data_pep484,
_data_pep544,
_data_pep585,
_data_pep593,
_data_pep604,
)
Expand Down
85 changes: 40 additions & 45 deletions beartype_test/a00_unit/data/hint/pep/proposal/_data_pep585.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,42 @@
Project-wide :pep:`585`-compliant **type hint test data.**
'''

# ....................{ IMPORTS }....................
from beartype._util.py.utilpyversion import (
IS_PYTHON_AT_MOST_3_11,
IS_PYTHON_AT_LEAST_3_9,
)

# ....................{ ADDERS }....................
def add_data(data_module: 'ModuleType') -> None:
# ....................{ FIXTURES }....................
def hints_pep_meta_pep585() -> 'List[HintPepMetadata]':
'''
Add :pep:`585`-compliant type hint test data to various global containers
declared by the passed module.
Parameters
----------
data_module : ModuleType
Module to be added to.
Session-scoped fixture returning a list of :pep:`585`-compliant **type hint
metadata** (i.e.,
:class:`beartype_test.a00_unit.data.hint.util.data_hintmetacls.HintPepMetadata`
instances describing test-specific :pep:`585`-compliant sample type hints
with metadata generically leveraged by various PEP-agnostic unit tests).
'''

# ..................{ IMPORTS }..................
# Defer fixture-specific imports.
from beartype._util.py.utilpyversion import (
IS_PYTHON_AT_MOST_3_11,
IS_PYTHON_AT_LEAST_3_9,
)

# ..................{ LOCALS }..................
# List of all PEP-specific type hint metadata to be returned.
hints_pep_meta = []

# If the active Python interpreter targets less than Python < 3.9, this
# interpreter fails to support PEP 585. In this case, reduce to a noop.
# interpreter fails to support PEP 585. In this case, return the empty list.
if not IS_PYTHON_AT_LEAST_3_9:
return
return hints_pep_meta
# Else, the active Python interpreter targets at least Python >= 3.9 and
# thus supports PEP 585.

# ..................{ IMPORTS }..................
# Defer Python >= 3.9-specific imports.
import re
from beartype.typing import (
Any,
TypeVar,
Union,
)
from beartype._cave._cavefast import IntType
from beartype._data.hint.pep.sign.datapepsigns import (
HintSignByteString,
Expand Down Expand Up @@ -77,23 +85,11 @@ def add_data(data_module: 'ModuleType') -> None:
Match,
Pattern,
)
from typing import (
Any,
TypeVar,
Union,
)

# ..................{ TYPEVARS }..................
# ..................{ LOCALS }..................
# User-defined generic "typing" type variables.
S = TypeVar('S')
'''
User-defined generic :mod:`typing` type variable.
'''


T = TypeVar('T')
'''
User-defined generic :mod:`typing` type variable.
'''

# ..................{ GENERICS ~ single }..................
# Note we intentionally do *NOT* declare unsubscripted PEP 585-compliant
Expand Down Expand Up @@ -232,22 +228,17 @@ def __len__(self) -> bool:
return len(self._iterable)

# ..................{ PRIVATE ~ forwardref }..................
# Fully-qualified classname of an arbitrary class guaranteed to be
# importable.
_TEST_PEP585_FORWARDREF_CLASSNAME = (
'beartype_test.a00_unit.data.data_type.Subclass')
'''
Fully-qualified classname of an arbitrary class guaranteed to be
importable.
'''


# Arbitrary class referred to by :data:`_PEP484_FORWARDREF_CLASSNAME`.
_TEST_PEP585_FORWARDREF_TYPE = Subclass
'''
Arbitrary class referred to by :data:`_PEP484_FORWARDREF_CLASSNAME`.
'''

# ..................{ MAPPINGS }..................
# Add PEP 585-specific test type hints to this dictionary global.
data_module.HINTS_PEP_META.extend((
# ..................{ LISTS }..................
# Add PEP-specific type hint metadata to this list.
hints_pep_meta.extend((
# ................{ CALLABLE }................
# Callable accepting no parameters and returning a string.
HintPepMetadata(
Expand Down Expand Up @@ -1148,9 +1139,9 @@ def __len__(self) -> bool:
# under Python >= 3.12.
from collections.abc import ByteString

# ..................{ MAPPINGS }..................
# Add PEP 585-specific test type hints to this dictionary global.
data_module.HINTS_PEP_META.extend((
# ..................{ LISTS }..................
# Add PEP-specific type hint metadata to this list.
hints_pep_meta.extend((
# ................{ BYTESTRING }................
# Byte string of integer constants satisfying the builtin "int"
# type. However, note that:
Expand Down Expand Up @@ -1203,3 +1194,7 @@ def __len__(self) -> bool:
),
),
))

# ..................{ RETURN }..................
# Return this list of all PEP-specific type hint metadata.
return hints_pep_meta

0 comments on commit fcb5d67

Please sign in to comment.