Skip to content

Commit

Permalink
Test coverage marginally improved.
Browse files Browse the repository at this point in the history
This commit marginally improves test coverage by unit testing the
heretofore-untested `beartype._util.utilobject.get_object_name()`
getter. Okay. That's... pretty much useless. But at least we did
something. I blame Pandera for my lassitude. What aren't those guys to
blame for, you know? Can I get a high five? Anyone? ANYOOOOOOONE!?
*crickets* (*Mind-boggling goggles in a bind!*)
  • Loading branch information
leycec committed Mar 30, 2023
1 parent fba824e commit 4499c51
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 8 deletions.
2 changes: 0 additions & 2 deletions beartype/_util/utilobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ def is_object_hashable(obj: object) -> bool:
return True

# ....................{ GETTERS ~ name }....................
#FIXME: Unit test us up, please.
def get_object_name(obj: Any) -> str:
'''
**Fully-qualified name** (i.e., ``.``-delimited string unambiguously
Expand Down Expand Up @@ -169,7 +168,6 @@ def get_object_name(obj: Any) -> str:
)

# ....................{ GETTERS ~ basename }....................
#FIXME: Unit test us up, please.
def get_object_basename_scoped(obj: Any) -> str:
'''
**Lexically scoped name** (i.e., ``.``-delimited string unambiguously
Expand Down
2 changes: 1 addition & 1 deletion beartype_test/_util/mark/pytmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# package-specific submodules at module scope.
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
import pytest
from beartype_test._util.pytroar import BeartypeTestMarkException

# ....................{ MARKS }....................
noop = pytest.mark.noop
Expand Down Expand Up @@ -69,6 +68,7 @@ def ignore_warnings(warning_cls: type) -> 'Callable':

# Defer test-specific imports.
from beartype._util.utilobject import get_object_type_name
from beartype_test._util.pytroar import BeartypeTestMarkException

# If this object is *NOT* a class, raise an exception.
if not isinstance(warning_cls, type):
Expand Down
4 changes: 2 additions & 2 deletions beartype_test/_util/pytroar.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class BeartypeTestException(BeartypeException, metaclass=_ABCMeta):

class BeartypeTestPathException(BeartypeTestException):
'''
**Beartype test path exceptions.**
**Beartype test path exception.**
This exception is raised at test time from callables and classes defined by
the :mod:`beartype_test._util.path` subpackage.
Expand All @@ -98,7 +98,7 @@ class BeartypeTestPathException(BeartypeTestException):

class BeartypeTestMarkException(BeartypeTestException):
'''
**Beartype test mark exceptions.**
**Beartype test mark exception.**
This exception is raised at test time from decorators defined by the
:mod:`beartype_test._util.mark` subpackage.
Expand Down
6 changes: 5 additions & 1 deletion beartype_test/a00_unit/a00_core/test_a00_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ def test_api_beartype() -> None:
Test the public API of the :mod:`beartype` package itself.
'''

# Import this package and relevant types from the beartype cave.
# Defer test-specific imports.
import beartype
from beartype._cave._cavefast import DecoratorTypes
from enum import Enum

# Assert this package's public attributes to be of the expected types.
assert isinstance(beartype.beartype, DecoratorTypes)
assert isinstance(beartype.BeartypeConf, type)
assert isinstance(beartype.BeartypeStrategy, type)
assert issubclass(beartype.BeartypeStrategy, Enum)
assert isinstance(beartype.__version__, str)
assert isinstance(beartype.__version_info__, tuple)

Expand Down
44 changes: 43 additions & 1 deletion beartype_test/a00_unit/a20_util/test_utilobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# See "LICENSE" for further details.

'''
**Beartype object utility unit tests.**
Project-wide **object utility unit tests.**
This submodule unit tests the public API of the private
:mod:`beartype._util.utilobject` submodule.
Expand Down Expand Up @@ -42,6 +42,7 @@ def test_get_object_basename_scoped() -> None:
getter.
'''

# ....................{ IMPORTS }....................
# Defer test-specific imports.
from beartype.roar._roarexc import _BeartypeUtilObjectNameException
from beartype._util.utilobject import get_object_basename_scoped
Expand All @@ -51,6 +52,7 @@ def test_get_object_basename_scoped() -> None:
)
from pytest import raises

# ....................{ PASS }....................
# Assert this getter returns the fully-qualified names of non-nested
# callables unmodified.
for callable_obj in CALLABLES:
Expand All @@ -62,8 +64,48 @@ def test_get_object_basename_scoped() -> None:
assert get_object_basename_scoped(closure_factory()) == (
'closure_factory.closure')

# ....................{ FAIL }....................
# Assert this getter raises "AttributeError" exceptions when passed objects
# declaring neither "__qualname__" nor "__name__" dunder attributes.
with raises(_BeartypeUtilObjectNameException):
get_object_basename_scoped(
'From the ice-gulfs that gird his secret throne,')


def test_get_object_name() -> None:
'''
Test usage of the
:func:`beartype._util.utilobject.get_object_name` getter.
'''

# ....................{ IMPORTS }....................
# Defer test-specific imports.
from functools import partial
from beartype.roar._roarexc import _BeartypeUtilObjectNameException
from beartype._util.utilobject import get_object_name
from pytest import raises

# ....................{ LOCALS }....................
def meet_in_the_vale(and_one_majestic_river: str) -> str:
'''
Arbitrary function.
'''

return and_one_majestic_river

# Function partial of the above function.
breath_and_blood = partial(
meet_in_the_vale, 'The breath and blood of distant lands, for ever')

# ....................{ PASS }....................
# Assert this getter returns the expected name for this function partial.
assert get_object_name(meet_in_the_vale) == (
'beartype_test.a00_unit.a20_util.test_utilobject.'
'test_get_object_name.meet_in_the_vale'
)

# ....................{ FAIL }....................
# Assert this getter raises "AttributeError" exceptions when passed objects
# declaring neither "__qualname__" nor "__name__" dunder attributes.
with raises(_BeartypeUtilObjectNameException):
get_object_name(breath_and_blood)
2 changes: 1 addition & 1 deletion doc/src/pep.rst
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ you into stunned disbelief that somebody typed all this. [#rsi]_
+------------------------+-----------------------------------------------+---------------------------+---------------------------+
| numpy.typing_ | numpy.typing.NDArray_ | **0.8.0**\ \ *current* | **0.8.0**\ \ *current* |
+------------------------+-----------------------------------------------+---------------------------+---------------------------+
| pandera_ | *all* | **0.13.0**\ \ *current* | *none* |
| pandera_ | *all* | **0.13.0**\ \ *current* | |
+------------------------+-----------------------------------------------+---------------------------+---------------------------+
| :mod:`re` | `re.Match`_ | **0.5.0**\ \ *current* | *none* |
+------------------------+-----------------------------------------------+---------------------------+---------------------------+
Expand Down

0 comments on commit 4499c51

Please sign in to comment.