Skip to content

Commit

Permalink
Test suite type hint metadata fixturization x 2.
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.
(*Lazered embers on an emblazoned blazer!*)
  • Loading branch information
leycec committed Oct 28, 2023
1 parent 69e2fe4 commit 3a234ac
Show file tree
Hide file tree
Showing 13 changed files with 517 additions and 656 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

# ....................{ TESTS }....................
def test_get_hint_pep484585_callable_params_and_return() -> None:
def test_get_hint_pep484585_callable_params_and_return(hints_pep_meta) -> None:
'''
Test both the ``get_hint_pep484585_callable_params`` and
``get_hint_pep484585_callable_return`` getters declared by the
Expand All @@ -27,6 +27,12 @@ def test_get_hint_pep484585_callable_params_and_return() -> None:
Since these getters are inextricably interrelated, this unit test exercises
both within the same test to satisfy Don't Repeat Yourself (DRY).
Parameters
----------
hints_pep_meta : List[beartype_test.a00_unit.data.hint.util.data_hintmetacls.HintPepMetadata]
List of PEP-compliant type hint metadata describing sample PEP-compliant
type hints exercising edge cases in the :mod:`beartype` codebase.
'''

# ..................{ IMPORTS }..................
Expand All @@ -43,15 +49,14 @@ def test_get_hint_pep484585_callable_params_and_return() -> None:
IS_PYTHON_AT_LEAST_3_9,
)
from beartype_test.a00_unit.data.hint.data_hint import NOT_HINTS_PEP
from beartype_test.a00_unit.data.hint.pep.data_pep import HINTS_PEP_META
from pytest import raises

# ..................{ GENERIC }..................
# General-purpose logic generically exercising these getters against all
# globally defined type hints.

# Assert these getters...
for hint_pep_meta in HINTS_PEP_META:
for hint_pep_meta in hints_pep_meta:
# Return zero or more arguments for PEP-compliant callable type hints.
if hint_pep_meta.pep_sign is HintSignCallable:
hint_callable_params = get_hint_pep484585_callable_params(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,29 @@
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

# ....................{ TESTS ~ testers }....................
def test_is_hint_pep484585_generic() -> None:
def test_is_hint_pep484585_generic(hints_pep_meta) -> None:
'''
Test the
:func:`beartype._util.hint.pep.proposal.pep484585.utilpep484585generic.is_hint_pep484585_generic`
tester.
Parameters
----------
hints_pep_meta : List[beartype_test.a00_unit.data.hint.util.data_hintmetacls.HintPepMetadata]
List of PEP-compliant type hint metadata describing sample PEP-compliant
type hints exercising edge cases in the :mod:`beartype` codebase.
'''

# Defer test-specific imports.
from beartype._data.hint.pep.sign.datapepsigns import HintSignGeneric
from beartype._util.hint.pep.proposal.pep484585.utilpep484585generic import (
is_hint_pep484585_generic)
from beartype_test.a00_unit.data.hint.data_hint import NOT_HINTS_PEP
from beartype_test.a00_unit.data.hint.pep.data_pep import (
HINTS_PEP_META)

# Assert this tester:
# * Accepts generic PEP 484-compliant generics.
# * Rejects concrete PEP-compliant type hints.
for hint_pep_meta in HINTS_PEP_META:
for hint_pep_meta in hints_pep_meta:
assert is_hint_pep484585_generic(hint_pep_meta.hint) is (
hint_pep_meta.pep_sign is HintSignGeneric)

Expand All @@ -45,26 +49,30 @@ def test_is_hint_pep484585_generic() -> None:
assert is_hint_pep484585_generic(not_hint_pep) is False

# ....................{ TESTS ~ getters }....................
def test_get_hint_pep484585_generic_type_or_none() -> None:
def test_get_hint_pep484585_generic_type_or_none(hints_pep_meta) -> None:
'''
Test the
:func:`beartype._util.hint.pep.proposal.pep484585.utilpep484585generic.get_hint_pep484585_generic_type_or_none`
getter.
Parameters
----------
hints_pep_meta : List[beartype_test.a00_unit.data.hint.util.data_hintmetacls.HintPepMetadata]
List of PEP-compliant type hint metadata describing sample PEP-compliant
type hints exercising edge cases in the :mod:`beartype` codebase.
'''

# Defer test-specific imports.
from beartype._data.hint.pep.sign.datapepsigns import HintSignGeneric
from beartype._util.hint.pep.proposal.pep484585.utilpep484585generic import (
get_hint_pep484585_generic_type_or_none)
from beartype_test.a00_unit.data.hint.pep.data_pep import (
HINTS_PEP_META)

# Assert this getter returns the expected type origin for all
# PEP-compliant type hint generics. While we could support non-generics as
# well, there's little benefit and significant costs to doing so. Instead,
# we assert this getter only returns the expected type origin for a small
# subset of type hints.
for hint_pep_meta in HINTS_PEP_META:
for hint_pep_meta in hints_pep_meta:
if hint_pep_meta.pep_sign is HintSignGeneric:
assert get_hint_pep484585_generic_type_or_none(
hint_pep_meta.hint) is hint_pep_meta.generic_type
Expand All @@ -84,11 +92,17 @@ def test_get_hint_pep484585_generic_type_or_none() -> None:
# assert get_hint_pep484585_generic_type_or_none(not_hint_pep) is None


def test_get_hint_pep484585_generic_bases_unerased() -> None:
def test_get_hint_pep484585_generic_bases_unerased(hints_pep_meta) -> None:
'''
Test the
:func:`beartype._util.hint.pep.proposal.pep484585.utilpep484585generic.get_hint_pep484585_generic_bases_unerased`
getter.
Parameters
----------
hints_pep_meta : List[beartype_test.a00_unit.data.hint.util.data_hintmetacls.HintPepMetadata]
List of PEP-compliant type hint metadata describing sample PEP-compliant
type hints exercising edge cases in the :mod:`beartype` codebase.
'''

# Defer test-specific imports.
Expand All @@ -98,11 +112,10 @@ def test_get_hint_pep484585_generic_bases_unerased() -> None:
get_hint_pep484585_generic_bases_unerased)
from beartype._util.hint.pep.utilpeptest import is_hint_pep_type_typing
from beartype_test.a00_unit.data.hint.data_hint import NOT_HINTS_PEP
from beartype_test.a00_unit.data.hint.pep.data_pep import HINTS_PEP_META
from pytest import raises

# Assert this getter...
for hint_pep_meta in HINTS_PEP_META:
for hint_pep_meta in hints_pep_meta:
# Returns one or more unerased pseudo-superclasses for PEP-compliant
# generics.
if hint_pep_meta.pep_sign is HintSignGeneric:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
# --------------------( LICENSE )--------------------
# --------------------( LICENSE )--------------------
# Copyright (c) 2014-2023 Beartype authors.
# See "LICENSE" for further details.

Expand All @@ -10,68 +10,80 @@
:mod:`beartype._util.hint.pep.proposal.utilpep585` submodule.
'''

# ....................{ IMPORTS }....................
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# ....................{ IMPORTS }....................
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# WARNING: To raise human-readable test errors, avoid importing from
# package-specific submodules at module scope.
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

# ....................{ TESTS ~ kind : builtin }....................
def test_is_hint_pep585_builtin() -> None:
# ....................{ TESTS ~ kind : builtin }....................
def test_is_hint_pep585_builtin(hints_pep_meta) -> None:
'''
Test the
:func:`beartype._util.hint.pep.proposal.utilpep585.is_hint_pep585_builtin`
function.
Parameters
----------
hints_pep_meta : List[beartype_test.a00_unit.data.hint.util.data_hintmetacls.HintPepMetadata]
List of type hint metadata describing sample type hints exercising edge
cases in the :mod:`beartype` codebase.
'''

# Defer test-specific imports.
from beartype._util.hint.pep.proposal.utilpep585 import (
is_hint_pep585_builtin)
from beartype_test.a00_unit.data.hint.pep.data_pep import (
HINTS_PEP_META)

# Assert this tester accepts only PEP 585-compliant type hints.
for hint_pep_meta in HINTS_PEP_META:
for hint_pep_meta in hints_pep_meta:
assert is_hint_pep585_builtin(hint_pep_meta.hint) is (
hint_pep_meta.is_pep585_builtin)

# ....................{ TESTS ~ kind : generic }....................
def test_is_hint_pep585_generic() -> None:
def test_is_hint_pep585_generic(hints_pep_meta) -> None:
'''
Test the
:func:`beartype._util.hint.pep.proposal.utilpep585.is_hint_pep585_generic`
function.
Parameters
----------
hints_pep_meta : List[beartype_test.a00_unit.data.hint.util.data_hintmetacls.HintPepMetadata]
List of type hint metadata describing sample type hints exercising edge
cases in the :mod:`beartype` codebase.
'''

# Defer test-specific imports.
from beartype._util.hint.pep.proposal.utilpep585 import (
is_hint_pep585_generic)
from beartype_test.a00_unit.data.hint.pep.data_pep import (
HINTS_PEP_META)

# Assert this tester accepts only PEP 585-compliant generics.
for hint_pep_meta in HINTS_PEP_META:
for hint_pep_meta in hints_pep_meta:
assert is_hint_pep585_generic(hint_pep_meta.hint) is (
hint_pep_meta.is_pep585_generic)


def test_get_hint_pep585_generic_typevars() -> None:
def test_get_hint_pep585_generic_typevars(hints_pep_meta) -> None:
'''
Test the
:func:`beartype._util.hint.pep.proposal.utilpep585.get_hint_pep585_generic_typevars`
function.
Parameters
----------
hints_pep_meta : List[beartype_test.a00_unit.data.hint.util.data_hintmetacls.HintPepMetadata]
List of type hint metadata describing sample type hints exercising edge
cases in the :mod:`beartype` codebase.
'''

# Defer test-specific imports.
from beartype.roar import BeartypeDecorHintPep585Exception
from beartype._util.hint.pep.proposal.utilpep585 import (
get_hint_pep585_generic_typevars)
from beartype_test.a00_unit.data.hint.pep.data_pep import (
HINTS_PEP_META)
from pytest import raises

# Assert this getter...
for hint_pep_meta in HINTS_PEP_META:
for hint_pep_meta in hints_pep_meta:
# If this hint is a PEP 585-compliant generic...
if hint_pep_meta.is_pep585_generic:
# Tuple of all tupe variables returned by this function.
Expand Down

0 comments on commit 3a234ac

Please sign in to comment.