Skip to content

Commit

Permalink
Test suite type hint metadata fixturization x 4.
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. (*Baka mitai! Back my tie!*)
  • Loading branch information
leycec committed Nov 1, 2023
1 parent 533df02 commit 8de732f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 35 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 @@ -160,6 +160,8 @@ def _init() -> None:
'''

# Defer fixture-specific imports.
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 (
hints_pep_meta_pep589)
from beartype_test.a00_unit.data.hint.pep.proposal._data_pep593 import (
Expand All @@ -178,6 +180,7 @@ def _init() -> None:

# Tuple of all fixtures defining "HINTS_PEP_META" subiterables.
HINTS_PEP_META_FIXTURES = (
hints_pep_meta_pep586,
hints_pep_meta_pep589,
hints_pep_meta_pep593,
hints_pep_meta_pep604,
Expand All @@ -202,7 +205,6 @@ def _init() -> None:
data_pep484,
_data_pep544,
_data_pep585,
_data_pep586,
_data_pep593,
_data_pep604,
)
Expand All @@ -217,7 +219,6 @@ def _init() -> None:
data_pep484,
_data_pep544,
_data_pep585,
_data_pep586,
_data_pep593,
_data_pep604,
)
Expand Down
55 changes: 22 additions & 33 deletions beartype_test/a00_unit/data/hint/pep/proposal/_data_pep586.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,24 @@
Project-wide :pep:`586`-compliant **type hint test data.**
'''

# ....................{ IMPORTS }....................

# ....................{ ADDERS }....................
def add_data(data_module: 'ModuleType') -> None:
# ....................{ FIXTURES }....................
def hints_pep_meta_pep586() -> 'List[HintPepMetadata]':
'''
Add :pep:`586`-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:`586`-compliant **type hint
metadata** (i.e.,
:class:`beartype_test.a00_unit.data.hint.util.data_hintmetacls.HintPepMetadata`
instances describing test-specific :pep:`586`-compliant sample type hints
with metadata generically leveraged by various PEP-agnostic unit tests).
'''

# ..................{ IMPORTS }..................
# Defer early-time fixture-specific imports.
from beartype._util.module.lib.utiltyping import (
is_typing_attr,
iter_typing_attrs,
)

# If *NO* currently importable "typing" module declares this type hint
# factory, the active Python interpreter fails to support this PEP. In this
# case, return the empty tuple.
if not is_typing_attr('Literal'):
return
# Else, this interpreter supports this PEP.

# ..................{ IMPORTS ~ moar }..................
# Defer all remaining fixture-specific imports.

# ..................{ IMPORTS }..................
# Defer data-dependent imports.
# Defer fixture-specific imports.
from beartype.typing import List
from beartype._data.hint.pep.sign.datapepsigns import (
HintSignList,
HintSignLiteral,
)
from beartype._util.module.lib.utiltyping import get_typing_attrs
from beartype_test.a00_unit.data.data_type import (
MasterlessDecreeVenomlessWhich)
from beartype_test.a00_unit.data.hint.util.data_hintmetacls import (
Expand All @@ -53,11 +33,16 @@ def add_data(data_module: 'ModuleType') -> None:
HintPithUnsatisfiedMetadata,
)

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

# ..................{ FACTORIES }..................
# For each "Literal" type hint factory importable from a typing module...
for Literal in iter_typing_attrs('Literal'):
# For each PEP-specific type hint factory importable from each currently
# importable "typing" module...
for Literal in get_typing_attrs('Literal'):
# Add PEP 586-specific test type hints to this tuple global.
data_module.HINTS_PEP_META.extend((
hints_pep_meta.extend((
# ..............{ LITERALS }..............
# Literal "None" singleton. Look, this is ridiculous. What you do?
HintPepMetadata(
Expand Down Expand Up @@ -92,7 +77,7 @@ def add_data(data_module: 'ModuleType') -> None:
HintPithSatisfiedMetadata(True),
# Boolean constant defined by different syntax but
# semantically equal to the same boolean.
HintPithSatisfiedMetadata(data_module is data_module),
HintPithSatisfiedMetadata(__name__ is __name__),
# Boolean constant *NOT* equal to the same boolean.
HintPithUnsatisfiedMetadata(
pith=False,
Expand Down Expand Up @@ -369,3 +354,7 @@ def add_data(data_module: 'ModuleType') -> None:
),
),
))

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

0 comments on commit 8de732f

Please sign in to comment.