# Path: src/astrodynamics/compat/contextlib.py
# class _SuppressExceptions:
#     def __init__(self, *exceptions):
#     def __enter__(self):
#     def __exit__(self, exctype, excinst, exctb):
# def _suppress(*exceptions):
# 
# Path: src/astrodynamics/compat/math.py
# def _isclose(a, b, rel_tol=1e-9, abs_tol=0.0):
# 
# Path: src/astrodynamics/utils/compat.py
# PY33 = sys.version_info >= (3, 3)


import errno
from contextlib import contextmanager
from astropy import units as u
from astropy.units import Unit, UnitBase
from ..compat.contextlib import suppress
from ..compat.math import isclose
from .compat import PY33

    Raises:
        ValueError: Units are not equivalent.

    Returns:
        ``quantity`` unchanged. Bare numbers will be converted to a dimensionless
        :py:class:`~astropy.units.Quantity`.

    Example:
        .. code-block:: python

            def __init__(self, a):
                self.a = verify_unit(a, astropy.units.m)

    """
    if not isinstance(unit, UnitBase):
        unit = Unit(unit)

    q = quantity * u.one
    if unit.is_equivalent(q.unit):
        return q
    else:
        raise ValueError(
            "Unit '{}' not equivalent to quantity '{}'.".format(unit, quantity))


def qisclose(a, b, rel_tol=1e-9, abs_tol=0.0):
    """Helper function for using :py:func:`math.isclose` with
    :py:class:`~astropy.units.Quantity` objects.
    """

# Path: src/astrodynamics/compat/contextlib.py
# class _SuppressExceptions:
#     def __init__(self, *exceptions):
#     def __enter__(self):
#     def __exit__(self, exctype, excinst, exctb):
# def _suppress(*exceptions):
# 
# Path: src/astrodynamics/compat/math.py
# def _isclose(a, b, rel_tol=1e-9, abs_tol=0.0):
# 
# Path: src/astrodynamics/utils/compat.py
# PY33 = sys.version_info >= (3, 3)


# Path: src/astrodynamics/utils/helper.py
import errno
from contextlib import contextmanager
from astropy import units as u
from astropy.units import Unit, UnitBase
from ..compat.contextlib import suppress
from ..compat.math import isclose
from .compat import PY33


    Raises:
        ValueError: Units are not equivalent.

    Returns:
        ``quantity`` unchanged. Bare numbers will be converted to a dimensionless
        :py:class:`~astropy.units.Quantity`.

    Example:
        .. code-block:: python

            def __init__(self, a):
                self.a = verify_unit(a, astropy.units.m)

    """
    if not isinstance(unit, UnitBase):
        unit = Unit(unit)

    q = quantity * u.one
    if unit.is_equivalent(q.unit):
        return q
    else:
        raise ValueError(
            "Unit '{}' not equivalent to quantity '{}'.".format(unit, quantity))


def qisclose(a, b, rel_tol=1e-9, abs_tol=0.0):
    """Helper function for using :py:func:`math.isclose` with
    :py:class:`~astropy.units.Quantity` objects.
    """

    return isclose(a.si.value, b.si.value, rel_tol=rel_tol, abs_tol=abs_tol)